java.lang.NullPointerException thrown on explicit / implicit waits with testng?
See original GitHub issueTestNG Windows timeouts
suite.windows.timeout=15000
@Test(description = "Suite Timeout Log and Report Test")
public void testSuite() {
try {
Thread.sleep(100000);
} catch (InterruptedException e) {
Assert.fail("Sleep Interrupt: We most likely hit the testng timeout set by suite.windows.timeout in build.properties", e.getCause());
}
}
This works as expected and I get:
org.testng.internal.thread.ThreadTimeoutException: Method org.testng.internal.TestNGMethod.testSuite() didn't finish within the time-out 15000
java.lang.Thread.sleep(Native Method)
timeoutTests.testSuite(Unknown Source)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) (with others of java.lang.reflect.\* or sun.reflect.\* omitted)
org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84) (with others of org.testng.\* omitted)
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
java.util.concurrent.FutureTask.run(FutureTask.java:262)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
java.lang.Thread.run(Thread.java:745)
org.testng.internal.thread.ThreadTimeoutException: Method org.testng.internal.TestNGMethod.testSuite() didn't finish within the time-out 15000
When I use explicit waits and do something like:
@Test(description = "Suite Timeout Log and Report Test")
public void testSuite() {
WebDriverWait wait = new WebDriverWait(getDriver(), 30);
try {
wait.until(ExpectedConditions.presenceOfElementLocated(By
.xpath("//label[text()='" + applicationName + "']")));
} catch (TimeoutException e) {
Assert.fail("FAILED because The GUI is taking too long to load..." + TIMEOUT + " Seconds have passed. " + "Does the Production build startup wihtout error?", e.getCause());
}
}
I get:
FAILED - testSuite - AutomationTest @ 08:54:58:694
java.lang.NullPointerException
com.google.common.base.Preconditions.checkNotNull(Preconditions.java:210)
org.openqa.selenium.support.ui.FluentWait.(FluentWait.java:94)
org.openqa.selenium.support.ui.WebDriverWait.(WebDriverWait.java:70)
org.openqa.selenium.support.ui.WebDriverWait.(WebDriverWait.java:44)
timeoutTests.testSuite(Unknown Source)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) (with others of java.lang.reflect.\* or sun.reflect.\* omitted)
org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84) (with others of org.testng.\* omitted)
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
java.util.concurrent.FutureTask.run(FutureTask.java:262)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
java.lang.Thread.run(Thread.java:745)
java.lang.NullPointerException
When I use implicit waits (doesn’t matter if suite.windows.timeout is less than or greater than the wait on implicitlyWait(30…)
@Test(description = "Suite Timeout Log and Report Test")
public void testSuite() {
//Implicit wait test
getDriver().manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
WebElement myDynamicElement = getDriver().findElement(By.id("myFakeElementId"));
myDynamicElement.getText();
}
I get:
FAILED - testSuite - AutomationTest @ 09:16:38:297
java.lang.NullPointerException
timeoutTests.testSuite(Unknown Source)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) (with others of java.lang.reflect.\* or sun.reflect.\* omitted)
org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84) (with others of org.testng.\* omitted)
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
java.util.concurrent.FutureTask.run(FutureTask.java:262)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
java.lang.Thread.run(Thread.java:745)
java.lang.NullPointerException
I am noticing that the Browser will come up on the node, then immediately exit out on the @test with the waits (explicit/ or implicit)
My @BeforeClass
is:
@BeforeClass
public void setUp() {
this.browserName = "firefox";
this.hubURL = "http://10.223.172.178:4444/wd/hub";
this.automationUrl = "http://10.223.175.99/app-automation/web";
threadDriver = new ThreadLocal<RemoteWebDriver>();
if (this.browserName.equalsIgnoreCase("firefox")) {
dc = DesiredCapabilities.firefox();
dc.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR,
UnexpectedAlertBehaviour.DISMISS);
FirefoxProfile fp = new FirefoxProfile();
fp.setAcceptUntrustedCertificates(true);
dc.setCapability(FirefoxDriver.PROFILE, fp);
dc.setBrowserName(DesiredCapabilities.firefox().getBrowserName());
}
dc.setCapability(CapabilityType.SUPPORTS_ALERTS, true);
dc.setCapability(CapabilityType.SUPPORTS_APPLICATION_CACHE, true);
dc.setCapability(CapabilityType.SUPPORTS_FINDING_BY_CSS, true);
dc.setCapability(CapabilityType.SUPPORTS_JAVASCRIPT, true);
dc.setCapability(CapabilityType.SUPPORTS_NETWORK_CONNECTION, true);
dc.setCapability(CapabilityType.SUPPORTS_WEB_STORAGE, true);
dc.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
dc.setCapability(CapabilityType.TAKES_SCREENSHOT, true);
try {
threadDriver.set(new RemoteWebDriver(new URL(this.hubURL), dc));
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
getDriver().get(this.automationUrl);
this.sessionId = threadDriver.get().getSessionId().toString();
System.out.println("SETUP - " + this.sessionId);
}
Issue Analytics
- State:
- Created 8 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
java.lang.NullPointerException on explicit wait - Stack Overflow
The Implicit wait is turned off before the loop, specifically because I am using the explicit wait and ensuring that I don't mix...
Read more >Web Driver throws nullpointer exception while trying to find ...
May be find elements is taking time to the element path better use implicit or explicit wait condition so it will wait till...
Read more >Getting Java Null Pointer Exception on running the test case in ...
Hello @sandhya ,. Java.lang.RuntimeException: java.lang.NullPointerException is thrown when an application attempts to use null in a case where ...
Read more >Selenium Wait – Implicit, Explicit and Fluent Waits - Guru99
The Implicit Wait in Selenium is used to tell the web driver to wait for a certain amount of time before it throws...
Read more >Page Object Model (POM) With Page Factory | Selenium Tutorial
Besides, there will be another JUNIT or TestNG or a Java class file ... then “initialize variable” error or NullPointerException is thrown.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@cktech529 This doesnt look to be a problem with TestNG but seems more of an issue related to a null
WebDriver
instance being retrieved viagetDriver()
method and that null being passed toWebDriverWaits
to perform the explicit waits.I am closing this issue.
@AlokATrivedi - For your issue, please file a new issue, and include all required details.
So Even I was facing the same issue. But the problem here is not TestNg. The real problem is you must have been initialising the driver instance twice and that actually confuses the complier and it throws null pointer exception. Just make sure you pass current class driver instance to explicit wait method where ever u have defined it and it will work perfectly as expected… I hope it clears it now.