【问题标题】:org.openqa.selenium.WebDriverException: Session [null] not available and is not among the last 1000 terminated sessions using SeleniumGrid in Dockerorg.openqa.selenium.WebDriverException:会话 [null] 不可用,并且不在 Docker 中使用 SeleniumGrid 的最后 1000 个终止会话中
【发布时间】:2020-01-31 05:17:23
【问题描述】:

我正在运行 selenium 网格并有 2 个节点连接到它。但是当我尝试运行一个测试脚本(.java)时,它给出了错误:

Exception in thread "Thread-23" org.openqa.selenium.WebDriverException: Session [null] not available and is not among the last 1000 terminated sessions.
Active sessions are[ext. key 3e5f8fb2ae3b0c5cddc8817f80eb8fe1]
Command duration or timeout: 92 milliseconds
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'

在 VNC 客户端中,chrome 浏览器打开,但 url 未加载并引发错误。

注意:脚本是使用 maven 从另一个 docker 容器运行的。

当我将脚本作为 java 应用程序运行时,它工作正常,但在 docker 中,我收到了错误。**

【问题讨论】:

    标签: maven selenium docker selenium-webdriver selenium-grid


    【解决方案1】:

    此错误消息...

    Exception in thread "Thread-23" org.openqa.selenium.WebDriverException: Session [null] not available and is not among the last 1000 terminated sessions.
    Active sessions are[ext. key 3e5f8fb2ae3b0c5cddc8817f80eb8fe1]
    Command duration or timeout: 92 milliseconds
    Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
    

    ...暗示 Selenium Grid Node 无法与 Selenium Grid Hub 通信。


    深入研究

    这个错误在ActiveTestSessions.java中定义,定义为:

    public TestSession getExistingSession(ExternalSessionKey externalkey) {
        TestSession sessionByExternalKey = findSessionByExternalKey(externalkey);
        if (sessionByExternalKey == null) {
          SessionTerminationReason sessionTerminationReason = reasons.get(externalkey);
          String keyId = externalkey != null ? externalkey.getKey() : "(null externalkey)";
          if (sessionTerminationReason != null) {
              String msg = "Session [" + keyId + "] was terminated due to " + sessionTerminationReason;
              log.fine(msg);
              throw new GridException(msg);
          } else {
              String msg = "Session [" + keyId + "] not available and is not among the last 1000 terminated sessions.\n"
              + "Active sessions are" + this.unmodifiableSet();
              log.fine(msg);
              throw new GridException(msg);
          }
        }
        return sessionByExternalKey;
    }
    

    根据以下讨论:

    这个错误似乎源于以下情况:

    • Selenium Grid HubSelenium Grid Node客户端进程不同版本 启动/生成Selenium 客户端。

    解决方案

    确保Selenium Grid HubSelenium Grid Node客户端进程都使用相同版本的Selenium 客户端,即 Selenium v​​3.141.59


    更新 1

    在正常情况下,您应该观察到Selenium Webdriver + Java - Eclipse: java.lang.NoClassDefFoundError,以防存在同一个 jar 的多个版本。关于您的测试架构的更多细节将有助于我们以更好的方式调试问题。可能你需要清理如下:

    • mvn clean
    • mvn install
    • mvn clean install
    • mvn test

    更新 2

    作为最后的手段,您可以删除MAVEN_HOME~/.m2 并重新启动构建过程。

    【讨论】:

    • 但是当我将脚本作为独立的 Java 应用程序运行时,它是如何运行的。我不确定。我已经将 gird 和 node 版本都设置为 3.141.59-zinc。
    • @MidhunKG 查看更新的答案,如果有任何问题,请告诉我。
    • 我认为是版本问题并将我的 pom.xml selenium 依赖更新为 3.141.59 但仍然是同样的错误。我尝试使用 maven clean install 运行
    • @MidhunKG 查看更新的答案并让我知道状态。
    • 仍然无法正常工作。在我为 selenium 指定版本的 pom 文件中,显示警告“覆盖 selenium-java 的托管版本 2.53.1”。这与它不起作用有什么关系吗?
    猜你喜欢
    • 1970-01-01
    • 2021-01-11
    • 1970-01-01
    • 1970-01-01
    • 2023-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-12
    相关资源
    最近更新 更多