2017-09-28 134 views
2

我有對網頁上的每一個元素定義內容的模塊,我有工作:如何一次性使用Spock驗證Geb模塊的全部內容,而不是單獨聲明每個元素?

package com.gdit.qa.fwa.geb.cmdr.modules 

import geb.Module 

class Member extends Module { 
    static content = { 
     // Member fields 
     mbrID {$("div.subject-details div.memberDetails input.projMbrId")} 
     mbrName {$("input.projMbrName")} 
     mbrRegion {$("select.projMbrReg")} 
     mbrAdd1 {$("input.projMbrAdd1")} 
     mbrAdd2 {$("input.projMbrAdd2")} 
     mbrAdd3 {$("input.projMbrAdd3")} 
     mbrCity {$("input.projMbrCity")} 
     mbrState {$("select.projMbrState")} 
     mbrZip {$("input.projMbrZip")} 
     mbrHomePhone {$("input.projMbrHomePhone")} 
     mbrHomePhoneExt {$("input.projMbrHomePhoneExt")} 
     mbrWrkPhone {$("input.projMbrWorkPhone")} 
     mbrWrkPhoneExt {$("input.projMbrWorkPhoneExt")} 
     mbrEmail {$("input.projMbrPersonalEMail")} 
     mbrWrkEmail {$("input.projMbrWorkEMail")} 
    } 
} 

在我的測試規範,我斷言,包含我的模塊中的每個元素存在,但只有這樣,我知道如何做到這一點是通過單獨斷言每個元素:一下子讓

package cmdr.ProjectCover 

import com.gdit.qa.fwa.geb.cmdr.pages.HomePage 
import com.gdit.qa.fwa.geb.cmdr.pages.ProjectCover 
import geb.spock.GebReportingSpec 

class VerifyMemberFields extends GebReportingSpec { 
    def setupSpec() { 
     // Log in to app 
     via HomePage 
     loginPage.signIn("marco", "abc123") 

     // Navigate to Member Page 
     memberPageButton.click() 
    } 

    def "Verify Member fields exist"() { 
     when: "User selects Member option for subject type" 
     at ProjectCover 
     projSubject.click() 
     projCoverMbrFields.projSubjectMbrOption.click() 

     then: "All expected member fields are displayed in the left panel" 
     assert projCoverMbrFields.mbrID.present 
     assert projCoverMbrFields.mbrName.present 
     assert projCoverMbrFields.mbrRegion.present 
     assert projCoverMbrFields.mbrAdd1.present 
     assert projCoverMbrFields.mbrAdd2.present 
     assert projCoverMbrFields.mbrAdd3.present 
     assert projCoverMbrFields.mbrCity.present 
     assert projCoverMbrFields.mbrState.present 
     assert projCoverMbrFields.mbrZip.present 
     assert projCoverMbrFields.mbrHomePhone.present 
     assert projCoverMbrFields.mbrHomePhoneExt.present 
     assert projCoverMbrFields.mbrWrkPhone.present 
     assert projCoverMbrFields.mbrWrkPhoneExt.present 
     assert projCoverMbrFields.mbrEmail.present 
     assert projCoverMbrFields.mbrWrkEmail.present 
    } 

我想知道是否有辦法爲我(而不是單獨斷言我的模塊中的每個元素)斷言模塊的全部內容我的特徵方法,然後阻止條件可以減少。

回答

1

我現在還不知道這樣做的方法,但是當GEB-369被實現時,這將是可能且相對容易的。

-1

我沒有時間來測試這一點,但我認爲,如果你想給它一個嘗試這應該工作:

def "Verify Member fields exist"() { 
    when: "User selects Member option for subject type" 
    at ProjectCover 
    projSubject.click() 
    projCoverMbrFields.projSubjectMbrOption.click() 

    then: "All expected member fields are displayed in the left panel" 
    projCoverMbrFields.content.each{ element -> 
     assert element.present 
    } 
} 
相關問題