Skip to content

Instantly share code, notes, and snippets.

@moloneymb
Forked from alnutile/custom_step.php
Created January 6, 2014 20:11
Show Gist options
  • Save moloneymb/8289065 to your computer and use it in GitHub Desktop.
Save moloneymb/8289065 to your computer and use it in GitHub Desktop.
/**
* See if the element (name|label|id) is greater than the % of the window
*
* @Then /^the element "([^"]*)" should be "([^"]*)" percent or greater than the window$/
*/
public function theElementShouldBePercentOrGreaterThanTheWindow($arg1, $arg2)
{
//1. make sure the target exists
//2. get the height of the target
//3. compare it to the window height
//4. fail if < percent given
$element = $this->getMainContext()->getSession()->getPage()->find('css', $arg1);
if($element) {
$javascipt = <<<HEREDOC
var target = jQuery('$arg1').height();
var window_height = jQuery(window).height();
var totalOf = target / window_height * 100;
if( totalOf >= $arg2 ) { return "PASSES"; } else { return "FAILED"; }
HEREDOC;
$results = $this->getMainContext()->getSession()->evaluateScript($javascipt);
if($results == "FAILED") {
throw new Exception('Element not found');
}
} else {
throw new Exception('Element not found');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment