我想实现一个类来执行一些常见的out驱动程序功能,但我总是得到:驱动程序服务器已死。
如下所示:
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
}
然后,链接这些方法,例如:
$drive = new mywebdriver();
try {
$drive->login()
->search( "toyota" )
->search( "ford" )
->logout();
} catch (Exception $e) {
echo "Caught Exception". $e->getMessage();
}
这是典型的,也是可能的吗?我尝试了一些方法,但是驱动服务器一直给我一个“已死”的异常。
发布于 2019-03-15 07:01:53
要实现方法链模式,只需像这样返回实例:
public function search( $value ) : mywebdriver
{
//enter a value in the search field and print results
return $this;
}
https://stackoverflow.com/questions/55173176
复制相似问题