WebDriverException:会话不可用,不在SeleniumGrid中与GeckoDriver和Firefox一起的最近1000个终止会话中

时间:2018-11-16 03:33:34

标签: java selenium firefox selenium-grid geckodriver

问题

 当我执行带有1个实例的Firefox的2个节点时,都没有问题。但是,如果我用3个或3个以上的节点执行,则会出现以下错误。如果我在chrome中执行100个测试用例,那没问题,但是Firefox似乎无法处理那么多测试用例。我有64 GB RAM的高配置服务器。我还观察到,在3个节点的情况下,内存消耗永远不会超过70%

HUB

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

节点

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

代码捕捉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;

}

代码捕捉-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;

}

错误消息

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 个答案:

答案 0 :(得分:0)

关于您的用例的更多信息可能有助于我们更好地分析问题。但是,您需要注意以下两个事实:

  • 使用以下配置启动 Selenium Grid Hub 似乎是不够的:

    -browserTimeout 30 -timeout 90

  • 您可以考虑将它们设置为默认值os,如下所示:

    -browserTimeout 0 -timeout 1800

  • 启动硒网格节点时,您需要提供 GeckoDriver 绝对路径,如下所示:

    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
    
  • 您可以考虑将它们设置为默认值,如下所示:

    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"