Selenium Grid PHP Webdriver Example

PHP Webdriver is supported by Gridlastic, run your tests in the cloud with real browsers.

// Install with composer,

namespace Facebook\WebDriver;

  use Facebook\WebDriver\Remote\DesiredCapabilities;
  use Facebook\WebDriver\Remote\RemoteWebDriver;

  $host = '';
  // If the requested test environment is not registered with the hub
  // or busy, allow enough time (600000, 600 sec, see below) for the Gridlastic auto scaling
  // functionality to launch grid nodes with the requested environment.
  // Note: starting from selenium version 3.9.1 you must also include "platformName": "windows" in the request when testing with firefox and IE.
  $driver = RemoteWebDriver::create(
    array("platform"=>"WIN10", "platformName"=>"windows", "browserName"=>"chrome", "version"=>"latest", "video"=>"True"),
  $driver->manage()->window()->maximize(); // If Linux set window size, max 1920x1080
  $element = $driver->findElement(WebDriverBy::name("q"));
  if($element) {
      $element->sendKeys("php webdriver");
  print "Video: " . VIDEO_URL . $driver->getSessionId();

The Gridlastic hub endpoint and the VIDEO_URL parameter used in this code example is displayed after launching your Gridlastic selenium grid. See documention Selenium Grid Configuration Parameters where to find these credentials and replace with your own.

Get a free account and launch your Gridlastic selenium grid, then run this code locally.

NOTE: Gridlastic auto scaling requires all 3 test environment parameters platform, browser and browser version to be specified in each request in order to launch test nodes to fulfill test demand. Video recording is optional. See test environments for capabilities options.
It is important to ensure that "driver.quit()" is always called for proper test execution and creation of video recordings of failed tests.