Behat - How to implement a step definition that targets all pages?

163 views Asked by At

I am trying to test a feature and ensure it shows itself on any page. How can I implement a custom step in my context class for something like

Scenario: ...
  Given I am on any page
  Then I should see "..."
  Then ...

without using 100 separate lined calls to MinkContext::visit for the 100 different parts of the site (example.com/a/, example.com/b/, example.com/a/a/ ...)?

1

There are 1 answers

0
lauda On

You can define a custom step like:

/**
 * @Given /^I am on (.*) page$/
 */
public function iAmOnPage($page)
{
    // call method to navigate to page identified by key
}

the $page param could be a key that identifies the page or a relative path to the base_url, depends on you on how you organize the code.