【问题标题】:Java/Selenium RemoteWebDriver/Maven/JUnit - Get null session id while trying to invoke browserJava/Selenium RemoteWebDriver/Maven/JUnit - 尝试调用浏览器时获取空会话 ID
【发布时间】:2012-04-07 00:49:16
【问题描述】:

背景/设置:
我在 JUnit 中有一堆测试类。全部通过 Maven 和 Eclipse 配置。每个测试类实例化一个 RemoteWebDriver 实例,并在测试类完成执行后在 tearDown 方法中退出它。

当我尝试通过执行“mvn clean install”来运行所有测试时,一些测试执行得很好,但其余测试由于以下异常(堆栈跟踪)而失败:

Tests in error: 
  com.tagged.qa.selenium.tests.gifts.GiftsPageTest: Error communicating with the remote browser. It may have died.(..)
  com.tagged.qa.selenium.tests.tags.TagsPageTest: Error communicating with the remote browser. It may have died.(..)
  addFriendsTest(com.tagged.qa.selenium.tests.friends.FriendsTest): Error communicating with the remote browser. It may have died.(..)
  deleteFriendsTest(com.tagged.qa.selenium.tests.friends.FriendsTest): Error communicating with the remote browser. It may have died.(..)
  com.tagged.qa.selenium.tests.statusupdates.StatusUpdatesTest: Error communicating with the remote browser. It may have died.(..)
  com.tagged.qa.selenium.tests.comments.CommentsTest: Error communicating with the remote browser. It may have died.(..)
  com.tagged.qa.selenium.tests.search.SearchPageTest: Error communicating with the remote browser. It may have died.(..)
  com.tagged.qa.selenium.tests.homepage.HomePageTest: Error communicating with the remote browser. It may have died.(..)
  com.tagged.qa.selenium.tests.wink.WinkPageTest: Error communicating with the remote browser. It may have died.(..)
  com.tagged.qa.selenium.tests.profile.ProfilePageTest: Error communicating with the remote browser. It may have died.(..)
  com.tagged.qa.selenium.tests.footerpagestests.TermsOfServiceTest: Error communicating with the remote browser. It may have died.(..)

Tests run: 18, Failures: 0, Errors: 11, Skipped: 0

在 target/surefire-reports/ 中检查失败的单个测试的日志会导致我这样:

org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
Caused by: org.openqa.selenium.WebDriverException: Session ID may not be null.

在测试执行过程中,我注意到浏览器(在我的例子中是 firefox)试图打开但很快就退出了。 Selenium 服务器记录没有会话 ID。它尝试了几次并退出尝试。之后,管道中的所有其他测试由于相同的原因而失败。

令人困惑的是,当我尝试单独运行这些测试时,不会出现此问题,但是当我尝试使用 maven 将所有这些测试一起运行时,这种情况始终如一。请帮忙?

【问题讨论】:

    标签: java maven selenium junit webdriver


    【解决方案1】:

    我不知道这是否会有所帮助,但我无法通过 maven 使用 3.x 以外的任何版本的 Firefox(根据我使用 3.18 的内存)使用 selenium。我在使用更高版本时出现了您的症状。

    我尝试了一切,但承认失败并简单地安装并使用旧版本。

    至少我们的 selenium 测试成功了,我们继续做真正的工作。

    【讨论】:

    • 有趣。我可以让它在 Firefox 11 上运行没问题。虽然我只是认为测试在 Eclipse 中失败的方式与在 Maven 中失败的方式相同。所以并不像预期的那样与maven有关。
    • 我的错。我只是没有在我的代码中正确调用浏览器。刚刚学到了关于java中关键字“static”的巨大教训。我的代码现在适用于带有 selenium-server-2.20 和 maven 2.2.1 的 FF 11.0。不过感谢您的回复。让我知道您是否需要帮助让它发挥波西米亚风格。
    【解决方案2】:

    我不确定,但通常当我在运行一组测试时看到失败,而在运行单个测试时通过,罪魁祸首通常是:

    1) 线程问题。这些测试是多线程的吗?如果是这样,可能存在某种资源争用。

    2) 拆解问题。是否在 tearDown 中发生了什么导致浏览器处于不良状态以致新浏览器无法正常启动?

    抱歉,我无法提供更多帮助,我不使用 Maven 和 Eclipse 来驱动我的 Selenium 测试。

    【讨论】:

      【解决方案3】:

      在我的这段代码中遇到了同样的问题。

              WebDriver augmentedDriver;
              if(BrowserConfig.getHubURL().equalsIgnoreCase("none"))
                  augmentedDriver = getDriver();
              else augmentedDriver = new Augmenter().augment(getDriver());
      
              LOGGER.info("Just before capture: ");
              LOGGER.info(augmentedDriver.toString());
              byte[] screenshot = ((TakesScreenshot) augmentedDriver).getScreenshotAs(OutputType.BYTES);
      

      发现在 getscreenshot 调用之前,driver.quit() 在流程中被调用。这个b

      【讨论】:

        猜你喜欢
        • 2013-03-23
        • 1970-01-01
        • 2021-03-29
        • 2012-02-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-07-15
        • 2013-10-22
        相关资源
        最近更新 更多