我是Spock和Geb的新手,并且正在我的Grails 1.3.7应用程序中使用它们。我有一个LoginSpec和LoginPage工作。现在我想要做的是多次执行LoginSpec,指定几个不同的用户名/密码组合。我不清楚我应该如何解决这个问题。
class LoginSpec extends geb.spock.GebReportingSpec {
def "At the login page"() {
when: "we visit the login page"
to LoginPage
then:
at LoginPage
}
def "failed login"() {
when: "a user goes to the login page and enters invalid data"
to LoginPage
loginForm.j_username = "bad@test.com"
loginForm.j_password = "password"
loginButton.click()
then:
at LoginPage
}
def "successful login"() {
when: "a user goes to the login page and enters valid data"
to LoginPage
loginForm.j_username = "good@test.com"
loginForm.j_password = "password"
loginButton.click()
then:
at DashboardPage
}
}
class LoginPage extends Page {
static url = "login/auth"
static at = { heading == "sign in" }
static content = {
heading { $(".page-header>h2").text() }
loginButton(to: [DashboardPage, LoginPage]) { $('#sign_in').find("button.primary") }
loginForm { $('#loginForm') }
}
}
答案 0 :(得分:3)
您可以使用Spock的支持进行数据驱动测试:
def "successful login"() {
when: "a user goes to the login page and enters valid data"
to LoginPage
loginForm.j_username = username
loginForm.j_password = password
loginButton.click()
then:
at DashboardPage
where:
username | password
"test@test.com" | "password"
"foo" | "bar"
}