Last active
March 16, 2016 03:35
-
-
Save backlineint/8fedeb670e2c96a44c15 to your computer and use it in GitHub Desktop.
Custom Front-End Behat Steps
This file contains 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
/** | |
* @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})"); | |
} | |
} |
This file contains 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
# 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