Selenium and chrome in php

Below example illustrates how to launch the chrome browser using Selenium in PHP. You may get error saying “WebDriverCurlException – Curl error thrown for http POST to /session with params”. To avoid this error, make sure that you have installed latest driver exe files.
 

<?php
class LaunchChrome extends PHPUnit_Framework_TestCase {

protected $driver;

public function setUp()
{
$capabilities = array(WebDriverCapabilityType::BROWSER_NAME => ‘chrome’);
$this->driver = RemoteWebDriver::create(‘https://localhost:4444/wd/hub’, $capabilities);
}

public function testLaunchChrome()
{
$this->driver->get(“https://www.softpost.org”);
// checking that page title contains word ‘Tutorial’
$this->assertContains(‘Tutorial’, $this->driver->getTitle());
}

public function tearDown()
{
//Quit the driver
$this->driver->quit();
}
}

//To execute this test, you need to use below command.
//vendor/bin/phpunit LaunchChrome.php
?>                    

Complex problems, Simple Solutions