# TestNG dosn't support openBrowser() function in webdriver coding

**URL:** <https://discuss.gradle.org/t/testng-dosnt-support-openbrowser-function-in-webdriver-coding/7273>\
**Category:** Old Forum Archive\
**Created:** [August 2, 2012, 11:17pm UTC](https://discuss.gradle.org/t/testng-dosnt-support-openbrowser-function-in-webdriver-coding/7273 "2012-08-02T23:17:00Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Harpreet\_Singh](https://avatars.discourse-cdn.com/v4/letter/h/fbc32d/32.png) [@Harpreet\_Singh](https://discuss.gradle.org/u/Harpreet_Singh)\
**Post date:** [August 2, 2012, 11:17pm UTC](https://discuss.gradle.org/t/testng-dosnt-support-openbrowser-function-in-webdriver-coding/7273/1 "2012-08-02T23:17:00Z")

</div>

TestBase main test case function it doesn’t open IE/Firefox/Chrome

Please help

TestBase.java

package com.qtpselenium.base;

import java.io.FileInputStream; import java.io.FileNotFoundException; import java.util.Properties;

import org.apache.log4j.Logger; import [org.openqa.selenium.By](http://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.testng.Assert;

import com.qtpselenium.util.ErrorUtil; import com.qtpselenium.util.Xls\_Reader; import com.thoughtworks.selenium.Selenium;

public class TestBase {

public static Logger APP\_LOGS=null;

public static Properties CONFIG=null;

public static Properties OR=null;

public static Xls\_Reader suiteXls=null;

public static Xls\_Reader suite\_shop\_xls=null;

public static Xls\_Reader suite\_cart\_xls=null;

public static Xls\_Reader suite\_productDisplay\_xls=null;

public static boolean isInitalized=false;

public static WebDriver driver = null;

public static Selenium selenium=null;

public static boolean isBrowserOpened=false;

public void initialize () throws Exception

{// logs

if(!isInitalized)

APP\_LOGS = Logger.getLogger(“devpinoyLogger”);

APP\_LOGS.debug(“Loading Property files”);

Properties CONFIG = new Properties();

FileInputStream ip = new FileInputStream(System.getProperty(“user.dir”)+"//src//com//qtpselenium//config/config.properties");

CONFIG.load(ip);

System.out.println(CONFIG.getProperty(“screenshotPath”));

OR = new Properties();

ip = new FileInputStream(System.getProperty(“user.dir”)+"//src//com//qtpselenium//config/OR.properties");

OR.load(ip);

APP\_LOGS.debug(“Loaded Property files successfully”);

[//System.out.println](https://System.out.println)(OR.getProperty(“login\_link”));

APP\_LOGS.debug(“Loading Property files”);

// xls file

suite\_shop\_xls = new Xls\_Reader(System.getProperty(“user.dir”)+"//src//com//qtpselenium//xls//Shop Suite.xlsx");

suite\_cart\_xls = new Xls\_Reader(System.getProperty(“user.dir”)+"//src//com//qtpselenium//xls//Cart Suite.xlsx");

suite\_productDisplay\_xls = new Xls\_Reader(System.getProperty(“user.dir”)+"//src//com//qtpselenium//xls//Product Display Suite.xlsx");

suiteXls = new Xls\_Reader(System.getProperty(“user.dir”)+"\src\com\qtpselenium\xls\Suite.xlsx");

APP\_LOGS.debug(“Loaded Property files Successfully”);

isInitalized=true;

}

public void openBrowser()

{

if(CONFIG.getProperty(“browserType”).equals(“MOZILLA”))

driver = new FirefoxDriver();

else if (CONFIG.getProperty(“browserType”).equals(“IE”))

driver = new InternetExplorerDriver();

else if (CONFIG.getProperty(“browserType”).equals(“Chrome”))

driver = new ChromeDriver();

}

public void closeBrowser()

{

driver.quit();

}

public boolean compareTitle(String expectedVal)

{

try{

Assert.assertEquals(driver.getTitle(), expectedVal);

}catch(Throwable t) {

ErrorUtil.addVerificationFailure(t);

APP\_LOGS.debug(“Titles do not match”);

return false;

}

return true;

}

public boolean compareNumbers(int actualValue, int expectedVal)

{

try{

Assert.assertEquals(expectedVal, actualValue);

}catch(Throwable t) {

ErrorUtil.addVerificationFailure(t);

APP\_LOGS.debug(“values do not match”);

return false;

}

return true; }

public boolean checkElementPresence(String xpathKey) { int count = driver.findElements(By.xpath(CONFIG.getProperty(xpathKey))).size(); try{ Assert.assertTrue(count\>0, “No element present”);

}catch(Throwable t) {

ErrorUtil.addVerificationFailure(t);

APP\_LOGS.debug(“No element present”);

return false; } return true; }

public WebElement getObject (String xpathKey) { try{ return driver.findElement(By.xpath(OR.getProperty(xpathKey))); }catch(Throwable t) { APP\_LOGS.debug(“Cannot find object with key–”+ xpathKey); return null;

} }} &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&7 AddProductTest.java

package [com.qtpselenium.suite.shop](http://com.qtpselenium.suite.shop);

import org.testng.annotations.Test; import [org.openqa.selenium.By](http://org.openqa.selenium.By); import org.testng.SkipException; import org.testng.annotations.AfterMethod; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.DataProvider; import org.testng.annotations.Test;

import com.qtpselenium.util.TestUtil;

public class AddProductTest extends TestSuiteBase {

String runmodes[]=null;

static int count=-1;

static boolean fail=false;

static boolean skip=false;

static boolean isTestPass=true;

@BeforeTest

public void checkTestSkip(){

if(!TestUtil.isTestCaseRunnable(suite\_shop\_xls, this.getClass().getSimpleName())){

// APP\_LOGS.debug(“Skipping Test Case as runmode set to NO”); //logs

//throw new SkipException(“Skipping Test Case as runmode set to NO”); //reports

}

runmodes=TestUtil.getDataRunmodes(suite\_shop\_xls, this.getClass().getSimpleName());

}

@Test(dataProvider=“getTestData”)

public void testCaseA2(

String Mobile\_Type,

String color,

String memory,

String Engraving,

String quantity

)

{

count++;

if(!runmodes[count].equalsIgnoreCase(“Y”)){

skip=true;

throw new SkipException(“Runmode for test set data set to no” +count);

}

APP\_LOGS.debug(“Executing TestCase\_A2”);

APP\_LOGS.debug(Mobile\_Type +" – “+color +” – "+memory );

openBrowser();

driver.get(CONFIG.getProperty(“testSiteName”));

getObject(“shopLink”).click();

getObject(“mobile\_phone\_link”).click();

}

@AfterMethod public void reportDataSetResult(){

if(skip)

TestUtil.reportDataSetResult(suite\_shop\_xls, this.getClass().getSimpleName(), count+2, “SKIP”);

else if(fail){

isTestPass=false;

TestUtil.reportDataSetResult(suite\_shop\_xls, this.getClass().getSimpleName(), count+2, “FAIL”);

}

else

TestUtil.reportDataSetResult(suite\_shop\_xls, this.getClass().getSimpleName(), count+2, “PASS”);

skip=false;

fail=false;

}

@AfterTest public void reportTestResult(){

if(isTestPass)

[//TestUtil.reportDataSetResult](https://TestUtil.reportDataSetResult)(suiteAxls, “Test Cases”, count+2, “PASS”);

TestUtil.reportDataSetResult(suite\_shop\_xls, “Test Cases”, TestUtil.getRowNum(suite\_shop\_xls,this.getClass().getSimpleName()), “PASS”);

else

[//TestUtil.reportDataSetResult](https://TestUtil.reportDataSetResult)(suiteAxls, “Test Cases”, count+2, “FAIL”);

TestUtil.reportDataSetResult(suite\_shop\_xls, “Test Cases”, TestUtil.getRowNum(suite\_shop\_xls,this.getClass().getSimpleName()), “FAIL”); }

@DataProvider

public Object[][] getTestData(){

return TestUtil.getData(suite\_shop\_xls, this.getClass().getSimpleName());

}

}

---

<div class="post-metadata">

**Author:** ![luke\_daley](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/luke_daley/32/9890_2.png) [@luke\_daley](https://discuss.gradle.org/u/luke_daley)\
**Post date:** [August 3, 2012, 8:21am UTC](https://discuss.gradle.org/t/testng-dosnt-support-openbrowser-function-in-webdriver-coding/7273/2 "2012-08-03T08:21:00Z")

</div>

Hi,

The question is far too vague to answer.

---

<div class="post-metadata">

**Author:** ![Harpreet\_Singh](https://avatars.discourse-cdn.com/v4/letter/h/fbc32d/32.png) [@Harpreet\_Singh](https://discuss.gradle.org/u/Harpreet_Singh)\
**Post date:** [August 3, 2012, 8:57pm UTC](https://discuss.gradle.org/t/testng-dosnt-support-openbrowser-function-in-webdriver-coding/7273/3 "2012-08-03T20:57:00Z")

</div>

this is the error

java.lang.NullPointerException

at com.qtpselenium.base.TestBase.openBrowser(TestBase.java:69)

at com.qtpselenium.suite.shop.AddProductTest.testCaseA2(AddProductTest.java:60)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)

at org.testng.internal.Invoker.invokeMethod(Invoker.java:702)

at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:894)

at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1219)

at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)

at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)

at org.testng.TestRunner.privateRun(TestRunner.java:767)

at org.testng.TestRunner.run(TestRunner.java:617)

at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)

at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)

at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)

at org.testng.SuiteRunner.run(SuiteRunner.java:240)

at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)

at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:87)

at org.testng.TestNG.runSuitesSequentially(TestNG.java:1197)

at org.testng.TestNG.runSuitesLocally(TestNG.java:1122)

at org.testng.TestNG.run(TestNG.java:1030)

at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)

at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)

at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)

this is function in base class public void openBrowser()

{

if(CONFIG.getProperty(“browserType”).equals(“MOZILLA”))

driver = new FirefoxDriver();

else if (CONFIG.getProperty(“browserType”).equals(“IE”))

driver = new InternetExplorerDriver();

else if (CONFIG.getProperty(“browserType”).equals(“Chrome”))

driver = new ChromeDriver();

}

it doesn’t open any of the browser

---

<div class="post-metadata">

**Author:** ![Rene](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/rene/32/8082_2.png) [@Rene](https://discuss.gradle.org/u/Rene)\
**Post date:** [August 3, 2012, 9:50pm UTC](https://discuss.gradle.org/t/testng-dosnt-support-openbrowser-function-in-webdriver-coding/7273/4 "2012-08-03T21:50:00Z")

</div>

Can you show the snippet of your build script that configures your testng based test task? My first guess is, that a property is not correctly passed to the test jvm. Where does this CONFIG class come from?

cheers, René

---

<div class="post-metadata">

**Author:** ![Harpreet\_Singh](https://avatars.discourse-cdn.com/v4/letter/h/fbc32d/32.png) [@Harpreet\_Singh](https://discuss.gradle.org/u/Harpreet_Singh)\
**Post date:** [August 3, 2012, 10:00pm UTC](https://discuss.gradle.org/t/testng-dosnt-support-openbrowser-function-in-webdriver-coding/7273/5 "2012-08-03T22:00:00Z")

</div>

Its in Test Package

package test;

import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Properties;

public class TestConfig {

/\*\*

- @param args

- @throws IOException

\*/

public static void main(String[] args) throws IOException {

Properties CONFIG = new Properties();

FileInputStream ip = new FileInputStream(System.getProperty(“user.dir”)+"//src//com//qtpselenium//config//config.properties");

CONFIG.load(ip);

System.out.println(CONFIG.getProperty(“screenshotPath”));

Properties OR = new Properties();

ip = new FileInputStream(System.getProperty(“user.dir”)+"//src//com//qtpselenium//config//OR.properties");

OR.load(ip);

System.out.println(OR.getProperty(“testSiteName”));

}

}

---

<div class="post-metadata">

**Author:** ![Rene](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/rene/32/8082_2.png) [@Rene](https://discuss.gradle.org/u/Rene)\
**Post date:** [August 3, 2012, 10:18pm UTC](https://discuss.gradle.org/t/testng-dosnt-support-openbrowser-function-in-webdriver-coding/7273/6 "2012-08-03T22:18:00Z")

</div>

Still, not not entirely sure what the problem is. I assume that the paths are not setup correctly. Can you do me a favor and create a small self contained example that shows the problem, Then I can take a look on it locally.

cheers, Rene

---

<div class="post-metadata">

**Author:** ![Harpreet\_Singh](https://avatars.discourse-cdn.com/v4/letter/h/fbc32d/32.png) [@Harpreet\_Singh](https://discuss.gradle.org/u/Harpreet_Singh)\
**Post date:** [August 3, 2012, 10:27pm UTC](https://discuss.gradle.org/t/testng-dosnt-support-openbrowser-function-in-webdriver-coding/7273/7 "2012-08-03T22:27:00Z")

</div>

Rene give me your email id i will send you the files

Thanks,

---

<div class="post-metadata">

**Author:** ![Rene](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/rene/32/8082_2.png) [@Rene](https://discuss.gradle.org/u/Rene)\
**Post date:** [August 3, 2012, 10:39pm UTC](https://discuss.gradle.org/t/testng-dosnt-support-openbrowser-function-in-webdriver-coding/7273/8 "2012-08-03T22:39:00Z")

</div>

[rene.groeschke@gradleware.com](mailto:rene.groeschke@gradleware.com)

---

<div class="post-metadata">

**Author:** ![Harpreet\_Singh](https://avatars.discourse-cdn.com/v4/letter/h/fbc32d/32.png) [@Harpreet\_Singh](https://discuss.gradle.org/u/Harpreet_Singh)\
**Post date:** [August 6, 2012, 10:43pm UTC](https://discuss.gradle.org/t/testng-dosnt-support-openbrowser-function-in-webdriver-coding/7273/9 "2012-08-06T22:43:00Z")

</div>

Hello Rene,

first thanks for the help, I just removed the null; from test base class.

public static Logger APPLOGS=null;

public static Properties CONFIG=null;

public static Properties OR=null;

public static XlsReader suiteXls=null;

public static XlsReader suiteshopxls=null;

public static XlsReader suitecartxls=null;

public static XlsReader suiteproductDisplay\_xls=null;

public static boolean isInitalized=false;

public static WebDriver driver = null;

public static Selenium selenium=null;

Thanks, Harpreet

---

<div class="post-metadata">

**Author:** ![Harpreet\_Singh](https://avatars.discourse-cdn.com/v4/letter/h/fbc32d/32.png) [@Harpreet\_Singh](https://discuss.gradle.org/u/Harpreet_Singh)\
**Post date:** [August 6, 2012, 10:48pm UTC](https://discuss.gradle.org/t/testng-dosnt-support-openbrowser-function-in-webdriver-coding/7273/10 "2012-08-06T22:48:00Z")

</div>

another question

its not doing Add\_to\_cart in the website.

config.properties file #- XPATHS, IDS, linkstext of my app

shopLink=html/body/div[3]/div[1]/div/div[1]/div/ul/li[2]/a/span mobile\_phone\_link=//_[@id=‘vmMainPage’]/div[2]/div[1]/div[3]/div/h2/a/img show\_cart\_link=//_[@id=‘rt-sidebar-c’]/div[1]/div/div/div[7]/a mp3\_player\_link=//_[@id=‘vmMainPage’]/div[2]/div[1]/div[1]/div/h2/a/img part1=//_[@id=‘vmMainPage’]/div[1]/div[part2=]/div[part3=]/div/h2/a

# Dropdowns mobile\_color\_list=//_[@id=‘Color\_field’] mobile\_memory\_list=//_[@id=‘Memory\_field’]

#input box mobile\_phone\_quantity=//input[starts-with(@id, ‘quantity’)] mobline\_phone\_engraving=//input[starts-with(@id, ‘Engraving’)]

#buttons add\_to\_cart\_button=//input[starts-with(@id, ‘addtocart\_501c’)]/div[2]/span[3]/input

#text price\_start=//\*[@id=‘vmMainPage’]/div[1]/div[price\_end=]/div[4] body=//body

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& class file this link in the class (driver.findElement(By.className(“addtocart-button”)).click()😉

package [com.qtpselenium.suite.shop](http://com.qtpselenium.suite.shop);

import org.testng.annotations.Test; import org.testng.annotations.Test; import [org.openqa.selenium.By](http://org.openqa.selenium.By); import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.ie.InternetExplorerDriver; import org.testng.Assert; import org.testng.SkipException; import org.testng.annotations.AfterMethod; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.DataProvider; import org.testng.annotations.Test;

import com.qtpselenium.util.TestUtil;

public class AddProductTest extends TestSuiteBase {

String runmodes[]=null;

static int count=-1;

static boolean fail=false;

static boolean skip=false;

static boolean isTestPass=true;

@BeforeTest

public void checkTestSkip(){

if(!TestUtil.isTestCaseRunnable(suite\_shop\_xls, this.getClass().getSimpleName())){

APP\_LOGS.debug(“Skipping Test Case as runmode set to NO”); //logs

throw new SkipException(“Skipping Test Case as runmode set to NO”); //reports

}

runmodes=TestUtil.getDataRunmodes(suite\_shop\_xls, this.getClass().getSimpleName());

}

@Test(dataProvider=“getTestData”)

public void testCaseA2(

String Mobile\_Type,

String color,

String memory,

String Engraving,

String quantity

) throws InterruptedException

{

count++;

if(!runmodes[count].equalsIgnoreCase(“Y”)){

//skip=true;

throw new SkipException(“Runmode for test set data set to no” +count);

}

APP\_LOGS.debug(“Executing TestCase\_A2”);

APP\_LOGS.debug(Mobile\_Type +" – “+color +” – "+memory );

openBrowser();

driver.get(CONFIG.getProperty(“testSiteName”));

getObject(“shopLink”).click();

getObject(“mobile\_phone\_link”).click();

driver.findElement(By.linkText(Mobile\_Type)).click();

getObject(“mobile\_color\_list”).sendKeys(color);

getObject(“mobile\_memory\_list”).sendKeys(memory);

getObject(“mobline\_phone\_engraving”).sendKeys(Engraving);

[//driver.findElement](https://driver.findElement)(By.xpath("[starts-with(@id, ‘Engraving’)]")).sendKeys(Engraving);

getObject(“mobile\_phone\_quantity”).clear();

//

int q= (int)Double.parseDouble(quantity);

getObject(“mobile\_phone\_quantity”).sendKeys(String.valueOf(q));

// add to cart

//getObject(“add\_to\_cart\_button”).click();

driver.findElement(By.className(“addtocart-button”)).click();

Thread.sleep(3000L);

String x=driver.findElement(By.className(“shop\_info”)).getText();

System.out.println(x);

[//Assert.assertEquals](https://Assert.assertEquals)(“Info: The product was added to your cart.”, x);

//compareStrings("","");

[//Assert.assertEquals](https://Assert.assertEquals)("", “”);

//compareTitle(expectedVal)

}

/\*if(!checkElementPresence(“shopLink”)){

// screenshot

//capturescreenshot(this.getClass().getSimpleName()+"\_"+count);

fail=true;

// quit

return;

}

getObject(“shopLink”).click();

getObject(“mobile\_phone\_link”).click();

driver.findElement(By.linkText(Mobile\_Type)).click();

getObject(“mobile\_color\_list”).sendKeys(color);

getObject(“mobile\_memory\_list”).sendKeys(memory);

getObject(“mobline\_phone\_engraving”).sendKeys(Engraving);

[//driver.findElement](https://driver.findElement)(By.xpath("")).sendKeys(engraving);

getObject(“mobile\_phone\_quantity”).clear();

//

int q= (int)Double.parseDouble(quantity);

getObject(“mobile\_phone\_quantity”).sendKeys(String.valueOf(q));

[//System.out.println](https://System.out.println)(“testCaseA2”);

} \*/

@AfterMethod public void reportDataSetResult(){

if(skip)

TestUtil.reportDataSetResult(suite\_shop\_xls, this.getClass().getSimpleName(), count+2, “SKIP”);

else if(fail){

isTestPass=false;

TestUtil.reportDataSetResult(suite\_shop\_xls, this.getClass().getSimpleName(), count+2, “FAIL”);

}

else

TestUtil.reportDataSetResult(suite\_shop\_xls, this.getClass().getSimpleName(), count+2, “PASS”);

skip=false;

fail=false;

}

@AfterTest public void reportTestResult(){

if(isTestPass)

[//TestUtil.reportDataSetResult](https://TestUtil.reportDataSetResult)(suiteAxls, “Test Cases”, count+2, “PASS”);

TestUtil.reportDataSetResult(suite\_shop\_xls, “Test Cases”, TestUtil.getRowNum(suite\_shop\_xls,this.getClass().getSimpleName()), “PASS”);

else

[//TestUtil.reportDataSetResult](https://TestUtil.reportDataSetResult)(suiteAxls, “Test Cases”, count+2, “FAIL”);

TestUtil.reportDataSetResult(suite\_shop\_xls, “Test Cases”, TestUtil.getRowNum(suite\_shop\_xls,this.getClass().getSimpleName()), “FAIL”); }

@DataProvider

public Object[][] getTestData(){

return TestUtil.getData(suite\_shop\_xls, this.getClass().getSimpleName());

}

}
