php - Chaining webdriver methods
Get the solution ↓↓↓I'd like to implement a class to carry out some common webdriver functions, but I keep getting: the driver server has died.
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.
Answer
Solution:
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;
}
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: an exception occurred in the driver: could not find driver
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.