Problem: My classes are Hooks for setup and test. I try to click on cookie pop-up, using WebdriverWait, but don't work. I have no idea why.
I am a beginner with selenium and automation testing and I am writing a selenium script using java, TestNG, and maven. When I write everything in one class, all works fine, but I want to have a package for all objects, a package for tests, and Hooks with the main setting. What I do public class Hooks { public WebDriver driver; @BeforeMethod public void Setup() throws InterruptedException { //set property for driver, Firefox instance System.setProperty("webdriver.driver.firefox", "C://SeleniumWebdrivers//chromedriver.exe"); //create driver object WebDriver driver = new ChromeDriver(); //Maximize page driver.manage().window().maximize(); //implicit wait driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS); driver.get("http://google.com/"); //scroll // JavascriptExecutor js = (JavascriptExecutor) driver; // js.executeScript("window.scrollBy(0,600)"); }
@AfterMethod
public void TearDown(){
driver.quit();
}
For test
public class Tests extends Hooks{
@Test
public void Test() throws InterruptedException{
//Arrange
HomePage homePage = new HomePage(driver);
//Act
WebDriverWait wait = new WebDriverWait(driver, 6000);
wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("#onetrust-accept-btn-handler"))).click();
//Assert
Assert.assertEquals("EVALUAREA APARATULUI LOCOMOTOR", "EVALUAREA APARATULUI LOCOMOTOR")
}
And the errors are:
java.lang.NullPointerException
at java.util.Objects.requireNonNull(Objects.java:203)
at org.openqa.selenium.support.ui.FluentWait.<init>(FluentWait.java:106)
at org.openqa.selenium.support.ui.WebDriverWait.<init>(WebDriverWait.java:85)
at org.openqa.selenium.support.ui.WebDriverWait.<init>(WebDriverWait.java:45)
at Tests.Test(Tests.java:15)
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: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.util.ArrayList.forEach(ArrayList.java:1259)
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 com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:66)
at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:109)
How can I fix these errors and why do they occur?
What I tried: I tried to add Hooks class, I added different properties for my class
HomePage
class ? what constructor it has ? Attach screenshot of Package structure . AdditionallySystem.setProperty
is wrongly set up, you have chromedriver exe for firefox instance. – cruisepandey