facebook/php-webdriver is an awesome client for selenium and php.
You can use it to automate web tasks (as the OP wanted), or you can simply integrate php-webdriver to your testing framework. There are some project already providing this:
Install Everything
Download and install facebook/php-webdriver. composer require facebook/webdriver
Download Selenium & Start it. java -jar selenium-server-standalone-#.jar
Download Quick Java and place it into your project directory.
Usage
In this example, we use the extension quickjava
to disable everything except javascript
and cookies
.
View more preference settings here:
https://github.com/ThatOneGuyDotNet/QuickJava/blob/master/defaults/preferences/defaults.js
View more example commands here:
https://github.com/facebook/php-webdriver/wiki/Example-command-reference
use FacebookWebDriverFirefoxFirefoxProfile;
use FacebookWebDriverFirefoxFirefoxDriver;
use FacebookWebDriverRemoteDesiredCapabilities;
use FacebookWebDriverRemoteRemoteWebDriver;
// Change this to the path of you xpi
$extensionPath = $this->container->getParameter('kernel.root_dir').'/../bin/selenium/quickjava-2.0.6-fx.xpi';
// Build our firefox profile
$profile = new FirefoxProfile();
$profile->addExtension($extensionPath);
$profile->setPreference('thatoneguydotnet.QuickJava.curVersion', '2.0.6.1');
$profile->setPreference('thatoneguydotnet.QuickJava.startupStatus.Images', 2);
$profile->setPreference('thatoneguydotnet.QuickJava.startupStatus.AnimatedImage', 2);
$profile->setPreference('thatoneguydotnet.QuickJava.startupStatus.CSS', 2);
//$profile->setPreference('thatoneguydotnet.QuickJava.startupStatus.Cookies', 2);
$profile->setPreference('thatoneguydotnet.QuickJava.startupStatus.Flash', 2);
$profile->setPreference('thatoneguydotnet.QuickJava.startupStatus.Java', 2);
//$profile->setPreference('thatoneguydotnet.QuickJava.startupStatus.JavaScript', 2);
$profile->setPreference("thatoneguydotnet.QuickJava.startupStatus.Silverlight", 2);
// Create DC + Driver
$dc = DesiredCapabilities::firefox();
$dc->setCapability(FirefoxDriver::PROFILE, $profile);
$driver = RemoteWebDriver::create($host, $dc);
$driver->get('http://stackoverflow.com');
// Do stuff - https://github.com/facebook/php-webdriver/wiki/Example-command-reference
//$driver->findElement(WebDriverBy::id("element-id"));
// The HTML Source code
$html = $driver->getPageSource();
// Firefox should be open and you can see no images or css was loaded
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…