在一次 Geb 测试中使用多个页面对象

测试猛禽

我正在尝试使用 spock 编写一个基本的登录geb 测试。我创建了 2 个页面对象,一个用于登录页面,另一个用于登录后进入的页面。

登录页面

package Pages

import geb.Page

class loginPage extends Page {
    static url = 'login/'
    static at = {title == "Login to TalentBank"}
    static content = {
        logo {$(".center-img img")}
        emailHeader {$(".form-group label", text:"Email")}
        emailTextBox {$('#email')}
        pwdHeader {$(".form-group label", text:"Password")}
        pwdTextBox {$("#password")}
        loginButton {$("#loginButton")}
    }
}

主页

package Pages

import geb.Page

class homePage extends Page {
    static at = {title == "Home"}
    static content = {
        tile1 {$("#page-container > div.container-fluid > div > div:nth-child(2) > div")}
    }
}

测试规格 这是转到登录页面、输入用户凭据、单击登录按钮、等待主页上的元素,然后验证您是否在主页上的基本测试。

import Pages.loginPage
import Pages.homePage
import geb.spock.GebReportingSpec


class loginPageSpec extends GebReportingSpec {


    def "Log in to TalentBank Core"(){
        given:
        to loginPage
        waitFor {loginButton.isDisplayed()}

        when:
        emailTextBox.value("Ruxin")
        pwdTextBox.value("Test1234")
        loginButton.click()

        then:
        waitFor {tile1.isDisplayed()}
        at homePage
    }
}

当我运行测试时,出现以下错误

引起:groovy.lang.MissingPropertyException:无法将 tile1 解析为 Pages.loginPage 的内容,或作为其导航器上下文中的属性。tile1 是您忘记导入的类吗?

它在 loginPage 而不是 homePage 中寻找 tile1。

小地毯

更改at测试中的位置,我还将添加页面引用,您将从自动完成中受益。

登录页面

package Pages

import geb.Page

class LoginPage extends Page {

    static url = 'login/'

    static at = {
           title == "Login to TalentBank"
    }

    static content = {
        logo         {$(".center-img img")}
        emailHeader  {$(".form-group label", text:"Email")}
        emailTextBox {$('#email')}
        pwdHeader    {$(".form-group label", text:"Password")}
        pwdTextBox   {$("#password")}
        loginButton  {$("#loginButton")}
    }
}

主页

package Pages

import geb.Page

class HomePage extends Page {

    static at = {
           waitFor {title == "Home"} // Add waitFor here to verify on page
    }

    static content = {
        tile1 {$("#page-container > div.container-fluid > div > div:nth-child(2) > div")}
    }
}

测试规格:

import Pages.LoginPage
import Pages.HomePage
import geb.spock.GebReportingSpec


class LoginPageSpec extends GebReportingSpec {

    def "Log in to TalentBank Core"(){
        given:
        Page loginPage = to LoginPage
        waitFor {loginPage.loginButton.isDisplayed()}

        when:
        loginPage.emailTextBox.value("Ruxin")
        loginPage.pwdTextBox.value("Test1234")

        and: "Click login"
        loginPage.loginButton.click()

        then: "Check at home page"
        Page homePage = at HomePage

        and:
        waitFor {homePage.tile1.isDisplayed()}
    }
} 

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章