I am doing running all tests using PHPUnit. Created a wrapper that launches an instance of Apache, then starts the Selenium standalone server, then creates the Chrome Remote Webdriver instance at http://localhost:4444/wd/hub. This process works 100% of the time on our dev machines, and 90% of the time on the test server, but from time to time, the tests fail as such:
[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
If we re-run the tests, works fine the next time.
Dev Machines:
- Windows 10 Pro (1809) (64 bit)
- Apache 2.4.38 (32 bit)
- PHP 7.2.15 (32 bit)
- Java 1.8.0_192 (64 bit)
- Selenium 3.141.59
- Selenium Chrome Driver 73.0.3683.20
Test Machine
- Windows Server 2008 R2 x64 (64 bit)
- Apache 2.4.38 (32 bit)
- PHP 7.2.15 (32 bit)
- Jenkins 2.1.64
- Java 1.8.0_192 (64 bit)
- Selenium 3.141.59
- Selenium Chrome Driver 73.0.3683.20
Log file shows that the server is up:
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
UPDATE #1: We now start the Selenium standalone server as a Service, still fails about the same frequency (once every 5-10 test runs).
UPDATE #2: We now start the Apache instance and the remote web driver at as part of our PHPUnit bootstrap file, before any tests are run. We also now test that the web driver is running (first, before attempting to start it), using fsockopen(). The failure rate has dropped to less than 5%, but it still happens from time to time. Strange thing is, the improvement actually seemed to occur after we add the fsockopen() call - maybe there is timing issue of some kind?