Screenshots in Selenium in php

Below example shows how to taking a screenshot using selenium in PHP.
class MyTest 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 testScreenshot()

//Set the path of screenshot file. Here we have used mt_rand() function to generate random file name

$screenshotFilePath = mt_rand() . “abc.png”;


public function tearDown()
//Quit the driver

Complex problems, Simple Solutions