Reputation: 1315
I have the following spock test. I am first going to the login page, and then I am clicking the login button without entering an email and password to verify the error message. I will add other steps later such as email but no password and email with incorrect password, but I first need to get this test to work.
package loginPageTests
import Pages.loginPage
import geb.Page
import geb.spock.GebReportingSpec
class invalidLoginSpec extends GebReportingSpec {
def "Go to login page"() {
when:
Page loginPage = to loginPage
waitFor { loginPage.loginButton.isDisplayed() }
then:
at loginPage
}
def "Try to log in without email or password"() {
when:
loginPage.loginButton.click()
then:
at loginPage
assert loginPage.loginError.text() == "Please enter your email and password."
}
}
And the following page object
package Pages
import geb.Page
class loginPage extends Page {
static url = 'login/'
static at = { title == "Login to TB"}
static content = {
loginButton {$("#loginButton")}
loginError(wait:true) {$("#loginError")}
}
}
The first method runs successfully, but I get this error when the second method tries to run
groovy.lang.MissingPropertyException: No such property: loginButton for class: Pages.loginPage
the property loginButton is in the loginPage page object, so I'm not sure why this error is occurring.
Upvotes: 2
Views: 2178
Reputation: 27200
The way you are interacting with the page is non-idiomatic but to answer the question asked...
You have defined loginPage
as a local variable inside of the first test method and then tried to reference it inside of the second test method where it is out of scope.
Upvotes: 1