5

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?

Keith Davis
  • 351
  • 5
  • 14
  • 1
    Can you check following url in page what status is giving.```http://localhost:4444/grid/console``` – KunduK Feb 18 '19 at 17:47
  • Which versions of `selenium-server-standalone` are you using? – KunduK Feb 18 '19 at 17:52
  • selenium-server-standalone - 3.141.59 – Keith Davis Feb 20 '19 at 19:37
  • http://localhost:4444/grid/console:Whoops! The URL specified routes to this help page. For more information about Selenium Standalone please see the docs and/or visit the wiki. Or perhaps you are looking for the Selenium Standalone console. Happy Testing! – Keith Davis Feb 20 '19 at 19:39
  • To access the console, I have to go here: http://localhost:4444/wd/hub/static/resource/hub.html, That shows the current sessions, if the server is running, but we are starting and stopping the Selenium server during testing and if this failure occurs, then the server has already exited. – Keith Davis Feb 20 '19 at 19:42

1 Answers1

3

This error message...

 [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"]}}}

...implies that Curl error was thrown while initializing the Chrome Browser session.

Your main issue seems to be with the desiredCapability platform being set as ANY.


As per the platformName section of Processing capabilities - WebDriver W3C Living Document, the following platform names are in common usage with well-understood semantics and, when matching capabilities, greatest interoperability can be achieved by honoring them as valid synonyms for well-known Operating Systems:

Key         System
---         ------
"linux"     Any server or desktop system based upon the Linux kernel.
"mac"       Any version of Apple’s macOS.
"windows"   Any version of Microsoft Windows, including desktop and mobile versions.

Note:This list is not exhaustive.

When returning capabilities from New Session, it is valid to return a more specific platformName, allowing users to correctly identify the Operating System the WebDriver implementation is running on.

So instead of passing "platform":"ANY" within the desiredCapabilities object, a more specific "platform":"windows" will be more desirable approach.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Ok, I made that change. May take a few days to know if this has an effect. – Keith Davis Feb 20 '19 at 20:14
  • 1
    Did not fix the issue. I also made a change to our configuration - before we were starting the Selenium standalone server as part of the testing, but now we are running it as a service. Still fails periodically (about once every 5-10 times tests are run) with the same error (except "platform":"windows"). – Keith Davis Feb 25 '19 at 16:53