Sta*_*bie 14 php selenium web-testing headless-browser
我想使用Selenium自动执行一些Web任务(不用于测试).我认为我安装了Selenium RC Server,但由于我在PHP中找不到客户端驱动程序,因此无法编写"测试脚本"(参见:http://seleniumhq.org/download/).
有没有办法让我使用Selenium和PHP?这似乎表明我需要PHPUnit http://www.phpunit.de/manual/current/en/selenium.html.我只想自动执行一些任务,而不是参与全套测试.
Ani*_*nil 17
facebook/php-webdriver是selenium和php的一个很棒的客户端.
您可以使用它来自动执行Web任务(如OP所需),或者您可以简单地将php-webdriver集成到您的测试框架中.有一些项目已经提供了这个:
下载并安装facebook/php-webdriver.composer require facebook/webdriver
下载Selenium并启动它.java -jar selenium-server-standalone-#.jar
下载Quick Java并将其放入项目目录中.
在这个例子中,我们使用扩展quickjava来禁用除javascript和之外的所有内容cookies.
在此处查看更多偏好设置:https:
//github.com/ThatOneGuyDotNet/QuickJava/blob/master/defaults/preferences/defaults.js
在此处查看更多示例命令:https:
//github.com/facebook/php-webdriver/wiki/Example-command-reference
use Facebook\WebDriver\Firefox\FirefoxProfile;
use Facebook\WebDriver\Firefox\FirefoxDriver;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
// 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
Run Code Online (Sandbox Code Playgroud)
lAH*_*2iV 15
尝试下面的事情
为了参考如何写这些文件点击这里,并尝试使用git hub
| 归档时间: |
|
| 查看次数: |
47922 次 |
| 最近记录: |