FAILED: beforetest
java.lang.NullPointerException: Cannot invoke “org.openqa.selenium.WebDriver.manage()” because “this.driver” is null
at Test_Scenarios.LoginPageScenarios.beforetest(LoginPageScenarios.java:19)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:133)
at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:598)
at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:173)
at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:824)
at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:146)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at org.testng.TestRunner.privateRun(TestRunner.java:794)
at org.testng.TestRunner.run(TestRunner.java:596)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:377)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:371)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:332)
at org.testng.SuiteRunner.run(SuiteRunner.java:276)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1212)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1134)
at org.testng.TestNG.runSuites(TestNG.java:1063)
at org.testng.TestNG.run(TestNG.java:1031)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
===============================================
Default test
Tests run: 2, Failures: 2, Skips: 0
Configuration Failures: 1, Skips: 0
===============================================
===============================================
Default suite
Total tests run: 2, Passes: 0, Failures: 2, Skips: 0
Configuration Failures: 1, Skips: 0
===============================================
Your WebDriver is not defined in beforeTest:
The solution to the “java.lang.nullpointerexception: cannot invoke “org.openqa.selenium.webdriver.manage()” because “this.driver” is null” error is to initialize the “driver” object before calling the “org.openqa.selenium.webdriver.manage()” method.
Here is an example of how to initialize the “driver” object using the Selenium WebDriver:
System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");
WebDriver driver = new ChromeDriver();
This code sets the path to the ChromeDriver executable and creates a new instance of the ChromeDriver, which is then assigned to the “driver” object.
Make sure that you have the Selenium WebDriver and browser driver (e.g. ChromeDriver for Chrome) installed and configured properly in your system, and the path to the driver is correct.
You can then use the “driver” object to perform various actions, such as navigating to a webpage, clicking on elements, etc. before using the “org.openqa.selenium.webdriver.manage()” method.
driver.get("https://www.example.com");
It’s also worth to check that the driver object is not being set to null somewhere in the code before calling the “org.openqa.selenium.webdriver.manage()” method.