Skip to content

Instantly share code, notes, and snippets.

@mrofi
Forked from michaellouieloria/gist:f2ee272d1709a0e80f71
Last active September 21, 2017 03:37
Show Gist options
  • Save mrofi/6a93be2e55402fd870860c54dc420bd0 to your computer and use it in GitHub Desktop.
Save mrofi/6a93be2e55402fd870860c54dc420bd0 to your computer and use it in GitHub Desktop.
Phantomjs in Facebook PHP webdriver
require_once __DIR__ . "/vendor/autoload.php";
use \Facebook\WebDriver\Remote\WebDriverCapabilityType;
use \Facebook\WebDriver\Remote\RemoteWebDriver;
use \Facebook\WebDriver\WebDriverDimension;
$host = '127.0.0.1:8910';
$capabilities = array(
WebDriverCapabilityType::BROWSER_NAME => 'phantomjs',
'phantomjs.page.settings.userAgent' => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:25.0) Gecko/20100101 Firefox/25.0',
);
$driver = RemoteWebDriver::create($host, $capabilities, 5000);
$window = new WebDriverDimension(1024, 768);
$driver->manage()->window()->setSize($window);
$driver->get('https://www.google.ru/');
$driver->takeScreenshot('/tmp/screen.png');
$driver->quit();
Use phantomjs. Start it:
$ phantomjs --webdriver=127.0.0.1:8910
Use:
require_once('lib/__init__.php');
$host = '127.0.0.1:8910';
$capabilities = array(
WebDriverCapabilityType::BROWSER_NAME => 'phantomjs',
'phantomjs.page.settings.userAgent' => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:25.0) Gecko/20100101 Firefox/25.0',
);
$driver = RemoteWebDriver::create($host, $capabilities, 5000);
$window = new WebDriverDimension(1024, 768);
$driver->manage()->window()->setSize($window);
$driver->get('https://www.google.ru/');
$driver->takeScreenshot('/tmp/screen.png');
$driver->quit();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment