Skip to content

Commit

Permalink
Add support for dynamic navigators created using siblings()
Browse files Browse the repository at this point in the history
  • Loading branch information
erdi committed May 11, 2019
1 parent 3365cde commit 6ae6d2c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
Expand Up @@ -715,12 +715,20 @@ class DefaultNavigator implements Navigator {

@Override
Navigator siblings(Map<String, Object> attributes) {
siblings().filter(attributes)
navigatorFor(dynamic(attributes)) {
collectSiblings {
it.findAll { matches(it, attributes) }
}
}
}

@Override
Navigator siblings(Map<String, Object> attributes = [:], String selector) {
siblings().filter(attributes, selector)
navigatorFor(dynamic(attributes)) {
collectSiblings {
it.findAll { CssSelector.matches(it, selector) && matches(it, attributes) }
}
}
}

@Override
Expand Down Expand Up @@ -1228,7 +1236,7 @@ class DefaultNavigator implements Navigator {
collectRelativeElements("child::*", filter)
}

protected Collection<WebElement> collectSiblings(Closure filter) {
protected Collection<WebElement> collectSiblings(@ClosureParams(value = FromString, options = "java.util.List<org.openqa.selenium.WebElement>") Closure filter) {
collectElements {
def elements = it.findElements(By.xpath("preceding-sibling::*")) + it.findElements(By.xpath("following-sibling::*"))
filter ? filter(elements) : elements
Expand Down
Expand Up @@ -958,4 +958,46 @@ class DynamicNavigatorSpec extends GebSpecWithCallbackServer {
dynamic.size() == 1
}

def "siblings attribute based dynamic navigator"() {
given:
bodyWithJquery {
div("div")
div("div")
div(class: "match", "div")
}

and:
def secondDiv = $("div::nth-of-type(2)")
def nonDynamic = secondDiv.siblings(class: "match")
def dynamic = secondDiv.siblings(class: "match", dynamic: true)

when:
secondDiv.jquery.before('<div class="match">div</div>')

then:
nonDynamic.size() == 1
dynamic.size() == 2
}

def "siblings selector based dynamic navigator"() {
given:
bodyWithJquery {
div("div")
div("div")
div(class: "match", "div")
}

and:
def secondDiv = $("div::nth-of-type(2)")
def nonDynamic = secondDiv.siblings(".match")
def dynamic = secondDiv.siblings(".match", dynamic: true)

when:
secondDiv.jquery.before('<div class="match">div</div>')

then:
nonDynamic.size() == 1
dynamic.size() == 2
}

}

0 comments on commit 6ae6d2c

Please sign in to comment.