Skip to content

Commit

Permalink
Merge pull request #430 from jhedstrom/jose-carmona-master
Browse files Browse the repository at this point in the history
reroll: fix issue #406 assertRegionElementAttribute

Signed-off-by: Jonathan Hedstrom <jhedstrom@gmail.com>
  • Loading branch information
jhedstrom committed Dec 4, 2017
1 parent fe62a15 commit c1f3d39
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
6 changes: 6 additions & 0 deletions features/blackbox.feature
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ Feature: Test DrupalContext
Given I am on the homepage
Then I should see "Drupal" in the "h1" element with the "id" attribute set to "site-name" in the "left header" region

Scenario: Find element with attribute set on a region
Given I am at "assertRegionElementAttribute.html"
Then I should see the "div" element with the "class" attribute set to "class1" in the "left header" region
And I should see the "div" element with the "class" attribute set to "class2" in the "left header" region
And I should see the "div" element with the "class" attribute set to "class3" in the "left header" region

Scenario: Error messages
Given I am on "user.html"
When I press "Log in"
Expand Down
20 changes: 20 additions & 0 deletions fixtures/blackbox/assertRegionElementAttribute.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<html>
<head>
<title>Drupal - Open Source CMS | Drupal.org</title>
</head>
<body>
<div id="nav-header">
<div id="header-left">
<h1 id="site-name">Drupal</h1>
<p>Build something amazing.</p>
</form>
<div id="d1" class="class class1">div1 class1</div>
<div id="d2" class="class class2">div2 class2</div>
<div id="d31" class="class class3">div31 class3</div>
<div id="d32" class="class class3">div32 class3</div>
</div>
</div>
<div id="footer">
</div>
</body>
</html>
16 changes: 11 additions & 5 deletions src/Drupal/DrupalExtension/Context/MarkupContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,24 @@ public function assertRegionElementAttribute($tag, $attribute, $value, $region)
}
if (!empty($attribute)) {
$found = FALSE;
$attrfound = FALSE;
foreach ($elements as $element) {
$attr = $element->getAttribute($attribute);
if (!empty($attr)) {
$found = TRUE;
if (strpos($attr, "$value") === FALSE) {
throw new \Exception(sprintf('The "%s" attribute does not equal "%s" on the element "%s" in the "%s" region on the page %s', $attribute, $value, $tag, $region, $this->getSession()->getCurrentUrl()));
$attrfound = TRUE;
if (strpos($attr, "$value") !== FALSE) {
$found = TRUE;
break;
}
break;
}
}
if (!$found) {
throw new \Exception(sprintf('The "%s" attribute is not present on the element "%s" in the "%s" region on the page %s', $attribute, $tag, $region, $this->getSession()->getCurrentUrl()));
if (!$attrfound) {
throw new \Exception(sprintf('The "%s" attribute is not present on the element "%s" in the "%s" region on the page %s', $attribute, $tag, $region, $this->getSession()->getCurrentUrl()));
}
else {
throw new \Exception(sprintf('The "%s" attribute does not equal "%s" on the element "%s" in the "%s" region on the page %s', $attribute, $value, $tag, $region, $this->getSession()->getCurrentUrl()));
}
}
}
}
Expand Down

0 comments on commit c1f3d39

Please sign in to comment.