Fork me on GitHub

LD.

Music, software, life… and stuff.

[ Twitter ] [ GitHub ] [ Linked In ]

Geb Modules and isDisplayed()

A question recently came up on the Geb user mailing list about checking to see if a module is displayed on a page. It turns out the concept of displayed could do with some exploration.

Say we have the following html…

<p class="a" style="display:none"/>
<p class="b"/>

The following assertions will pass…

def a = $("p.a")
def b = $("p.b")
def c = $("p.c")

assert a && !a.displayed
assert b && b.displayed
assert !c && !c.displayed

So isDisplayed() means that the navigator matches some content and the first thing that it has matched is actually visible on the page. $("p.c").displayed returns false because it doesn’t match anything.

Navigator objects implement the Groovy Truth, so those assertions could be written as…

assert a.size() != 0 && !a.displayed

Modules also implement the Groovy Truth using the same test, so…

class ParagraphA extends Module {
    static base = { $("p.a") }
}
class ParagraphB extends Module {
    static base = { $("p.b") }
}
class ParagraphB extends Module {
    static base = { $("p.c") }
}

Now assume we have moduleA, moduleB and moduleC vars that are instances of the corresponding modules, and we can write the following assertions…

assert moduleA && !moduleA.$().displayed
assert moduleB && moduleB.$().displayed
assert !moduleC && !moduleC.$().displayed

You can get the “base” of a module at anytime with «module».$(), just like you can do relative lookups (i.e. someModule.$(“p.d”))

Posted: Jun 16th, 2011 @ 9:56 am

Tags: #software  #geb  

Comments

Archive · RSS · Theme by Autumn