Grails Geb点击在输入完成之前执行

Grails Geb点击在输入完成之前执行,grails,geb,Grails,Geb,我正在运行一个简单的Geb测试,如下所示: class IndexPage extends Page { //static url = "http://localhost:8080/sampleGrailsApp" static at = { title == "sampleGrailsApp" } static content = { signInButton { $("div", 0, class: "container-fluid").find("button", 0)

我正在运行一个简单的Geb测试,如下所示:

class IndexPage extends Page {
  //static url = "http://localhost:8080/sampleGrailsApp"
  static at = { title == "sampleGrailsApp" }
  static content = {
    signInButton { $("div", 0, class: "container-fluid").find("button", 0) }
    modalFooterSignInButton(wait: true, to: MyPage) { $("footer", 0, class: "modal-footer").find("input", 0, class: "btn-primary") }
    modalFooterUsernameInput { $("form").username = it }
    modalFooterPasswordInput { $("form").password = it }
    signIn { username, password ->
      signInButton.click()
      waitFor { modalFooterSignInButton.present }
      modalFooterUsernameInput username
      modalFooterPasswordInput password
      modalFooterSignInButton.click()
    }
  }    
}
在我的测试中,页面调用如下:

def "sigin"() {
    given: "User is at index page"
    at IndexPage

    when: "User signs in"
    signIn "username","password"

    then: "Goes to MyPage"
    at MyPage
  }
在某些情况下,modalFooterSignInButton.click()发生在用户名完全输入之前,因此测试失败。以前有人遇到过这种情况吗?如何等待输入首先完成,然后再激活单击?我使用的是GEB0.9.2


提前感谢。

您可以执行以下操作:

waitFor { $(<username-input>).text().contains("username") } // after username is entered.
waitFor { $(<password-input>).text().contains("password") } // after password is entered.
输入用户名后,
waitFor{$().text()包含(“用户名”)}//。
输入密码后等待{$().text()包含(“密码”)}//。
在调用modalFooterSignInButton之前。单击()


此外,这种行为是特定于任何浏览器还是在所有浏览器中都会发生?

尝试使用
isDisplayed()
而不是present as present表示代码中存在,但isDisplayed()表示它出现在UI中。希望下面的东西能解决你的问题

waitFor { modalFooterSignInButton.isDisplayed()}

另外,在紧急情况下使用
waitFor{}
,因为我对你的应用程序一无所知。

谢谢,我试过了,但没用。我认为不可能读取文本输入,因为它没有出现在html中。我目前只在Chrome中测试它,所以我不确定它是否在其他浏览器中发生。这不是一个理想的解决方案,但如果在modalFooterSignInButton.click()之前添加一个sleep(500)或sleep(1000),那么它应该可以工作。我从未见过有人需要等待文本输入完成,所以这种行为让我感到困惑(waitFor应该能够很好地处理这种情况!即使是geb的核心开发者Erdi或Peter,他们也总是不鼓励使用睡眠或相关的东西!我自己从来没有在geb中使用过睡眠!@user3240644即使我没有遇到过这种行为,但我一直使用FireFox进行测试。Mamun:同意你的观点,但例外情况是e总是在那里:)谢谢。isDisplayed()似乎已经解决了这个问题。我现在不能确定,因为这个问题是间歇性的。但是我已经运行了几次测试,没有遇到这个问题。再次感谢。@user3240644:别担心,伙计!感觉真的很棒,它为你工作!让我们发展geb社区,让它成为一个更大的社区!