/ */ namespace BehatTests; use Behat\Behat\Context\Step; class BrowserSessionContext extends AbstractContext { /** * Validate that Swarm's urls are correctly hit. * * @param string $page Swarm Page name * * @Given /^(?: |I) (?:hit the|am on|visit the|go to) swarm "(?P[^"]*)" (?: |page|link|url)$/ */ public function iGoToSwarmPage($page = 'activity') { $url = $page; $translation = array( 'activity' => '', 'home' => '', 'history' => 'changes', 'help' => 'docs' ); // relative URLs get converted to absolute ones if (preg_match('/https?:\/\//', $page) == false) { $page = isset($translation[$page]) ? $translation[$page] : $page; $url = $this->configParams['base_url'] . '/' . $page; } $context = $this->getMinkContext(); $context->getSession()->visit($url); $context->waitUntilPageUrlLoads($url); } /** * @Then /^I should see a HTTP response code of (\d+)$/ */ public function iShouldSeeAHttpStatusCode($statusCode) { assertEquals( $statusCode, $this->getMinkContext()->getHttpStatusCode(), "HTTP response code for url \"{$this->getSession()->getCurrentUrl()}\" does not match expected" ); } }