Null pointer exception when I try to utilize parameter value set in testng.xml

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Null pointer exception when I try to utilize parameter value set in testng.xml

saurabh sharma
Hi , 

I am facing Null pointer Exception when I try to access the parameter value set in the testng.xml
My testng.xml looks like 

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
 
<suite name="Suite1" verbose="3" parallel="tests" thread-counts="2" >
  <parameter name="browser"  value="firefox" />
  <test name="First Test"   >
      <classes>
       <class name="Driver" />
   
    </classes>
 </test>
 </suite>


I am trying to run selenium grid test here but my parameter value is not invoked. here is my code.

public class Driver {

public static WebDriver driver;

DesiredCapabilities capability=null;
@BeforeTest 
@Parameters({ "browser" })
public void setUp() throws IOException
{
System.out.println(browser);  
if(browser.equalsIgnoreCase("firefox")){
System.out.println("firefox");
capability= DesiredCapabilities.firefox();
capability.setBrowserName("firefox");
capability.setPlatform(org.openqa.selenium.Platform.ANY);
//capability.setVersion("");
}
if(browser=="iexplore"){
System.out.println("iexplore");
capability= DesiredCapabilities.internetExplorer();
capability.setBrowserName("iexplore");
capability.setPlatform(org.openqa.selenium.Platform.WINDOWS);
capability.setVersion("");
}
driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);
driver.navigate().to("http://www.ourgoalplan.com");

error is below
null
FAILED CONFIGURATION: @BeforeTest setUp
java.lang.NullPointerException
at Driver.setUp(Driver.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
at org.testng.TestRunner.beforeRun(TestRunner.java:641)
at org.testng.TestRunner.run(TestRunner.java:609)
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:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
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)
Line 60 in my code points to --- if(browser.equalsIgnoreCase("firefox"))
even I printed the value of Browser it is showing as null . 

Pointers will be helpful :) Thanks in Advance 

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: Null pointer exception when I try to utilize parameter value set in testng.xml

Yevhen Bilevych
You had to write "setUp(String browser)"

Sent from my BlackBerry® PlayBook™
www.blackberry.com


From: "saurabh sharma" <[hidden email]>
To: "[hidden email]" <[hidden email]>
Sent: January 17, 2014 7:20 PM
Subject: [testng-users] Null pointer exception when I try to utilize parameter value set in testng.xml

Hi , 

I am facing Null pointer Exception when I try to access the parameter value set in the testng.xml
My testng.xml looks like 

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
 
<suite name="Suite1" verbose="3" parallel="tests" thread-counts="2" >
  <parameter name="browser"  value="firefox" />
  <test name="First Test"   >
      <classes>
       <class name="Driver" />
   
    </classes>
 </test>
 </suite>


I am trying to run selenium grid test here but my parameter value is not invoked. here is my code.

public class Driver {

public static WebDriver driver;

DesiredCapabilities capability=null;
@BeforeTest 
@Parameters({ "browser" })
public void setUp() throws IOException
{
System.out.println(browser);  
if(browser.equalsIgnoreCase("firefox")){
System.out.println("firefox");
capability= DesiredCapabilities.firefox();
capability.setBrowserName("firefox");
capability.setPlatform(org.openqa.selenium.Platform.ANY);
//capability.setVersion("");
}
if(browser=="iexplore"){
System.out.println("iexplore");
capability= DesiredCapabilities.internetExplorer();
capability.setBrowserName("iexplore");
capability.setPlatform(org.openqa.selenium.Platform.WINDOWS);
capability.setVersion("");
}
driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);
driver.navigate().to("http://www.ourgoalplan.com");

error is below
null
FAILED CONFIGURATION: @BeforeTest setUp
java.lang.NullPointerException
at Driver.setUp(Driver.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
at org.testng.TestRunner.beforeRun(TestRunner.java:641)
at org.testng.TestRunner.run(TestRunner.java:609)
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:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
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)
Line 60 in my code points to --- if(browser.equalsIgnoreCase("firefox"))
even I printed the value of Browser it is showing as null . 

Pointers will be helpful :) Thanks in Advance 

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: Null pointer exception when I try to utilize parameter value set in testng.xml

praveen133t
In reply to this post by saurabh sharma
Did you try public void setUp(String browser) ???


On Friday, January 17, 2014 7:01:13 AM UTC-6, saurabh sharma wrote:
Hi , 

I am facing Null pointer Exception when I try to access the parameter value set in the testng.xml
My testng.xml looks like 

<!DOCTYPE suite SYSTEM "<a href="http://testng.org/testng-1.0.dtd" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Ftestng.org%2Ftestng-1.0.dtd\46sa\75D\46sntz\0751\46usg\75AFQjCNFHihXzQ1YlwcxcDehnw97TuniFLA';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Ftestng.org%2Ftestng-1.0.dtd\46sa\75D\46sntz\0751\46usg\75AFQjCNFHihXzQ1YlwcxcDehnw97TuniFLA';return true;">http://testng.org/testng-1.0.dtd" >
 
<suite name="Suite1" verbose="3" parallel="tests" thread-counts="2" >
  <parameter name="browser"  value="firefox" />
  <test name="First Test"   >
      <classes>
       <class name="Driver" />
   
    </classes>
 </test>
 </suite>


I am trying to run selenium grid test here but my parameter value is not invoked. here is my code.

public class Driver {

public static WebDriver driver;

DesiredCapabilities capability=null;
@BeforeTest 
@Parameters({ "browser" })
public void setUp() throws IOException
{
System.out.println(browser);  
if(browser.equalsIgnoreCase("firefox")){
System.out.println("firefox");
capability= DesiredCapabilities.firefox();
capability.setBrowserName("firefox");
capability.setPlatform(org.openqa.selenium.Platform.ANY);
//capability.setVersion("");
}
if(browser=="iexplore"){
System.out.println("iexplore");
capability= DesiredCapabilities.internetExplorer();
capability.setBrowserName("iexplore");
capability.setPlatform(org.openqa.selenium.Platform.WINDOWS);
capability.setVersion("");
}
driver = new RemoteWebDriver(new URL("<a href="http://localhost:4444/wd/hub" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Flocalhost%3A4444%2Fwd%2Fhub\46sa\75D\46sntz\0751\46usg\75AFQjCNGL7ghOGmWpqo93CZkfCgX3jjpVBg';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Flocalhost%3A4444%2Fwd%2Fhub\46sa\75D\46sntz\0751\46usg\75AFQjCNGL7ghOGmWpqo93CZkfCgX3jjpVBg';return true;">http://localhost:4444/wd/hub"), capability);
driver.navigate().to("<a href="http://www.ourgoalplan.com" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fwww.ourgoalplan.com\46sa\75D\46sntz\0751\46usg\75AFQjCNF00DEBitj2a4g9bM5be7kqdn97oA';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fwww.ourgoalplan.com\46sa\75D\46sntz\0751\46usg\75AFQjCNF00DEBitj2a4g9bM5be7kqdn97oA';return true;">http://www.ourgoalplan.com");

error is below
null
FAILED CONFIGURATION: @BeforeTest setUp
java.lang.NullPointerException
at Driver.setUp(Driver.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
at org.testng.TestRunner.beforeRun(TestRunner.java:641)
at org.testng.TestRunner.run(TestRunner.java:609)
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:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
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)
Line 60 in my code points to --- if(browser.equalsIgnoreCase("firefox"))
even I printed the value of Browser it is showing as null . 

Pointers will be helpful :) Thanks in Advance 

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/groups/opt_out.