MDL-42236 behat: New steps to look for elements visibility

This commit is contained in:
David Monllao 2013-10-30 14:20:46 +08:00 committed by Sam Hemelryk
parent 98719c48fa
commit 63950e4d0b
3 changed files with 102 additions and 4 deletions

View File

@ -20,6 +20,10 @@ Feature: Page contents assertions
And I wait "2" seconds
And I hover ".region-content .generaltable td span" "css_element"
Then I should see "I'm the description"
And "Grouping" "select" in the "region-main" "region" should be visible
And "Group" "select" should be visible
And "Messaging" "link" in the "Administration" "block" should not be visible
And "Change password" "link" should not be visible
And I should see "Filter groups by"
And I should not see "Filter groupssss by"
And I should see "Group members" in the ".region-content table th.c1" "css_element"

View File

@ -18,8 +18,8 @@ Feature: Course files
Then I should see "Legacy course files"
And I follow "Legacy course files"
And I press "Edit legacy course files"
And I should see "Add..."
And I should see "Create folder"
And "Add..." "link" should be visible
And "Create folder" "link" should be visible
@javascript
Scenario: Add legacy file disabled
@ -35,5 +35,5 @@ Feature: Course files
Then I should see "Legacy course files"
And I follow "Legacy course files"
And I press "Edit legacy course files"
And I should not see "Add..."
And I should not see "Create folder"
And "Add..." "link" should not be visible
And "Create folder" "link" should not be visible

View File

@ -275,6 +275,100 @@ class behat_general extends behat_base {
$this->getSession()->getDriver()->dragTo($sourcexpath, $destinationxpath);
}
/**
* Checks, that the specified element is visible. Only available in tests using Javascript.
*
* @Then /^"(?P<element_string>(?:[^"]|\\")*)" "(?P<selector_string>(?:[^"]|\\")*)" should be visible$/
* @throws ElementNotFoundException
* @throws ExpectationException
* @throws DriverException
* @param string $element
* @param string $selectortype
* @return void
*/
public function should_be_visible($element, $selectortype) {
if (!$this->running_javascript()) {
throw new DriverException('Visible checks are disabled in scenarios without Javascript support');
}
$node = $this->get_selected_node($selectortype, $element);
if (!$node->isVisible()) {
throw new ExpectationException('"' . $element . '" "' . $selectortype . '" is not visible', $this->getSession());
}
}
/**
* Checks, that the specified element is not visible. Only available in tests using Javascript.
*
* @Then /^"(?P<element_string>(?:[^"]|\\")*)" "(?P<selector_string>(?:[^"]|\\")*)" should not be visible$/
* @throws ElementNotFoundException
* @throws ExpectationException
* @param string $element
* @param string $selectortype
* @return void
*/
public function should_not_be_visible($element, $selectortype) {
try {
$this->should_be_visible($element, $selectortype);
throw new ExpectationException('"' . $element . '" "' . $selectortype . '" is visible', $this->getSession());
} catch (ExpectationException $e) {
// All as expected.
}
}
/**
* Checks, that the specified element is visible inside the specified container. Only available in tests using Javascript.
*
* @Then /^"(?P<element_string>(?:[^"]|\\")*)" "(?P<selector_string>[^"]*)" in the "(?P<element_container_string>(?:[^"]|\\")*)" "(?P<text_selector_string>[^"]*)" should be visible$/
* @throws ElementNotFoundException
* @throws DriverException
* @throws ExpectationException
* @param string $element Element we look for
* @param string $selectortype The type of what we look for
* @param string $nodeelement Element we look in
* @param string $nodeselectortype The type of selector where we look in
*/
public function in_the_should_be_visible($element, $selectortype, $nodeelement, $nodeselectortype) {
if (!$this->running_javascript()) {
throw new DriverException('Visible checks are disabled in scenarios without Javascript support');
}
$node = $this->get_node_in_container($selectortype, $element, $nodeselectortype, $nodeelement);
if (!$node->isVisible()) {
throw new ExpectationException(
'"' . $element . '" "' . $selectortype . '" in the "' . $nodeelement . '" "' . $nodeselectortype . '" is not visible',
$this->getSession()
);
}
}
/**
* Checks, that the specified element is not visible inside the specified container. Only available in tests using Javascript.
*
* @Then /^"(?P<element_string>(?:[^"]|\\")*)" "(?P<selector_string>[^"]*)" in the "(?P<element_container_string>(?:[^"]|\\")*)" "(?P<text_selector_string>[^"]*)" should not be visible$/
* @throws ElementNotFoundException
* @throws ExpectationException
* @param string $element Element we look for
* @param string $selectortype The type of what we look for
* @param string $nodeelement Element we look in
* @param string $nodeselectortype The type of selector where we look in
*/
public function in_the_should_not_be_visible($element, $selectortype, $nodeelement, $nodeselectortype) {
try {
$this->in_the_should_be_visible($element, $selectortype, $nodeelement, $nodeselectortype);
throw new ExpectationException(
'"' . $element . '" "' . $selectortype . '" in the "' . $nodeelement . '" "' . $nodeselectortype . '" is visible',
$this->getSession()
);
} catch (ExpectationException $e) {
// All as expected.
}
}
/**
* Checks, that page contains specified text. It also checks if the text is visible when running Javascript tests.
*