How to configure and run Selenium TestNG in Bamboo? I need a savior please.
Asked by Nelson Ntege:

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/](http://jobgo.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](http://java.io).FileNotFoundException;  
import [java.io](http://java.io).IOException;  
import [java.io](http://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](http://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](http://By.id)("main_username")).clear();  
username.findElement([By.id](http://By.id)("main_username")).sendKeys("mnn@[yahoo.com](http://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](http://By.id)("main_password")).clear();  
passwd.findElement([By.id](http://By.id)("main_password")).sendKeys("123kdd12");  

<br />

// 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();  
}  

<br />

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")));  
}

<br />

/\*  
\* 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


Answers:
author: Vincent Mutambuki { Mumo Systems }
body: The simplest and most scalable way is to used Selenium IDE and this[add-on](https://marketplace.atlassian.com/plugins/com.mumosystems.charlotte/server/overview) in Bamboo. With one build plan you can target all major browsers from one build plan.


author: Nelson Ntege
body: Hi Alexey,

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

Cheers,

Nelson

comments: author: Deep (TechTime Initiative Group)
body: [@Nelson Ntege](/t5/user/viewprofilepage/user-id/457656) can you please share a sample project/code how you made it work as I am stuck with the same problem. TIA.


author: Alexey Chystoprudov
body: 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

comments: author: Aditya
body: Hi [@Alexey Chystoprudov](/t5/user/viewprofilepage/user-id/781646) [@Nelson Ntege](/t5/user/viewprofilepage/user-id/457656)

I am trying to execute testng using ant in bamboo. Please visit this [link](https://community.atlassian.com/t5/Bamboo-questions/Atlassian-Bamboo-Logs-testng-Cannot-find-class-in-classpath-com/qaq-p/881040#U881049) 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


author: Nelson Ntege
body: 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

[](https://community.atlassian.com/t5/Bamboo-questions/How-to-configure-and-run-Selenium-TestNG-in-Bamboo-I-need-a/qaq-p/46454?attachment-id=12105){#link_11696699bfa424}  
[](/tnckb94959/attachments/tnckb94959/bamboo-questions/1425/1/image2014-11-6%2021%3A43%3A25.png){#display_11696699bfa424_0}  
[](https://community.atlassian.com/t5/Bamboo-questions/How-to-configure-and-run-Selenium-TestNG-in-Bamboo-I-need-a/qaq-p/46454?attachment-id=12106){#link_11696699bfa424_0}  
[](/tnckb94959/attachments/tnckb94959/bamboo-questions/1425/2/Maven_conf.png){#display_11696699bfa424_2}

comments: author: Krystian Brazulewicz
body: It always pays off to read documentation: <https://confluence.atlassian.com/display/BAMBOO/Maven>


author: Alexey Chystoprudov
body: 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>


Tags: bitbucket-cloud

cloud

selenium