Session ID is null. Using WebDriver after calling quit()?

5,540 views
Skip to first unread message

Arvind Sah

unread,
Aug 4, 2020, 1:21:33 AM8/4/20
to Selenium Users

Hello Selenium Users, 

 

I need help with the below error which I am facing from past couple of days. Please note this doesn't happen all the time, out of 4 jobs it will fail for 1 or 2 jobs.

 

Below error occur sometimes when it's executing 10th or 30 or nth test script - 

 

Error - Session ID is null. Using WebDriver after calling quit()?

 

Error logs- 

 

546I am in onTestSuccess method TEST41 succeed

546closing browser

547I am in onTestFailure method TEST41 failed

548Screenshot captured for test case :- TEST41

549[TestHTMLReporter] The system cannot find the path specified

550I am in onFinish method Smoke suite Tests Scripts

551[ERROR] Session ID is null. Using WebDriver after calling quit()?

552Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'

553System info: host: 'EC2AMAZ-MSGKABO', os.name: 'Windows Server 2019', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_262'

554Driver info: driver.version: RemoteWebDriver

555[INFO]

556[INFO] Results:

557[INFO]

558[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[INFO]

560[ERROR] There are test failures.

561Please refer to C:\GitLab-Runner\builds\abc\target\surefire-reports for the individual test results.

562Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.

563There was an error in the forked process

564Session ID is null. Using WebDriver after calling quit()?

565Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'

566System info: , os.name: 'Windows Server 2019', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_262'

567Driver info: driver.version: RemoteWebDriver

568org.apache.maven.surefire.booter.SurefireBooterForkException: There was an error in the forked process

569Session ID is null. Using WebDriver after calling quit()?

570Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'

571System info: os.name: 'Windows Server 2019', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_262'

 

 

Driver info: driver.version: RemoteWebDriver

573 at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:733)

574 at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:305)

575 at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:265)

576 at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider(AbstractSurefireMojo.java:1314)

577 at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(AbstractSurefireMojo.java:1159)

578 at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(AbstractSurefireMojo.java:932)

579 at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)

580 at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)

581 at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)



 

System Info:

Java- 1.8

Maven 3.0.0-M5

Testng- 6.14.3

 

 

Browser Initialization (BasePage)-

 

private static ThreadLocal<WebDriver> tldriver = new ThreadLocal<WebDriver>();

           

            public synchronized static WebDriver getDriver() {

                        return tldriver.get();

            }

           

            public WebDriver init_driver(String browerName, String url)  {

                        stepComment("launch the "+ browerName + " browser" );

                       

                       

                        highlightElement = prop.getProperty("highlight").equals("true") ? true : false;

                        optionsManager= new OptionsManager(prop);

                        switch(browerName.toLowerCase()) {

                        case "chrome" :

                                    WebDriverManager.chromedriver().setup();

                                    tldriver.set(new ChromeDriver(optionsManager.getChromeOptions()));

                                    break;

 

 

            @BeforeMethod(alwaysRun=true)

            public synchronized void setup() {

                        basePage = new BasePage();

                        prop = basePage.init_properties();

                        browser = prop.getProperty("browser");

                        url = prop.getProperty("url");

                        basePage.init_driver(browser, url);

            }

 

            @AfterMethod(alwaysRun = true)

            public synchronized void tearDown(){

                       

                        stepComment("closing browser");

                    getDriver().quit();           

                                   

                        }

            }

           

 

 

 

Tried looking for some solution but seems like none of them solved the issue -

https://stackoverflow.com/questions/41352248/sessionnotfoundexception-session-id-is-null-using-webdriver-after-calling-quit

 

Thanks and Regards,

Arvind

 

 

Radhika Joshi

unread,
Aug 4, 2020, 2:36:29 AM8/4/20
to seleniu...@googlegroups.com
This is because once you have called quit, you need to instantiate the webdriver once again. The webdriver closes after calling quit() method. Make sure you return a driver object in the base class everytime you call it.

Regards,
Radhika Joshi

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/2b960d1f-853d-4a45-b751-50aa0973ea28o%40googlegroups.com.

Arvind Sah

unread,
Aug 4, 2020, 3:31:46 AM8/4/20
to Selenium Users
Hello Radhika, 

Thank you so much for your valuable response and for your time.

For every test method I am re-instantiating the browser and keeping the driver instance as part of threadLocal and calling it as and when needed. 

Please note- this error doesn't comes always, sometimes it comes after completing 40 or 50 script

BasePage method where am instantiating the driver


private static ThreadLocal<WebDriver> tldriver = new ThreadLocal<WebDriver>();
 
 
public synchronized static WebDriver getDriver() {
 
return tldriver.get();
 
}

public WebDriver init_driver(String browerName, String url)  {
stepComment("launch the "+ browerName + " browser" );
highlightElement = prop.getProperty("highlight").equals("true") ? true : false;
optionsManager= new OptionsManager(prop);

switch(browerName.toLowerCase()) {
case "chrome" :
WebDriverManager.chromedriver().setup();
tldriver.set(new ChromeDriver(optionsManager.getChromeOptions()));
break;



Below are my before and after methods

@BeforeMethod
(alwaysRun=true)
 
public void setup() {

 
 basePage
= new BasePage();
 prop
= basePage.init_properties();
 browser
= prop.getProperty("browser");
 url
= prop.getProperty("url");
 basePage
.init_driver(browser, url);
 
}


 
@AfterMethod(alwaysRun = true)

 
public void tearDown() {


 
if (!getDriver().toString().contains("(null)")) {


 stepComment("closing browser");
 getDriver().quit();


 
}
 
}


public WebDriver getDriver() {
return BasePage.getDriver();
}
 
}



Error logs (this error doesn't comes always, sometimes it comes after completing 40 or 50 script)
line
Number 800+


I am
in onTestSkipped method CheckUserAbleToMakePaymentUsingPVandCreditCard skipped
Screenshot captured for test case :- CheckUserAbleToMakePaymentUsingPVandCreditCard
I am
in onTestFailure method CheckUserAbleToMakePaymentUsingPVandCreditCard failed
Screenshot captured for test case :- CheckUserAbleToMakePaymentUsingPVandCreditCard
[TestHTMLReporter] The system cannot find the path specified
I am
in onFinish method Smoke suite Tests Scripts
[ERROR] Session ID is null. Using WebDriver after calling quit()?
Build info: version: '3.141.59', revision: '', time: '2018-11-14T08:17:03'
System info: host: 'EC2AMAZ-', ip: '', os.name: 'Windows Server 2019', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_262'
Driver info: driver.version: RemoteWebDriver
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0


Thanks and Regards,
Arvind Sah
To unsubscribe from this group and stop receiving emails from it, send an email to seleniu...@googlegroups.com.

⇜Krishnan Mahadevan⇝

unread,
Aug 4, 2020, 3:38:09 AM8/4/20
to Selenium Users
Show us the full stacktrace when the problem arises ?
Your webdriver is threadsafe (via ThreadLocal) but what about the page objects that are using the WebDriver instance? Are they thread safe ?


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribblings @ https://rationaleemotions.com/


To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/ac7e28ca-f2ab-46b2-9a49-69a6c52e5e91o%40googlegroups.com.

Radhika Joshi

unread,
Aug 4, 2020, 3:42:11 AM8/4/20
to seleniu...@googlegroups.com
Hey 
I had faced a similar problem.
try modifying your getdriver code and return an object of the newly created driver everytime you instantiate it. The error is because after quitting it, the script loses control of the driver.


Regards
Radhika Joshi

To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/ac7e28ca-f2ab-46b2-9a49-69a6c52e5e91o%40googlegroups.com.

Arvind Sah

unread,
Aug 4, 2020, 3:55:39 AM8/4/20
to Selenium Users
Hello Krishnan Mahadevan,

Below is the stacktrace of the issue. Some more info about the issue- sometimes they just run fine, all 100+ scripts run successfully ( with some failure) and sometimes they exit after executing 40 or 60 scripts

ChromeDriver was started successfully.
I am in onTestSkipped method TestMethod101 skipped
Screenshot captured for test case :- TestMethod101 
I am in onTestFailure method TestMethod101 failed
Screenshot captured for test case :- TestMethod101 
[TestHTMLReporter] The system cannot find the path specified
I am in onFinish method Smoke suite Tests Scripts 
[ERROR] Session ID is null. Using WebDriver after calling quit()?
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info:  os.name: 'Windows Server 2019', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_262'
Driver info: driver.version: RemoteWebDriver
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] 
[ERROR] There are test failures.
Please refer to C:\GitLab-Runner\builds\projectname\target\surefire-reports for the individual test results.
Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
There was an error in the forked process
Session ID is null. Using WebDriver after calling quit()?
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info:  os.name: 'Windows Server 2019', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_262'
Driver info: driver.version: RemoteWebDriver
org.apache.maven.surefire.booter.SurefireBooterForkException: There was an error in the forked process
Session ID is null. Using WebDriver after calling quit()?
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host:  os.name: 'Windows Server 2019', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_262'
Driver info: driver.version: RemoteWebDriver
at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:733)
at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:305)
at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:265)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider(AbstractSurefireMojo.java:1314)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(AbstractSurefireMojo.java:1159)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(AbstractSurefireMojo.java:932)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:957)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:289)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:193)
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.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)
[INFO] 
[INFO] --- maven-surefire-plugin:3.0.0-M5:test (default) @  ---
[INFO] Skipping execution of surefire because it has already been run for this configuration
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @  ---
[INFO] Building jar: C:\GitLab-Runner\builds\projectname\target\
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) 
[INFO] Installing C:\GitLab-Runner\builds\
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  37:58 min
[INFO] Finished at: 2020-08-03T15:56:19Z


Sample Test method

public class OrderJourneyTest extends BaseTest {

DashaboardPage dashaboardPage;
@Test
public void placeSingleOrderUsingCreditCard() {
dashaboardPage = new LoginPage(getDriver()).doLoginUsingMobileNumber(getCredentialsNewPC());
}



Sample page objects class
public class LoginPage extends BasePage{
private final WebDriver driver;
ElementUtil elementUtil;
JSUtil jsUtil;
/**
* constructor to set the driver instance and initialize the other variables
* @param driver
*/
public LoginPage(WebDriver driver) {
this.driver= driver;
elementUtil=new ElementUtil(driver) ;
jsUtil= new JSUtil(driver);
}
}


⇜Krishnan Mahadevan⇝

unread,
Aug 4, 2020, 4:08:30 AM8/4/20
to Selenium Users
Arvind,

Can you open up your surefire reports and see if you can find the stacktrace which is relevant to a WebDriver call ?
The stacktrace you shared is basically the Maven surefire plugin conking because of an exception.

What I am looking for is the call stacktrace that can be tied to an "execute" call that gets invoked from within RemoteWebDriver.


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribblings @ https://rationaleemotions.com/

To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/9cf1b045-d5c5-4fc5-abb6-167372bf7580o%40googlegroups.com.

Arvind Sah

unread,
Aug 4, 2020, 4:43:50 AM8/4/20
to Selenium Users

Hello  Krishnan Mahadevan,  

Thank you for your response, upon further I analysis I could see that when execution is about to exit it won't be instantiating the driver instance as I don't see the statement being called for launching the browser.

I will  re-run the suite again and will share the logs from surefire reports.


launch the chrome browser
929ChromeDriver was started successfully.
930I am in onTestSkipped method Test101 skipped
931Screenshot captured for test case :- Test101
932I am in onTestFailure method  Test101   failed
933Screenshot captured for test case :- Test101
934[TestHTMLReporter] The system cannot find the path specified
935I am in onFinish method Regression suite Stage 1 Tests Scripts
936[ERROR] Session ID is null. Using WebDriver after calling quit()?


Thanks and Regards,
Arvind Sah

Arvind Sah

unread,
Aug 4, 2020, 9:01:22 AM8/4/20
to Selenium Users
Hello Krishnan Mahadevan,

I could find below 2 types of file under surefire-reports folder ( I ran the suite 4 times and it got failed once)

1. 2020-08-04T11-11-25_325-jvmRun1.dumpstream
2. 2020-08-04T11-11-25_325-jvmRun1.dump


2020-08-04T11-11-25_325-jvmRun1.dumpstream



# Created at 2020-08-04T11:59:13.321
invalid session id
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: , os.name: 'Windows Server 2019', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_262'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 84.0.4147.105, chrome: {chromedriverVersion: 84.0.4147.30 (48b3e868b4cc0..., userDataDir: C:\Users\arvind.sah\AppData...}, goog:chromeOptions: {debuggerAddress: localhost:56134}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:virtualAuthenticators: true}
Session ID: c86ec20556ca9fd09d97e457672b2444




2020-08-04T11-11-25_325-jvmRun1.dump


# Created at 2020-08-04T11:59:13.289
org.openqa.selenium.NoSuchSessionException: invalid session id
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: os.name: 'Windows Server 2019', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_262'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 84.0.4147.105, chrome: {chromedriverVersion: 84.0.4147.30 (48b3e868b4cc0..., userDataDir: C:\Users\arvind.sah\AppData...}, goog:chromeOptions: {debuggerAddress: localhost:56134}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:virtualAuthenticators: true}
Session ID: c86ec20556ca9fd09d97e457672b2444
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:609)
at org.openqa.selenium.remote.RemoteWebDriver.getScreenshotAs(RemoteWebDriver.java:295)
at com.test.listeners.TestAllureListener.saveScreenshotPNG(TestAllureListener.java:32)
at com.test.listeners.TestAllureListener.onTestFailure(TestAllureListener.java:79)
at org.testng.internal.TestListenerHelper.runTestListeners(TestListenerHelper.java:67)
at org.testng.internal.Invoker.runTestListeners(Invoker.java:1389)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1042)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
at org.testng.TestNG.runSuites(TestNG.java:1049)
at org.testng.TestNG.run(TestNG.java:1017)
at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:284)
at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:75)
at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:119)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:428)
at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:162)
at org.apache.maven.surefire.booter.ForkedBooter.run(ForkedBooter.java:562)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:548)




Gitlab consol logs

launch the chrome browser
ChromeDriver was started successfully.
Aug 04, 2020 11:59:08 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Before window size - (800, 600)
After window size - (1382, 768)
I am in onTestSkipped method TEST101 skipped
Screenshot captured for test case :- TEST101 
I am in onTestFailure method TEST101 failed
Screenshot captured for test case :- TEST101 
[TestHTMLReporter] The system cannot find the path specified
I am in onFinish method Smoke suite Tests Scripts 
[ERROR] invalid session id
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info:  os.name: 'Windows Server 2019', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_262'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 84.0.4147.105, chrome: {chromedriverVersion: 84.0.4147.30 (48b3e868b4cc0..., userDataDir: C:\Users\arvind.sah\AppData...}, goog:chromeOptions: {debuggerAddress: localhost:56134}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:virtualAuthenticators: true}
Session ID: c86ec20556ca9fd09d97e457672b2444
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] 
[ERROR] There are test failures.
Please refer to C:\GitLab-Runner\builds\projectaname\target\surefire-reports for the individual test results.
Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
There was an error in the forked process
invalid session id
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info:  os.name: 'Windows Server 2019', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_262'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 84.0.4147.105, chrome: {chromedriverVersion: 84.0.4147.30 (48b3e868b4cc0..., userDataDir: C:\Users\arvind.sah\AppData...}, goog:chromeOptions: {debuggerAddress: localhost:56134}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:virtualAuthenticators: true}
Session ID: c86ec20556ca9fd09d97e457672b2444
org.apache.maven.surefire.booter.SurefireBooterForkException: There was an error in the forked process
invalid session id
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'EC2AMAZ-MSGKQS0', ip: '10.124.68.151', os.name: 'Windows Server 2019', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_262'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 84.0.4147.105, chrome: {chromedriverVersion: 84.0.4147.30 (48b3e868b4cc0..., userDataDir: C:\Users\arvind.sah\AppData...}, goog:chromeOptions: {debuggerAddress: localhost:56134}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:virtualAuthenticators: true}
Session ID: c86ec20556ca9fd09d97e457672b2444

Thanks and Regards,
Arvind Sah

⇜Krishnan Mahadevan⇝

unread,
Aug 4, 2020, 9:22:16 AM8/4/20
to Selenium Users
Aravind,

This is exactly what I was having as a hunch:

at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:609)
at org.openqa.selenium.remote.RemoteWebDriver.getScreenshotAs(RemoteWebDriver.java:295)
at com.test.listeners.TestAllureListener.saveScreenshotPNG(TestAllureListener.java:32)
at com.test.listeners.TestAllureListener.onTestFailure(TestAllureListener.java:79)
at org.testng.internal.TestListenerHelper.runTestListeners(TestListenerHelper.java:67)


This stacktrace kind of confirms that the culprit is your listener. Your listener seems to be the culprit.

The fact that you are relying on "onTestFailure" seems to be indicating that you dont perhaps have a valid WebDriver here since you are dealing with ThreadLocal variant.

Instead of relying on org.testng.ITestListener to trigger the capture screenshot activity, I would suggest that you move the functionality into org.testng.IInvokedMethodListener implementation wherein within its afterInvocation() you check if the test failed and then trigger a call to save screenshot.


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribblings @ https://rationaleemotions.com/

To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/bdaa92f9-1953-418e-b729-7d4082bb5f3ao%40googlegroups.com.

Arvind Sah

unread,
Aug 4, 2020, 11:15:58 AM8/4/20
to Selenium Users
Hello Krishnan Mahadevan,

Thank you so much for the response. I will try changing the the listener "IInvokedMethodListener" and see if this resolves the issue.


Note - Previously had tried commenting the commenting "onTestFailure" method itself but the result was same. 


Thanks and Regards,
Arvind Sah

Arvind Sah

unread,
Aug 5, 2020, 12:38:19 AM8/5/20
to Selenium Users
Hello Krishnan Mahadevan,

Greeting for the Day!!!


I tried adding the  "IInvokedMethodListener" listener but the result is it same still I could see that scripts are getting failed while taking the screenshot. Even though right now am running scripts serially but still for some reason driver instance is getting closed. 

Just a thought- could this be possible that @AfterMethod is running parallel to listeners which are added into testng.xml file. Is there any way I can make sure that listeners are always executed before @AfterMethod execution.


Error logs after implementing "IInvokedMethodListener" listener



com.test.Test053#tearDown
Exception
org.openqa.selenium.NoSuchSessionException: Session ID is null. Using WebDriver after calling quit()?
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_251'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:125)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:609)
at org.openqa.selenium.remote.RemoteWebDriver.getScreenshotAs(RemoteWebDriver.java:295)
at com.test.listeners.TestAllureListener2.saveScreenshotPNG(TestAllureListener2.java:29)
at com.test.listeners.TestAllureListener2.afterInvocation(TestAllureListener2.java:114)
... Removed 29 stack frames


com.test.Test062#tearDown
Exception
org.openqa.selenium.NoSuchSessionException: Session ID is null. Using WebDriver after calling quit()?
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: , os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_251'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:125)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:609)
at org.openqa.selenium.remote.RemoteWebDriver.getScreenshotAs(RemoteWebDriver.java:295)
at com.test.listeners.TestAllureListener2.saveScreenshotPNG(TestAllureListener2.java:29)
at com.test.listeners.TestAllureListener2.afterInvocation(TestAllureListener2.java:114)
... Removed 29 stack frames




 "IInvokedMethodListener" listener Implementation

public class TestAllureListener2 implements IInvokedMethodListener

@Override
public void afterInvocation(IInvokedMethod method, ITestResult testResult) {

if ((testResult.isSuccess() && method.isTestMethod())) {
log.info("I am in onTestSuccess method " + getTestMethodName(testResult) + " succeed");
}

else {
log.error("I am in onTestFailure method " + getTestMethodName(testResult) + " failed");
if (getDriver() instanceof WebDriver) {
System.out.println("Screenshot captured for test case :- " + getTestMethodName(testResult));
saveScreenshotPNG(getDriver());
}

saveTextLog(getTestMethodName(testResult) + " failed and screenshot taken!");
}

}

@Attachment(value = "Page screenshot", type = "image/png")
public byte[] saveScreenshotPNG(WebDriver driver) {
return ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
}


testng.xml file 

<suite name="Regression Suite "   >

<listeners>
<listener class-name="com.test.listeners.RetryListener"/>
      <listener class-name="com.test.listeners.TestAllureListener2" />
</listeners>


sai charan

unread,
Aug 6, 2020, 10:00:08 AM8/6/20
to seleniu...@googlegroups.com
Hello Krishnan,

Sorry to deviate from the problem here. You have said  " Your web driver is threadsafe (via ThreadLocal) but what about the page objects that are using the WebDriver instance? Are they thread-safe ?"

Is there any better way to make the page objects also thread-safe? Can you please throw some light here if possible?

Many thanks
Sai

To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/cdfff3ee-2b60-4ac0-870b-62cec9285fdeo%40googlegroups.com.


--

⇜Krishnan Mahadevan⇝

unread,
Aug 6, 2020, 2:06:28 PM8/6/20
to Selenium Users
To make the page objects also threadsafe, their instantiation should be confined within the test method which is where the webdriver instance is created as a thread local.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribblings @ https://rationaleemotions.com/

Reply all
Reply to author
Forward
0 new messages