[英]Chaining webdriver methods
I'd like to implement a class to carry out some common webdriver functions, but I keep getting: the driver server has died. 我想实现一个类来执行一些常见的webdriver函数,但我不断得到: 驱动程序服务器已经死了。
Something like this: 像这样的东西:
class mywebdriver {
function __construct( $args ){
//options
$options = new ChromeOptions();
$options->addArguments($args);
//capabilities
$caps = DesiredCapabilities::chrome();
$caps->setCapability(ChromeOptions::CAPABILITY, $options);
$driver = ChromeDriver::start($caps);
$driver->manage()->timeouts()->implicitlyWait = 20;
$this->driver = $driver;
}
function login(){
//all things related to logging into a site using $this->driver
$this->driver->get( "www.url.com" );
}
function logout(){
//all things related to logging into a site using $this->driver
$this->driver->quit();
}
function search( $value ){
//enter a value in the search field and print results
}
... other methods
}
Then, chaining the methods, such as: 然后,链接方法,例如:
$drive = new mywebdriver();
try {
$drive->login()
->search( "toyota" )
->search( "ford" )
->logout();
} catch (Exception $e) {
echo "Caught Exception". $e->getMessage();
}
Is this typical, and possible? 这是典型的,也可能吗? I've tried a few things, but the driver server keeps giving me that "died" exception.
我已经尝试了一些东西,但驱动程序服务器一直给我“死”的例外。
To implement a method chain pattern, just return the instance like that: 要实现方法链模式,只需返回实例:
public function search( $value ) : mywebdriver
{
//enter a value in the search field and print results
return $this;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.