unit testing - How to "match" complex patterns like tables with Geb Page? -
suppose have complex construct repeating patterns long table data or nesting constructs.
just small example:
<div id="mycontroller1"> <div class="myfield1">some text11</div> <div class="myfield2">some text12</div> </div> <div id="mycontroller2"> <div class="myfield1">some text21</div> <div class="myfield2">some text22</div> </div>
and suppose content of these divs can changed javascript , wish check it. write like:
def 'whether page worked correctly'() { when: mypage ... then: assert mycontroller1.myfield1 == "some text11" assert mycontroller1.myfield2 == "some text12" assert mycontroller2.myfield1 == "some text21" assert mycontroller2.myfield2 == "some text22" }
i.e. access fields via intermediate hierarchy member (note dot notation).
how write page definition then?
currently suspect know how write "flat" way
class mypage extends page { static url ... static @ ... static content = { mycontroller1_myfield1 { $('#mycontroller1 .myfield1').text() } mycontroller1_myfield2 { $('#mycontroller1 .myfield2').text() } mycontroller2_myfield1 { $('#mycontroller2 .myfield1').text() } mycontroller2_myfield2 { $('#mycontroller2 .myfield2').text() } } }
which allow test "flat" (note underscore)
def 'whether page worked correctly'() { when: mypage ... then: assert mycontroller1_myfield1 == "some text11" assert mycontroller1_myfield2 == "some text12" assert mycontroller2_myfield1 == "some text21" assert mycontroller2_myfield2 == "some text22" }
how write hierarchical?
also, required write search $('#mycontroller1
many times, looks excessive. if able select block , add furhter selections or checks block -- great.
you should use class extends module
model repeating content - repeating across different pages or in single page. modules explained in this chapter of book of geb , there section abut using modules repeating content.
Comments
Post a Comment