Screenshots in Selenium in php

Below example shows how to taking a screenshot using selenium in PHP.
 
<?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);
$this->driver->manage()->window()->maximize();
}

public function testScreenshot()
{
$this->driver->get(“https://www.softpost.org/selenium-test-page”);

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

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

$this->driver->takeScreenshot($screenshotFilePath);
}

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

Complex problems, Simple Solutions