jeudi 2 juin 2016

Behat - Check list element contains content

I have a drop menu containing list elements that are some static and some changing my main goal is to check that the menu contains any 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)
{
   $element=$this->assertSession()->elementExists('css', $locator); //check element exists on page

    //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)

Aucun commentaire:

Enregistrer un commentaire