[🐛 Bug]: Multiple sessions are not initializing using testng with selenium 4
See original GitHub issueWhat happened?
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?
maven surefire plugin pom.txt testng.txt
`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);
}`
How can we reproduce the issue?
Try to run multiple methods using the config mentioned.
Relevant log output
FAILED: AT__Desktop_Test("MicrosoftEdge", "latest-1", "Windows 10", "", "", public void com.dell.tnt.tests.SoTest.Automation_Test.AT_30133_Desktop_Test(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.reflect.Method) throws java.lang.InterruptedException,com.dell.tnt.exceptions.OfferNotFoundException,java.io.IOException,java.lang.NullPointerException,java.lang.IndexOutOfBoundsException,java.lang.ArrayIndexOutOfBoundsException)
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: '7b1ebf28ef'
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: {name: AT_Premier_D..., platformName: Windows 10, resolution: 1920x1080}}], desiredCapabilities=Capabilities {browserName: MicrosoftEdge, browserVersion: latest-1, sauce:options: {name: AT_Premier_D..., platformName: Windows 10, resolution: 1920x1080}, seleniumVersion: 4.1.3}}]
Capabilities {}
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:585)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:248)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:164)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:146)
at com.dell.tnt.tests.BaseTestNew.createDriver(BaseTestNew.java:619)
at com.dell.tnt.tests.SoTest.Automation_Test.AT_Desktop_Test(Automation_Test.java:97)
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.TestMethodWithDataProviderMethodWorker.call(TestMethodWithDataProviderMethodWorker.java:77)
at org.testng.internal.TestMethodWithDataProviderMethodWorker.call(TestMethodWithDataProviderMethodWorker.java:15)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.io.UncheckedIOException: java.io.IOException: Stream closed
at org.openqa.selenium.remote.http.netty.NettyHttpHandler.makeCall(NettyHttpHandler.java:80)
at org.openqa.selenium.remote.http.AddSeleniumUserAgent.lambda$apply$0(AddSeleniumUserAgent.java:42)
at org.openqa.selenium.remote.http.Filter.lambda$andFinally$1(Filter.java:56)
at org.openqa.selenium.remote.http.netty.NettyHttpHandler.execute(NettyHttpHandler.java:51)
at org.openqa.selenium.remote.http.AddSeleniumUserAgent.lambda$apply$0(AddSeleniumUserAgent.java:42)
at org.openqa.selenium.remote.http.Filter.lambda$andFinally$1(Filter.java:56)
at org.openqa.selenium.remote.http.netty.NettyClient.execute(NettyClient.java:124)
at org.openqa.selenium.remote.tracing.TracedHttpClient.execute(TracedHttpClient.java:55)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:102)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:84)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:62)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:156)
at org.openqa.selenium.remote.TracedCommandExecutor.execute(TracedCommandExecutor.java:51)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:567)
... 20 more
Caused by: java.io.IOException: Stream closed
at java.base/java.io.BufferedInputStream.getBufIfOpen(BufferedInputStream.java:168)
at java.base/java.io.BufferedInputStream.reset(BufferedInputStream.java:444)
at org.asynchttpclient.netty.request.body.NettyInputStreamBody.write(NettyInputStreamBody.java:61)
at org.asynchttpclient.netty.request.NettyRequestSender.writeRequest(NettyRequestSender.java:433)
at org.asynchttpclient.netty.request.NettyRequestSender.sendRequestWithOpenChannel(NettyRequestSender.java:260)
at org.asynchttpclient.netty.request.NettyRequestSender.sendRequestWithCertainForceConnect(NettyRequestSender.java:142)
at org.asynchttpclient.netty.request.NettyRequestSender.sendRequest(NettyRequestSender.java:114)
at org.asynchttpclient.netty.request.NettyRequestSender.sendNextRequest(NettyRequestSender.java:562)
at org.asynchttpclient.netty.request.NettyRequestSender$3.lambda$call$0(NettyRequestSender.java:643)
at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:578)
at io.netty.util.concurrent.DefaultPromise.notifyListeners0(DefaultPromise.java:571)
at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:550)
at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:491)
at io.netty.util.concurrent.DefaultPromise.setValue0(DefaultPromise.java:616)
at io.netty.util.concurrent.DefaultPromise.setSuccess0(DefaultPromise.java:605)
at io.netty.util.concurrent.DefaultPromise.trySuccess(DefaultPromise.java:104)
at io.netty.handler.ssl.SslHandler.setHandshakeSuccess(SslHandler.java:1828)
at io.netty.handler.ssl.SslHandler.unwrap(SslHandler.java:1359)
at io.netty.handler.ssl.SslHandler.decodeJdkCompatible(SslHandler.java:1235)
at io.netty.handler.ssl.SslHandler.decode(SslHandler.java:1284)
at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:510)
at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:449)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:279)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:722)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:658)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:584)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:496)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
... 1 more
Operating System
Windows 10
Selenium version
Java 17.0.1
What are the browser(s) and version(s) where you see this issue?
Chrome 100, Firefox 91.7
What are the browser driver(s) and version(s) where you see this issue?
Chrome 100.0, geckodriver 0.30
Are you using Selenium Grid?
4.1.3
Issue Analytics
- State:
- Created a year ago
- Comments:17 (4 by maintainers)
Top GitHub Comments
@akshaychavan97 - This worked like a charm. Didn’t know the issue could be this. Thank you so much Akshay. 😃
I am also facing same issue, I am using platformName for creating session with saucelabs still issue persist. Add on - This works fine with first set of thread but when first test end and we try to create new session for next test this exception throws. Again for next test works as expected. If anyone can share sample project which works in parallel and implemented using thread concept for remote webdriver is much appreciated