I have a drop down menu containing list elements that are sometimes static and sometimes changed. My main goal is to check that the menu contains some content [followed by outputting that content and exporting it in a report].
The function I created in my FeatureContext.php looks like this:
/**
* @Then /^I check content exists for element "([^"]*)"$/
*/
public function iCheckElementContent($locator)
{
//check element exists on page
$element=$this->assertSession()->elementExists('css', $locator);
//check element content is not empty (returns exception if true)
if ( empty($this->getPage()->find('css', $locator)->getText()) ) {
throw new Exception;
}
}
As you can notice, it is based on the reply to the other question regarding this feature. My problem however is that it doesn't seem to like the getPage()
parameter. The error I get is:
PHP Fatal error: Uncaught Error: Call to undefined method FeatureContext::getPage()
I also tried changing it to getValue(), without any success. Any ideas? (bonus awesome points for also helping me with the second step of my requirements)
I think I found a solution, but I'm not sure if it passes because it works or because it's searching for nothing and finding it.
$session = $this->getSession();
$element = $session->getPage()->find('css', $locator);
//check element content is not empty (returns exception if true)
if (empty ($element->getText()) ) {
throw new Exception;
}
Can someone please code-review this?