I'm writting cucumber test cases in grails project. I want to access messages that are configured in message.properties file
e.g. I have a property configured in message.properties file as:
view.user.page.title = View user
I have a cucumber step ViewUserSteps.groovy
Given(~'^I looged in into the app$') { ->
//code related to login
}
When(~'^I click view users tab"$') { ->
// click user tab logic
}
Then(~'^I see I am on View User page$') { ->
at ViewUserPage
}
And ViewUserPage.groovy is
import geb.Page
import grails.util.Holders
class ViewUserPage extends Page{
static url = "${Holders.config.app.url}/users/view"
static at = {
waitFor(30,2) {
title == "Edit user" // this title should be fetched from message.properties file
}
}
}
Here in ViewUserPage I should be able to fetch the title that is configured in message.properties. Something like g.message(code:'view.user.page.title') or by some other way so that if I change in message.properties, no need to change test case. Any thoughts?
You can get ask the
messageSourcebean what the text is and then compare that to the result of the request.This can look like this (with
responseData.errors.usernamebeing the result of the request (i.e. theWhenstep):messageis a small helper function to get the text of the message:We added
messageto theWorldobject, so that it is automatically available in steps.