Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing state between pages when using geb & spock
    primarykey
    data
    text
    <p>In the example below (Taken from the <a href="http://geb.codehaus.org/manual/latest/index.html" rel="nofollow noreferrer">Book of Geb</a>), we're clicking on a button that takes us to another page. </p> <pre><code>class GoogleHomePage extends Page { static url = "http://google.com" static at = { title == "Google" } static content = { searchField { $("input[name=q]") } searchButton(to: GoogleResultsPage) { $("input[value='Google Search']") } } } Browser.drive(GoogleHomePage) { searchField.value("Chuck Norris") searchButton.click() assert at(GoogleResultsPage) assert resultLink(0).text() ==~ /Chuck/ } </code></pre> <p>How can we pass state when going to another page? eg The user has selected this language, in the next page, I expect the page to be in that language. A more generic example:</p> <pre><code>import geb.* import grails.plugin.geb.GebSpec class GoogleHomePage extends Page { static url = "http://google.com" static at = { title == "Google" } static content = { searchField { $("input[name=q]") } searchButton(to: GoogleResultsPage, searchTerm:searchField.value()) { $("input[value='Google Search']") } } } class GoogleResultsPage extends Page { def searchTerm static at = { title == "${searchTerm} - Google Search" } } class MainFunctionalSpec extends GebSpec { def "Google search"() { when: to GoogleHomePage then: searchField.value("Chuck Norris") searchButton.click() assert at(GoogleResultsPage) } } </code></pre> <p>This code has 2 problems, I get a "No such property: searchField for class: GoogleHomePage" on searchButton.click() when trying to populate searchTerm. Even if I hardcode what gets passed, GoogleResultsPage.searchTerm is null and the at assert fails. Any ideas? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload