如何使用Geb验证错误消息



如何捕获网页上生成的错误消息(例如,在未插入任何用户名或密码的情况下按下登录按钮时生成的错误信息(,如何使用geb提取此错误消息"username is required"。im使用基于geb-groovy的自动化

因此,您将首先对页面进行建模,并获取要断言的错误的定位器。请注意,您希望将其设置为required:false,因为您不希望它在第一次登录页面时显示。

带有示例页面错误的页面,ID为#pageError:

class MyPage extends Page
{
static url = "/mypageurl"
static at = {
title == "My Page"
}
static content = {
pageError (required: false) { $('#pageError') }
submitButton { $('#mySubmitButton') }
}
def submitForm() {
submitButton.click()
}
}

然后你有你的测试:

def "If I try click Submit without filling out all form details show me an error message"()
{
when: "I click Submit without completing all form fields"
def myPage = to(MyPage)
myPage.submitForm()
then: "I am shown an error message on the same page"
myPage.pageError.displayed
}

编辑:

注意到你提到了获取错误的内容,你会调用它来获取文本:

myPage.pageError.text()

相关内容

最新更新