WebDriverException: Session not available and is not among the last 1000 terminated sessions with GeckoDriver and Firefox in SeleniumGrid

a 夏天 提交于 2021-02-05 09:04:37

问题


Problem

When I execute 2 nodes of Firefox with 1 instance each no problem. But if I execute with 3 or more than 3 nodes getting the below error. No Problem if I execute 100 Test cases in chrome but seems Firefox not able to handle so many test cases. I have high config server with 64 GB RAM. I also observed, with 3 nodes the consumption of memory is never goes beyond 70%

HUB

java -jar selenium-server-standalone-3.14.0.jar -role hub -browserTimeout 30 -timeout 90

Node

java -Dwebdriver.gecko.driver=./geckodriver.exe -jar selenium-server-standalone-3.14.0.jar -role node  -hub http://localhost:4444/grid/register -browser browserName=firefox, -port 7771

Code Snap-1

private WebDriver firefoxDriver() {
WebDriver driver;
driver = null;
try{
    System.setProperty("webdriver.gecko.driver",Constants.sFirefoxDriverPath);

    FirefoxOptions opt= new FirefoxOptions();
    opt.setAcceptInsecureCerts(true);
    opt.setCapability("marionette", true);          
    driver = new RemoteWebDriver(new URL(Constants.sHubUrl), opt);
    driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
}catch(Exception ex){           
    logger.error("Error in Firefox Driver --> " , ex);
    driver.close();
}
return driver;

}

Code Snap -2

private WebDriver firefoxDriver() {
WebDriver driver;
driver = null;
try{
    System.setProperty("webdriver.gecko.driver",Constants.sFirefoxDriverPath);
    DesiredCapabilities cap = DesiredCapabilities.firefox();
    cap.setCapability("marionette",true);
    cap.setVersion("ANY");
    cap.setAcceptInsecureCerts(true);
    driver = new RemoteWebDriver(new URL(Constants.sHubUrl), cap);
    driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
}catch(Exception ex){           
    logger.error("Error in Firefox Driver --> " , ex);
    driver.close();
}
return driver;

}

Error Message

org.openqa.selenium.WebDriverException: Session [4c40e39b-ac68-459a-ac33-f77d5f7d57f8] not available and is not among the last 1000 terminated sessions.
Active sessions are[ext. key 6ee03f37-a595-4d82-a0e3-2aed3ff42df5, ext. key 6db69284-3582-4c6a-950b-7ca4e0bbc059, ext. key 5d3d5a41-101e-4bfc-858a-b20ae0e916fb]
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:19:58.91Z'
System info: host: 'XXXXXX', ip: 'XXX.XX.XXX.XXX', os.name: 'Windows Server 2012 R2', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_192'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities {acceptInsecureCerts: true, browserName: firefox, browserVersion: 63.0.1, javascriptEnabled: true, moz:accessibilityChecks: false, moz:geckodriverVersion: 0.23.0, moz:headless: false, moz:processID: 14432, moz:profile: C:\Users\XXXX\AppData\Local\..., moz:useNonSpecCompliantPointerOrigin: false, moz:webdriverClick: true, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, platformVersion: 6.3, rotatable: false, setWindowRect: true, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webdriver.remote.sessionid: 4c40e39b-ac68-459a-ac33-f77...}
Session ID: 4c40e39b-ac68-459a-ac33-f77d5f7d57f8
    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.RemoteWebDriver.execute(RemoteWebDriver.java:548)
    at org.openqa.selenium.remote.RemoteWebDriver$RemoteWebDriverOptions$RemoteTimeouts.implicitlyWait(RemoteWebDriver.java:776)
    at com.HCF_AutomationFramework_Selenium.keyWords.kDrivers.firefoxDriver(kDrivers.java:134)
    at com.HCF_AutomationFramework_Selenium.keyWords.kDrivers.kSelectDriver(kDrivers.java:42)
    at com.Modules.EmailQuote.TestCases.EmailQuote.EmailQuote_Referer_CustomiseCover(EmailQuote.java:93)
    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:86)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:643)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:820)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1128)
    at org.testng.internal.TestMethodWorker.invokeTestMethods (TestMethodWorker.java:129)    
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

回答1:


Some more information about your usecase might have helped us to analyze the issue in a better way. However, you need to take care a couple of facts as follows:

  • Initiating the Selenium Grid Hub with the following configuration seems insufficient:

    -browserTimeout 30 -timeout 90

  • You may consider setting them to the default value os follows:

    -browserTimeout 0 -timeout 1800

  • While initiating the Selenium Grid Node you need to provide the absolute path of the GeckoDriver as follows:

    java -Dwebdriver.gecko.driver=./geckodriver.exe -jar selenium-server-standalone-3.14.0.jar -role node  -hub http://localhost:4444/grid/register -browser browserName=firefox, -port 7771
    
  • You may consider setting them to the default value as follows:

    java -Dwebdriver.gecko.driver=C:/path/to/geckodriver.exe -jar selenium-server-standalone-3.14.0.jar -role node -port 7771 -hub http://localhost:4444/grid/register -browser "browserName=firefox, maxInstances=5, seleniumProtocol=WebDriver"
    

Additional Consideration

As per the following discussions:

  • Session [url] not available and is not among the last 1000 terminated sessions. How to solve this?
  • Selenium: Session externalKey not available

It seems this error occurs when:

  • Selenium Grid Hub, Selenium Grid Node and the Client Process are initiated/spawned from different versions of Selenium client.

Solution

Ensure that Selenium Grid Hub, Selenium Grid Node and the Client Process all of them uses the same version of Selenium client i.e. Selenium v3.141.59



来源:https://stackoverflow.com/questions/53331029/webdriverexception-session-not-available-and-is-not-among-the-last-1000-termina

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!