Error while executing Selenium script - java.lang.NullPointerException - TestNG

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Error while executing Selenium script - java.lang.NullPointerException - TestNG



I'm trying to run a script via testNG. But getting java.lang.NullPointerException. I have put in the driver initialisation code in BeforeMethod and rest of the code under Test. Please let me know what's wrong in my script due which Im getting the error.Thanks in Advance.



My Script:


public class NewTest {

WebDriver driver = null;
@BeforeMethod
public void beforeMethod() {

System.setProperty("webdriver.chrome.driver", Constants.Chrome_Driver);

WebDriver driver = new ChromeDriver();

driver.manage().window().maximize();

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

driver.get("http://" + Constants.auth_Username + ":" + Constants.auth_Password + "@" + Constants.URL);
}

@Test
public void f() throws InterruptedException {

actions.Admin_Login.txbx_aUsername(driver).sendKeys(Constants.aUsername);

actions.Admin_Login.txbx_aPassword(driver).sendKeys(Constants.aPassword);

actions.Admin_Login.btn_login(driver).click();

actions.create(driver).click();

Actions action = new Actions(driver);
action.moveToElement(actions.create.list(driver)).build().perform();

//Create a Course Category

actions.create_list.list_category(driver).click();

actions.create_list.list_ceate_category(driver).click();

actions.create_list.txtbx_Cat_tile(driver).sendKeys(Constants.list_title);

actions.create_list.btn_Cat_Save(driver).click();

System.out.println("List Created Successfully");
}

}



I am using PageObjects to get the data. This script is running fine without testNG. But when I convert the test into testNG and execute, it throws error.



Error I am facing:


java.lang.NullPointerException
at actions.Admin_Login.txbx_aUsername(Admin_Login.java:13)
at testScripts.NewTest.f(NewTest.java:43)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:580)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:716)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:988)
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:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
at org.testng.TestNG.runSuites(TestNG.java:1049)
at org.testng.TestNG.run(TestNG.java:1017)
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)





Possible duplicate of What is a NullPointerException, and how do I fix it?
– sidgate
2 mins ago









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Visual Studio Code: How to configure includePath for better IntelliSense results

C++ virtual function: Base class function is called instead of derived