geb.error.RequiredPageContentNotPresent:所需的页面内容'loginButton不存在

时间:2015-09-21 14:08:19

标签: testing geb

我尝试启动测试时遇到此错误。

请帮我看看为什么它无法点击我的提交按钮

geb.error.RequiredPageContentNotPresent: The required page content 'loginButton - SimplePageContent (owner: LoginPage, args: [], value: null)' is not present

在我的LoginPage下面

import geb.Page
import pages.IndexPage

class LoginPage extends Page {

    static url = "login/auth"

    static at = { title == "[Paynum] Identification" }

    static content = {
        loginForm { $("form") }
        loginButton { $("input", type: "submit") }
    }
}

在我的测试页下面

import geb.spock.GebReportingSpec
import pages.*
import spock.lang.Stepwise

@Stepwise
class FactControllerSpec extends GebReportingSpec {

    def "invalid login"() {
        given: "I am at the login page"
        to LoginPage

        when: "I am entering invalid password" 
        loginForm.j_username = "bba"
        loginForm.j_password = "Bocxy1990"
        loginButton.click()

        then: "I am being redirected to the login page, the password I entered is wrong"
        at LoginPage
        loginForm.j_username == "bba"
        !loginButton.j_password
    }
}

这是我提交按钮的片段

<div>
      <button id='submit' type='submit'>
        <em class='fa fa-sign-in fa-lg'></em>
        <g:message code='springSecurity.login.button' />
      </button>
    </div>

1 个答案:

答案 0 :(得分:1)

loginButton {$(&#34;输入&#34;,输入:&#34;提交&#34;)}

应该是

loginButton {$(&#34;按钮&#34;,键入:&#34;提交&#34;)} 或者可能更好

loginButton {$(&#34; button#submit&#34;)} ,这意味着找到一个id等于提交的按钮。