I use mink to test a website and I want to write a test scenario to check for error scenarios. So I want to see If I insert invalid data a page should return error and I should be in the same page as before. I mean I don't want to go to another page. for that I wrote a test scenario like below:
some steps ....
And Save current page
some other steps....
Then I should stay in the same page
for the two steps I wrote to method like beloww:
/**
* @Given /^Save current page$/
*/
public function SaveCurrentPage() {
$this->_last_page = $this->getSession ()->getCurrentUrl ();
}
and
/**
* @Given /^I should stay in the same page$/
*/
public function StayInSamePage() {
if ($this->_last_page === null) {
throw new FailureException ( "current page is not defined" );
// throw new Exception ( "current page is not defined" );
}
if ($this->_last_page !== $this->getSession ()->getCurrentUrl ()) {
throw new FailureException ( "you should be in " . $this->_last_page . " but you are in " . $this->getSession ()->getCurrentUrl () );
// throw new Exception ( "you should be in " . $this->_last_page . " but you are in " . $this->getSession ()->getCurrentUrl () );
} else {
return;
}
}
But I really don't like my solution. Since the line Save current page does'nt relate to the behavior of the application and is only used for mink and I think is not what behat/mink's goal is.
Is there any better solution?
Thank you in advance