【发布时间】:2019-07-12 03:40:00
【问题描述】:
我正在使用 PHPUnit 运行所有测试。创建了一个启动 Apache 实例的包装器,然后启动 Selenium 独立服务器,然后在 http://localhost:4444/wd/hub 创建 Chrome 远程 Webdriver 实例。这个过程 100% 的时间在我们的开发机器上运行,90% 的时间在测试服务器上运行,但有时,测试会失败:
[exec] 1) Intranet\Pages\FinancialReportsSeleniumTest::test_changeMonthYear
[exec] Facebook\WebDriver\Exception\WebDriverCurlException: Curl error thrown for http POST to /session with params: {"desiredCapabilities":{"browserName":"chrome","platform":"ANY","chromeOptions":{"binary":"","args":["--window-size=1400,900","--no-sandbox","--headless"]},"goog:chromeOptions":{"args":["--window-size=1400,900","--no-sandbox","--headless"]}}}
[exec]
[exec] Failed to connect to localhost port 4444: Connection refused
[exec]
[exec] C:\Jenkins\jobs\Intranet-Master\workspace\vendor\facebook\webdriver\lib\Remote\HttpCommandExecutor.php:292
[exec] C:\Jenkins\jobs\Intranet-Master\workspace\vendor\facebook\webdriver\lib\Remote\RemoteWebDriver.php:126
[exec] C:\Jenkins\jobs\Intranet-Master\workspace\phpunit\library\Intranet\Selenium.php:364
[exec] C:\Jenkins\jobs\Intranet-Master\workspace\phpunit\library\Intranet\Selenium.php:51
[exec] C:\Jenkins\jobs\Intranet-Master\workspace\phpunit\library\Intranet\SeleniumTestCase.php:9
如果我们重新运行测试,下次可以正常工作。
开发机器:
- Windows 10 专业版 (1809)(64 位)
- Apache 2.4.38(32 位)
- PHP 7.2.15(32 位)
- Java 1.8.0_192(64 位)
- 硒 3.141.59
- Selenium Chrome 驱动程序 73.0.3683.20
测试机
- Windows Server 2008 R2 x64(64 位)
- Apache 2.4.38(32 位)
- PHP 7.2.15(32 位)
- 詹金斯 2.1.64
- Java 1.8.0_192(64 位)
- 硒 3.141.59
- Selenium Chrome 驱动程序 73.0.3683.20
日志文件显示服务器已启动:
10:41:27.392 INFO [GridLauncherV3.launch] - Selenium build info: version: '3.14.0', revision: 'aacccce0'
10:41:27.392 INFO [GridLauncherV3$1.launch] - Launching a standalone Selenium Server on port 4444
10:41:28.562 INFO [SeleniumServer.boot] - Selenium Server is up and running on port 4444
更新 #1:我们现在将 Selenium 独立服务器作为服务启动,但仍然以相同的频率失败(每 5-10 次测试运行一次)。
更新 #2:在运行任何测试之前,我们现在将 Apache 实例和远程 Web 驱动程序作为 PHPUnit 引导文件的一部分启动。我们现在还使用 fsockopen() 测试 Web 驱动程序是否正在运行(首先,在尝试启动它之前)。故障率已降至 5% 以下,但仍时有发生。奇怪的是,实际上似乎是在我们添加 fsockopen() 调用之后出现了改进 - 也许存在某种时间问题?
【问题讨论】:
-
你能在页面中查看下面的 url 是什么状态吗?
http://localhost:4444/grid/console -
您使用的是哪个版本的
selenium-server-standalone? -
selenium-server-standalone - 3.141.59
-
localhost:4444/grid/console:Whoops! URL 指定了到此帮助页面的路由。有关 Selenium Standalone 的更多信息,请参阅文档和/或访问 wiki。或者您正在寻找 Selenium Standalone 控制台。祝测试愉快!
-
要访问控制台,我必须去这里:localhost:4444/wd/hub/static/resource/hub.html,它显示当前会话,如果服务器正在运行,但我们在测试期间启动和停止 Selenium 服务器,如果此失败发生,则服务器已经退出。
标签: windows selenium google-chrome phpunit selenium-chromedriver