Created
May 17, 2011 21:19
-
-
Save rande/977427 to your computer and use it in GitHub Desktop.
Behat steps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$steps->And('/^I press item "([^"]*)"$/', function($world, $xpath) { | |
$button = $world->getSession()->getDriver()->find($xpath); | |
$button = count($button) > 0 ? current($button) : null; | |
if (null === $button) { | |
throw new ElementNotFoundException('button', $xpath); | |
} | |
$world->getSession()->getDriver()->click($button->getXpath()); | |
}); | |
$steps->When('/^I fill item "([^"]*)" with "([^"]*)"$/', function($world, $xpath, $value) { | |
$world->getSession()->getDriver()->setValue($xpath, $value); | |
}); | |
$steps->When('/^I post to (?P<page>.+) with (?P<encoded_data>.+)$/', function($world, $page, $encoded_data) { | |
$data = json_decode($encoded_data, true); | |
$world->getSession()->getDriver()->getClient()->request('post', $page, $data); | |
}); | |
$steps->Then('/^debug (?P<type>.+)$/', function(MinkEnvironment $world, $type) { | |
if ($type == 'cookies') { | |
$cookies = $world->getSession()->getDriver()->getClient()->getCookieJar(); | |
$world->printDebug("Cookies"); | |
foreach ($cookies->all() as $name => $value) { | |
$world->printDebug(sprintf(" => %s => %s", $name, $value)); | |
} | |
return; | |
} | |
if ($type == 'response') { | |
$world->printDebug('content: '.$world->getSession()->getPage()->getContent()); | |
$world->printDebug('current url: '.$world->getSession()->getCurrentUrl()); | |
return; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment