2016-01-07 30 views
0

假設我有一個複雜的結構,其中包含重複的模式,如具有數據或類似嵌套構造的長表。如何「匹配」像Geb Page這樣的複雜模式?

只是一個小例子:

<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> 

,並假設這些div的內容可以用JavaScript來實現改變,我要檢查一下。我想編寫類似:通過中間層次結構成員(注點表示)

def 'Whether my page worked correctly'() { 

    when: 
     to MyPage 
     ... 

    then: 

     assert mycontroller1.myfield1 == "Some text11" 
     assert mycontroller1.myfield2 == "Some text12" 

     assert mycontroller2.myfield1 == "Some text21" 
     assert mycontroller2.myfield2 == "Some text22" 

} 

即接入領域。

那麼我會如何寫頁面定義呢?

目前我懷疑我知道怎麼寫「平」的方式

class MyPage extends Page { 

    static url ... 

    static at ... 

    static content = { 

     mycontroller1_myfield1 { 
      $('#mycontroller1 .myfield1').text() 
     } 

     mycontroller1_myfield2 { 
      $('#mycontroller1 .myfield2').text() 
     } 

     mycontroller2_myfield1 { 
      $('#mycontroller2 .myfield1').text() 
     } 

     mycontroller2_myfield2 { 
      $('#mycontroller2 .myfield2').text() 
     } 



    } 

} 

允許測試「平」(注下劃線)

def 'Whether my page worked correctly'() { 

    when: 
     to MyPage 
     ... 

    then: 
     assert mycontroller1_myfield1 == "Some text11" 
     assert mycontroller1_myfield2 == "Some text12" 

     assert mycontroller2_myfield1 == "Some text21" 
     assert mycontroller2_myfield2 == "Some text22" 

} 

如何寫分層?

此外,我需要多次搜索$('#mycontroller1,這看起來過多。如果我能夠選擇一些塊,然後添加一些furhter選擇或檢查到該塊 - 這將是偉大的。

+0

爲什麼不在「內容」塊中將它們稱爲「myfield1」? –

+0

在某些情況下可能有重複。例如,頁面上的許多表單等。 – Dims

+1

複製ID –

回答