i***@gmail.com
8 years ago
Hi All
Please bear with me for asking a silly question but iam curious to know the
technical reason for why iam getting 'Null pointer exception' for
literally a simple one line code. I have written code so many time but i
was trying to check whether
my system (new this time) has all files and exe's to run the Selenium Code
on my system.
So, was trying to add/download the files as and when it started giving me
error and fixing it up.
What iam trying to do : I wrote the script to check if all
files/jars/testng.exe are there to open the gmail page in my system and
close it.
*Code *:->
package pkg;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver.SystemProperty;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class TC_01 {
ChromeDriver driver;
@BeforeMethod
public void ST(){
System.setProperty("webdriver.chrome.driver",
"C:\\Selenium\\chromedriver.exe");
ChromeDriver driver = new ChromeDriver();
driver.get("https://www.google.com/gmail/about/#");
}
@Test
public void TM(){
}
@AfterMethod
public void CM(){
*driver.quit(); // Getting error at this point*
}
}
What error iam getting : Getting on line 26 : driver.quit
Starting ChromeDriver 2.32.498550
(9dec58e66c31bcc53a9ce3c7226f0c1c5810906a) on port 40532
Only local connections are allowed.
Sep 20, 2017 1:35:39 PM org.openqa.selenium.remote.ProtocolHandshake
createSession
INFO: Detected dialect: OSS
FAILED CONFIGURATION: @AfterMethod CM
java.lang.NullPointerException
at pkg.TC_01.CM(TC_01.java:26)
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:108)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:523)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:224)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:731)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:877)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1201)
at
org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:776)
at org.testng.TestRunner.run(TestRunner.java:634)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:425)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:420)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:385)
at org.testng.SuiteRunner.run(SuiteRunner.java:334)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1318)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1243)
at org.testng.TestNG.runSuites(TestNG.java:1161)
at org.testng.TestNG.run(TestNG.java:1129)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
PASSED: TM
My control is not reaching there. Any guidance would be appreciated.
Thanks in advance.
Please bear with me for asking a silly question but iam curious to know the
technical reason for why iam getting 'Null pointer exception' for
literally a simple one line code. I have written code so many time but i
was trying to check whether
my system (new this time) has all files and exe's to run the Selenium Code
on my system.
So, was trying to add/download the files as and when it started giving me
error and fixing it up.
What iam trying to do : I wrote the script to check if all
files/jars/testng.exe are there to open the gmail page in my system and
close it.
*Code *:->
package pkg;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver.SystemProperty;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class TC_01 {
ChromeDriver driver;
@BeforeMethod
public void ST(){
System.setProperty("webdriver.chrome.driver",
"C:\\Selenium\\chromedriver.exe");
ChromeDriver driver = new ChromeDriver();
driver.get("https://www.google.com/gmail/about/#");
}
@Test
public void TM(){
}
@AfterMethod
public void CM(){
*driver.quit(); // Getting error at this point*
}
}
What error iam getting : Getting on line 26 : driver.quit
Starting ChromeDriver 2.32.498550
(9dec58e66c31bcc53a9ce3c7226f0c1c5810906a) on port 40532
Only local connections are allowed.
Sep 20, 2017 1:35:39 PM org.openqa.selenium.remote.ProtocolHandshake
createSession
INFO: Detected dialect: OSS
FAILED CONFIGURATION: @AfterMethod CM
java.lang.NullPointerException
at pkg.TC_01.CM(TC_01.java:26)
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:108)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:523)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:224)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:731)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:877)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1201)
at
org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:776)
at org.testng.TestRunner.run(TestRunner.java:634)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:425)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:420)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:385)
at org.testng.SuiteRunner.run(SuiteRunner.java:334)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1318)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1243)
at org.testng.TestNG.runSuites(TestNG.java:1161)
at org.testng.TestNG.run(TestNG.java:1129)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
PASSED: TM
My control is not reaching there. Any guidance would be appreciated.
Thanks in advance.
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+***@googlegroups.com.
To post to this group, send email to selenium-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/9f19e642-8fe3-4a70-988c-d931447a35bb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+***@googlegroups.com.
To post to this group, send email to selenium-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/9f19e642-8fe3-4a70-988c-d931447a35bb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.