Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to configure and run Selenium TestNG in Bamboo? I need a savior please.

Nelson Ntege November 5, 2014

I have selenium TestNG test written in java and using STS IDE. I use testNG.xml file to run it as testNG Suite. I use Bitbucket to store all the repositories. Now I want to run the Selenium TestNG test using Bamboo. I have already connected Bamboo to Bitbucket to use the repositories. But I can't figure out how to configure the testNG.xml file, java file, and the jar to Bamboo.

Does any one have any ideas of how to go about it. I have searched from the net for quite sometime, but I haven't come across any good tutorial or guide of how to go about it. 

Here are the files I was using in STS IDE:

JARS

  1. selenium-java-2.44.0.jar
  2. selenium-java-2.44.0-srcs.jar

CONFIG.PROPERTIES FILE

url=http://mnn.com/

 

XML FILE

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="JobGo Suite">

<test name="FirefoxTest">
      <parameter name="browser" value="firefox" />
      <classes>
           <class name="com.mnn.MeTab"/>
      </classes>
</test>

</suite>

JAVA FILE

package com.mnn;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.interactions.internal.Coordinates;
import org.openqa.selenium.internal.Locatable;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class MeTab{
    private WebDriver driver;
    private String propertyFileName = "config.properties";
    private InputStream inputStream = MeTab.class.getClassLoader().getResourceAsStream(propertyFileName);
    private Properties prop = new Properties();

   /*
    * Opens the browser and navigate to the Landing Page
    */
   @BeforeClass
   @Parameters("browser")
   public void beforeTest(String browser) throws IOException{

   if(browser.equalsIgnoreCase("firefox")){
       driver = new FirefoxDriver();
    }else if(browser.equalsIgnoreCase("chrome")){
       driver = new ChromeDriver();
    }else if(browser.equalsIgnoreCase("ie")){
       driver = new InternetExplorerDriver();
    }else{
       throw new RuntimeException("Browser type unsupported");
    }

     driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

     prop.load(inputStream);

    if( inputStream == null ){
        throw new FileNotFoundException("property file " + propertyFileName +
                " not found in the classpath");
    }

    // navigate to jobgo web site
   driver.get(prop.getProperty("url"));

   // Maximize the browser Window
   driver.manage().window().maximize();

} // end of method beforeTest

/*
* Method tests the landing page
*
*/
@Test(priority = 0)
public void testLogin() throws Exception{
//time that elapses as the browser as the browser waits before executing
WebDriverWait wait = new WebDriverWait(driver, 120);

// Text has to be visible before another process is executed
wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("login")));

// Click on Login
WebElement muwl = driver.findElement(By.className("Model_User_Widget_Login"));
muwl.findElement(By.className("login")).click();

// From the Login pop up, use the Sign In tab to login known credentials to the application
WebElement username = driver.findElement(By.className("login_form"));
username.findElement(By.id("main_username")).clear();
username.findElement(By.id("main_username")).sendKeys("mnn@yahoo.com");

// From the Login pop up, use the Sign In tab to login known credentials to the application
WebElement passwd = driver.findElement(By.className("login_form"));
passwd.findElement(By.id("main_password")).clear();
passwd.findElement(By.id("main_password")).sendKeys("123kdd12");


// Check if 'Remember me' checkbox is not checked then check it
WebElement notChkbox = driver.findElement(By.className("chkbox"));
if(!notChkbox.isSelected()){
notChkbox.click();
}

Thread.sleep(3000);

// If 'Remember me' checkbox is checked then uncheck it
WebElement chkbox = driver.findElement(By.className("chkbox"));
if(chkbox.isSelected()){
chkbox.click();
}


Thread.sleep(3000);

// Click on 'Sign in' button
WebElement signIn = driver.findElement(By.className("login_form"));
signIn.findElement(By.className("login_btn")).click();

// Text has to be visible before another process is executed
wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("well_txt")));
}


/*
* Closes the browser
*/
@AfterClass
public void quitDriver() throws Exception{
Thread.sleep(3000);
driver.quit();
} // end of method quitDriver
}

 

Please any help is welcome. 

Cheers, Nelson

5 answers

0 votes
Vincent Mutambuki _ Mumo Systems _ October 18, 2016

The simplest and most scalable way is to used Selenium IDE and this add-on in Bamboo. With one build plan you can target all major browsers from one build plan. 

0 votes
Nelson Ntege November 9, 2014

Hi Alexey,

Thank you so much for the help. At last it has worked out. 

Cheers,

Nelson

Deep (TechTime Initiative Group) July 28, 2019

@Nelson Ntege can you please share a sample project/code how you made it work as I am stuck with the same problem. TIA. 

0 votes
Alexey Chystoprudov
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 7, 2014

Hello Nelson,

I created sample repository with Maven project and WebDriver test: https://bitbucket.org/chystoprudov/selenium_bamboo/overview

Please see instructions at Readme section. It looks like you configured everything except Maven capability. please follow link in readme to receive more instructions how to setup it. It's pretty easy, you just need to define path to Maven home folder in your environment.

In case pom.xml is not in the root of your repository you need to specify work folder for Maven task

Hope it helps

Regards,

Alexey

Aditya September 2, 2018

Hi @Alexey Chystoprudov @Nelson Ntege

I am trying to execute testng using ant in bamboo. Please visit this link for config details. The problem mentioned in that link has been resolved, but I am unable to execute testng with chromedriver.

I am now getting configuration failure: 1, skips: 1. The testng listener is unable to initialize chromedriver.

How to set chromedriver capability in bamboo? (my bamboo server is on a RHEL server, and driver is located in /usr/local/bin/chromedriver)

Or should I use htmlunit driver? And how to set its capability in bamboo?

 

PS: Ant and JDK capabilities are already set, and I'm running chrome in headless mode. I haven't also downloaded selenium-java client. i am just working with standalone selenium server jar. 

The tests are successfull in my eclipse IDE and cmd.exe

0 votes
Nelson Ntege November 6, 2014

Hello Alexey,

Thank you so much for the quick reply. I have made the modifications in code using Maven which executes when I use Eclipse IDE.  My biggest problem is with bamboo, I don't have a cue what to put in Executable and Environment variable fields as shown below. 

In the Executable field I have tried to link it up with the JARS from my local machine, but nothing happens. 

image2014-11-6 21:43:25.png

 

The repository attached to Bamboo from Bitbucket contains mnn_maven folder (master branch). Inside it, it has the pom.xml and src/com/mnn/simpleBrowserTest.java

Please guide me from here as the configuration seems to be my biggest issue.

Cheers,

Nelson

 

 

 

 

 

 

 

Krystian Brazulewicz
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 12, 2014

It always pays off to read documentation: https://confluence.atlassian.com/display/BAMBOO/Maven

0 votes
Alexey Chystoprudov
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 5, 2014

Hello Nelson,

To execute your tests in Bamboo you should use some executable build tool. Bamboo supports Ant, Maven, Command line, Grails.

Example of Maven configuration for TestNG tests: http://maven.apache.org/surefire/maven-surefire-plugin/examples/testng.html

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events