diff --git a/behat.varbase.yml b/behat.varbase.yml index d19b6f7965ea3ba99fdd1769566f7890b7dcb889..f58a6ecf2f7762677aed2fa414e4b522e701e5fa 100644 --- a/behat.varbase.yml +++ b/behat.varbase.yml @@ -49,7 +49,7 @@ default: output_path: "%paths.base%/tests/reports/" extensions: Drupal\MinkExtension: - ajax_timeout: 20 + ajax_timeout: 60 files_path: "%paths.base%/tests/assets/" goutte: ~ selenium2: diff --git a/tests/features/bootstrap/VarbaseContext.php b/tests/features/bootstrap/VarbaseContext.php index 160a74f43c6fc7dc5a6ada9f507d52ab96391a69..73c6e7072bb4654b753f55b886db205639e87058 100644 --- a/tests/features/bootstrap/VarbaseContext.php +++ b/tests/features/bootstrap/VarbaseContext.php @@ -86,7 +86,7 @@ class VarbaseContext extends RawDrupalContext implements SnippetAcceptingContext $element = $this->getSession()->getPage(); $this->getSession()->visit($this->locatePath('/user')); - sleep(2); + sleep(2); $element->fillField('edit-name', $username); $element->fillField('edit-pass', $password); $submit = $element->findButton('op'); @@ -115,7 +115,7 @@ class VarbaseContext extends RawDrupalContext implements SnippetAcceptingContext // Login with the. $element = $this->getSession()->getPage(); $this->getSession()->visit($this->locatePath('/user')); - sleep(2); + sleep(2); $element->fillField('edit-name', $username); $element->fillField('edit-pass', $password); $submit = $element->findButton('op'); @@ -211,7 +211,7 @@ class VarbaseContext extends RawDrupalContext implements SnippetAcceptingContext * @Given /^(?:|I )wait max of (?P<time>\d+)s(?:| for the page to be ready and loaded)$/ * @Given /^(?:|I )wait(?:| for the page)$/ * - * @throws Exception + * @throws \WebDriver\Exception * If timeout is reached. */ public function iWaitMaxOfSecondsForThePageToBeReadyAndLoaded($time = 10000) { @@ -933,7 +933,7 @@ class VarbaseContext extends RawDrupalContext implements SnippetAcceptingContext if (preg_match($regex, $actual)) { $found = TRUE; - break; + break; } } if (!$found) { @@ -951,6 +951,49 @@ class VarbaseContext extends RawDrupalContext implements SnippetAcceptingContext } } + /** + * Check if we do not have the text in the selected element. + * + * Varbase Context #varbase. + * + * Example #1: Then I should not see "your text" in the "ol" element with the "class" attribute set to "breadcrumb" + * Example #2: And I should not see "your text" in the "div" element with the "id" attribute set to "right-panel" + * + * @Then /^I should not see "(?P<text>[^"]*)" in the "(?P<htmlTagName>[^"]*)" element with the "(?P<attribute>[^"]*)" attribute set to "(?P<value>[^"]*)"$/ + */ + public function iShouldNotSeeTextInTheHtmlTagElement($text, $htmlTagName, $attribute, $value) { + + $elements = $this->getSession()->getPage()->findAll('css', $htmlTagName); + if (empty($elements)) { + throw new \Exception(sprintf('The element "%s" was not found in the page', $htmlTagName)); + } + + $found = FALSE; + foreach ($elements as $element) { + $actual = $element->getText(); + $actual = preg_replace('/\s+/u', ' ', $actual); + $regex = '/' . preg_quote($text, '/') . '/ui'; + + if (preg_match($regex, $actual)) { + $found = TRUE; + break; + } + } + if ($found) { + throw new \Exception(sprintf('"%s" was found in the "%s" element', $text, $htmlTagName)); + } + + if (empty($attribute)) { + $attr = $element->getAttribute($attribute); + if (empty($attr)) { + throw new \Exception(sprintf('The "%s" attribute is present on the element "%s"', $attribute, $htmlTagName)); + } + if (strpos($attr, "$value") === FALSE) { + throw new \Exception(sprintf('The "%s" attribute does not equal "%s" on the element "%s"', $attribute, $value, $htmlTagName)); + } + } + } + /** * Click on the text in the selected element. * @@ -977,7 +1020,7 @@ class VarbaseContext extends RawDrupalContext implements SnippetAcceptingContext if (preg_match($regex, $actual)) { $found = TRUE; $element->click(); - break; + break; } } if (!$found) { @@ -1602,7 +1645,7 @@ JS; * @When /^I select (?:|the )"([^"]*)" paragraph component$/ */ public function iSelectTheParagraphComponent($value) { - $this->getSession()->getPage()->find('xpath', '//*[contains(@class, "paragraphs-add-dialog") and contains(@class, "ui-dialog-content")]//*[contains(@name, "'. $value . '")]')->click(); + $this->getSession()->getPage()->find('xpath', '//*[contains(@class, "paragraphs-add-dialog") and contains(@class, "ui-dialog-content")]//*[contains(@name, "' . $value . '")]')->click(); } /** @@ -1660,4 +1703,5 @@ JS; // no-op, alert might not be present. } } -} + +} \ No newline at end of file