I am facing tear down/Null pointer issues (org.openqa.selenium.SessionNotCreatedException) when running an entire class or a test suit which holds many methods on different browsers and devices. Tests are ran on saucelabs.
when a single method is run, it works absolutely fine but while running the entire class or a suite, it is not working. Also, few methods are passing (say like 3 methods) while the others are getting skipped or failed (going in tear down/Null Pointer or session not created). This is the same even if I am using maven plugin to run. Looks like the driver is not closing the session before starting a new one. What could be the possibilities ? am i missing anything?
Code
` private ThreadLocal webDriver = new ThreadLocal();
public WebDriver getWebDriver() {
// Starts the ThreadLocal<Boolean> for checking the evidon banner as false
hasEvidonBeenChecked.set(false);
if (!BaseTest.isLocal) {
return webDriver.get();
} else {
return localWebDriver;
}
}
@org.testng.annotations.Test(dataProvider = "remoteBrowsers", priority = 1)
public void TestPractive(String browser, String version, String os, String platformversion, String devicename,
Method method) throws InterruptedException, OfferNotFoundException, IOException, NullPointerException,
IndexOutOfBoundsException, ArrayIndexOutOfBoundsException {
this.createDriver(browser, version, os, platformversion, devicename, method.getName());
WebDriver driver = this.getWebDriver();
this.setupImplicitWait(driver, 20);
}`
FAILED CONFIGURATION: @AfterMethod tearDown java.lang.NullPointerException: Cannot invoke "org.openqa.selenium.JavascriptExecutor.executeScript(String, Object[])" because the return value of "java.lang.ThreadLocal.get()" is null
org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure. Build info: version: '4.1.3', revision: '87802e897b' System info: host: 'W105482ZY2', ip: '192.168.29.171', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.1' Driver info: org.openqa.selenium.remote.RemoteWebDriver Command: [null, newSession {capabilities=[Capabilities {browserName: MicrosoftEdge, browserVersion: latest-1, sauce:options:, desiredCapabilities=Capabilities {browserName: MicrosoftEdge, browserVersion: latest-1, sauce:options: , platformName: Windows 10, resolution: 1920x1080}, seleniumVersion: 4.1.3}}] Capabilities {}
Problem Statement
I am facing tear down/Null pointer issues (org.openqa.selenium.SessionNotCreatedException) when running an entire class or a test suit which holds many methods on different browsers and devices. Tests are ran on saucelabs.
when a single method is run, it works absolutely fine but while running the entire class or a suite, it is not working. Also, few methods are passing (say like 3 methods) while the others are getting skipped or failed (going in tear down/Null Pointer or session not created). This is the same even if I am using maven plugin to run. Looks like the driver is not closing the session before starting a new one. What could be the possibilities ? am i missing anything?
Code
` private ThreadLocal webDriver = new ThreadLocal();
XML testng.txt
Maven plugin pom: maven surefire plugin pom.txt
Any relate message in "Error Log" view
Default suite Total tests run: 9, Passes: 3, Failures: 3, Skips: 3 Configuration Failures: 3, Skips: 3
[AsyncHttpClient-1-8] ERROR org.asynchttpclient.netty.request.NettyRequestSender - Can't write request [AsyncHttpClient-1-10] ERROR org.asynchttpclient.netty.request.NettyRequestSender - Can't write request [AsyncHttpClient-1-9] ERROR org.asynchttpclient.netty.request.NettyRequestSender - Can't write request java.io.IOException: Stream closed
FAILED CONFIGURATION: @AfterMethod tearDown java.lang.NullPointerException: Cannot invoke "org.openqa.selenium.JavascriptExecutor.executeScript(String, Object[])" because the return value of "java.lang.ThreadLocal.get()" is null
org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure. Build info: version: '4.1.3', revision: '87802e897b' System info: host: 'W105482ZY2', ip: '192.168.29.171', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.1' Driver info: org.openqa.selenium.remote.RemoteWebDriver Command: [null, newSession {capabilities=[Capabilities {browserName: MicrosoftEdge, browserVersion: latest-1, sauce:options:, desiredCapabilities=Capabilities {browserName: MicrosoftEdge, browserVersion: latest-1, sauce:options: , platformName: Windows 10, resolution: 1920x1080}, seleniumVersion: 4.1.3}}] Capabilities {}
The Dependency Management tool for your project
TestNG - 7.4.0 Maven - 3.8.4 Selenium - 4.1.3
Operating System