Question

I'm using Behat with Mink.

I would like one of my step definitions to act differently depending on which driver is running.

Ideally, my code would look something like this

public function stepDefinition(){
    if($this->getSession()->getDriver()->name == 'goutte'){
        //code to run if using goutte
    }else{
        //code to run if selenium is running
    }
}
Was it helpful?

Solution

So, though a little bit of delving into the code meant that I've found a solution to this. And seen as google was no help, hopefully this will be of help to someone else.

My code now looks like this

    if( $this->getSession()->getDriver() instanceof Behat\Mink\Driver\Selenium2Driver){
       // Selenium Code
    }else{
        //Goutte Code
    }

I've just grabbed the driver object and have checked which driver class it's an extension of, simple.

Now I can run the same step definition if the @javascript tag is or isn't before my scenario.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top