有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

Java/Selenium RemoteWebDriver/Maven/JUnit在尝试调用浏览器时获取空会话id

背景/设置:
我在JUnit中有很多测试类。所有这些都是通过Maven和Eclipse配置的。每个测试类实例化一个RemoteWebDriver实例,并在测试类完成执行后在tearDown方法中退出它

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

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将所有测试一起运行时,这种情况会一直发生。请帮忙


共 (3) 个答案

  1. # 1 楼答案

    在我的代码里也有同样的问题

            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调用之前,正在o flow中调用quit()。这是b

  2. # 2 楼答案

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

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

    2)拆卸问题。是否在拆卸过程中出现了一些问题,导致浏览器处于不良状态,导致新浏览器无法正常启动

    抱歉,我帮不上什么忙,我没有使用Maven和Eclipse来驱动我的Selenium测试

  3. # 3 楼答案

    我不知道这是否会有帮助,但我无法通过maven让selenium在firefox 3之外的任何版本上运行。x(根据我使用的内存3.18)。我在使用更高版本时发现了你的症状

    我尝试了一切,但承认失败,只是安装了旧版本并与之共存

    至少我们的硒测试成功了,我们开始做真正的工作