Keith Davis
Keith Davis

Reputation: 351

Curl error thrown for http POST to /session with params: {"desiredCapabilities":{"browserName":"chrome","platform":"ANY" with Selenium and PHPUnit

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:

Test Machine

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?

Upvotes: 5

Views: 5510

Answers (1)

undetected Selenium
undetected Selenium

Reputation: 193138

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.

Upvotes: 4

Related Questions