Using BrowserStack to automate collection of ScreenShots of my pages across multiple devices.

Install PHP WebDriver

git clone https://github.com/facebook/php-webdriver.git
#!/usr/bin/php
<?php
/**
    Attempts to Visit a Web-Page and Get a Screenshot?
*/

require(__DIR__ . '/php-webdriver/lib/__init__.php');

$auth = 'http://user:auth@hub.browserstack.com/wd/hub';
$page = 'http://www.discuss.io/';

$chrome_opts = array('args' => array(
    '--disable-popup-blocking'
));

$caps_list = array(
    // Windows XP
    // array("os" => "Windows", "os_version" => "XP", "browser" => "Chrome", "browser_version" => "31.0"),
    // array("os" => "Windows", "os_version" => "XP", "browser" => "Firefox", "browser_version" => "25.0"),
    // array("os" => "Windows", "os_version" => "XP", "browser" => "Opera", "browser_version" => "12.16"),
    // array("os" => "Windows", "os_version" => "XP", "browser" => "IE", "browser_version" => "7.0"),

    // Windows 7
    // array("os" => "Windows", "os_version" => "7", "browser" => "IE", "browser_version" => "11.0"),
    // array("os" => "Windows", "os_version" => "7", "browser" => "Chrome", "browser_version" => "31.0"),
    // array("os" => "Windows", "os_version" => "7", "browser" => "Firefox", "browser_version" => "25.0"),
    // array("os" => "Windows", "os_version" => "7", "browser" => "Opera", "browser_version" => "12.16"),

    // Windows 8.1
    array("os" => "Windows", "os_version" => "8.1", "browser" => "IE", "browser_version" => "11.0"),
    array("os" => "Windows", "os_version" => "8.1", "browser" => "Chrome", "browser_version" => "31.0"),
    array("os" => "Windows", "os_version" => "8.1", "browser" => "Firefox", "browser_version" => "25.0"),
    array("os" => "Windows", "os_version" => "8.1", "browser" => "Opera", "browser_version" => "12.16"),

    // OS X Maverics
    array("os" => "OS X", "os_version" => "Mavericks", "browser" => "Safari", "browser_version" => "7.0", ),
    array("os" => "OS X", "os_version" => "Mavericks", "browser" => "Chrome", "browser_version" => "31.0", ),
    array("os" => "OS X", "os_version" => "Mavericks", "browser" => "Firefox", "browser_version" => "25.0", ),
    array("os" => "OS X", "os_version" => "Mavericks", "browser" => "Opera", "browser_version" => "12.15", ),

    // iOS 7
    array("platform" => "MAC", "device" => "iPhone 5S", "browserName" => "iPhone"),
    array("platform" => "MAC", "device" => "iPad 3rd (7.0)", "browserName" => "iPad"),

    // Android 4.2
    array("platform" => "ANDROID", "device" => "LG Nexus 4", "browserName" => "android"),
    array("platform" => "ANDROID", "device" => "Google Nexus 7", "browserName" => "android"),

);

$html = '<h1>ScreenShots</h1>';

foreach ($caps_list as $caps) {

    $caps = array_merge($caps, array('browserstack.debug' => true));

    $web_driver = RemoteWebDriver::create($auth, $caps);
    $web_driver->get($page);
    // $element = $web_driver->findElement(WebDriverBy::name("q"));
    // if($element) {
    //   $element->sendKeys("Browserstack");
    //   $element->submit();
    // }

    // $web_driver->executeScript("return alert('SEO Sorcerer Rocks')", array());
    $ret = $web_driver->executeScript("return window.width;", array());
    print_r($ret);
    $ret = $web_driver->executeScript("return window.height;", array());
    print_r($ret);

    // print $web_driver->getTitle();
    $file = sprintf('%08x', crc32(serialize($caps)));
    file_put_contents("/opt/dio/AT_Source/$file.png", $web_driver->takeScreenshot());
    $html.= "<h2>{$caps['os']} / {$caps['os_version']} / {$caps['browser']} / {$caps['browser_version']}</h2>";

    // @todo when OS is maverics, find full height, scroll step-by-step, capture and stitch together

    $web_driver->quit();

}

file_put_contents($html);

See Also