Skip to content

Instantly share code, notes, and snippets.

@backlineint
Last active March 16, 2016 03:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save backlineint/8fedeb670e2c96a44c15 to your computer and use it in GitHub Desktop.
Save backlineint/8fedeb670e2c96a44c15 to your computer and use it in GitHub Desktop.
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