Skip to content

Instantly share code, notes, and snippets.

@alnutile
Created January 11, 2014 01:27
Show Gist options
  • Save alnutile/8365794 to your computer and use it in GitHub Desktop.
Save alnutile/8365794 to your computer and use it in GitHub Desktop.
Test Height
/**
* 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)
{
//@todo
$javascript_check = <<<HEREDOC
if(!jQuery('$arg1').length) { return "FAILED"; }
HEREDOC;
if($javascript_check != "FAILED") {
$javascipt = <<<HEREDOC
var target = jQuery('$arg1').height();
var window_height = jQuery(window).height();
var totalOf = target / window_height * 100;
if( totalOf >= $arg2 ) { return totalOf; } else { return "FAILED"; }
HEREDOC;
$results = $this->getMainContext()->getSession()->evaluateScript($javascipt);
if($results == "FAILED") {
throw new Exception('Element not the right size');
}
} 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