Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix behat bug introduced in INT-14068 #138

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions tests/behat/behat_theme_snap.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,64 @@
*/
class behat_theme_snap extends behat_base {

/**
* Ensures that the provided node is visible and we can interact with it.
*
* @throws ExpectationException
* @param NodeElement $node
* @return void Throws an exception if it times out without the element being visible
*/
protected function ensure_node_not_visible($node) {

if (!$this->running_javascript()) {
return;
}

// Exception if it timesout and the element is still there.
$msg = 'The "' . $node->getXPath() . '" xpath node is visible and it should be hidden';
$exception = new ExpectationException($msg, $this->getSession());

// It will stop spinning once the isVisible() method returns false.
$this->spin(
function($context, $args) {
if (!$args->isVisible()) {
return true;
}
return false;
},
$node,
self::EXTENDED_TIMEOUT,
$exception,
true
);
}

/**
* Ensures that the provided element is not visible or does not exist.
*
* @throws ExpectationException
* @param string $element
* @param string $selectortype
* @return void
*/
protected function ensure_element_not_visible($element, $selectortype) {

if (!$this->running_javascript()) {
return;
}

try {
$node = $this->get_selected_node($selectortype, $element);
} catch (ElementNotFoundException $e) {
// Element is not found - that's good enough!
return;
}

$this->ensure_node_not_visible($node);

return $node;
}

/**
* Checks if running in a Blackboard Open LMS system, skips the test if not.
*
Expand Down