如何使用SPOCK立即验证GEB模块的整个内容,而无需单独主张每个元素



我有一个模块,该模块为我正在使用的网页上的每个元素定义了:

package com.abc.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
    }

我想知道我是否有一种方法可以(而不是单独断言我的模块的每个元素)立即主张模块的整个内容,以便可以减少我的功能方法。

我目前不知道一种方法,但是当实施GEB-369时,这将是可能的,并且相对容易。

我没有时间进行测试,但是如果您想尝试一下,我认为这应该有效:

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

相关内容

  • 没有找到相关文章

最新更新