Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Custom Front-End Behat Steps
/**
* @When /^I am browsing using a "([^"]*)"$/
*/
public function iAmBrowsingUsingA($device) {
switch ($device) {
case "phone":
$this->getSession()
->resizeWindow((int) $this->customParameters['phone_width'], (int) $this->customParameters['phone_height'], 'current');
break;
case "tablet":
$this->getSession()
->resizeWindow((int) $this->customParameters['tablet_width'], (int) $this->customParameters['tablet_height'], 'current');
break;
case "small desktop":
$this->getSession()
->resizeWindow((int) $this->customParameters['desktop_sm_width'], (int) $this->customParameters['desktop_sm_height'], 'current');
break;
default:
$this->getSession()
->resizeWindow((int) $this->customParameters['desktop_width'], (int) $this->customParameters['desktop_height'], 'current');
}
}
/**
* @Given /^"([^"]*)" should have a "([^"]*)" css value of "([^"]*)"$/
* @param $selector , $rule, $value
* @throws Exception
*/
public function shouldHaveACssValueOf($selector, $rule, $value) {
$computed = $this->getSession()->evaluateScript("
return jQuery( '" . $selector . "' ).css('" . $rule . "');
");
// Adjust background image results to use relative paths
if ($rule == 'background-image' && !empty($computed)) {
// Split out the URL components
$relative = explode('/', $computed);
$relative = array_slice($relative, 3);
$computed = "url('" . implode('/', $relative);
}
// Convert double quotes to single quotes for matching purposes.
$computed = str_replace('"', "'", $computed);
if ($value != $computed) {
throw new Exception("Element ({$selector}) does not have a ({$rule}) value of ({$value}). The actual value is ({$computed})");
}
}
# Include in behat.yml to support 'I am browsing using a 'device' steps
context:
class: FeatureContext
parameters:
phone_width: '375'
phone_height: '667'
tablet_width: '768'
tablet_height: '1024'
desktop_width: '1280'
desktop_height: '800'
desktop_sm_width: '1100'
desktop_sm_height: '800'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.