背景/设置:
我在 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 一起运行所有这些测试时,这种情况始终如一。请帮忙?