4

The website I want to test has a landing page which asks you to chose a language. You can skip this question by adding an extra parameter in the url. I want to test this behaviour with Geb and Spock as testing framework.

So I have the landing page with language selection:

class LanguageSelectionPage extends Page {

    static url = "http://localhost:8080/registration/"

    static at = { $("form#languageForm") }
}

The second page where it redirects to:

class InsertCardReaderPage extends Page {

    static at = { welcomeTitle1 }

    static content = {
        welcomeTitle1(wait: true, cache: false) { $("#eidWelcomeTitle1") }
        welcomeTitle2(wait: true, cache: false) { $("#eidWelcomeTitle2") }
    }
}

(I've removed some methods from the pasted code)

So this is my test:

given:
to LanguageSelectionPage, "09";

expect:
at InsertCardReaderPage;

The "09" is an extra parameter in the url, when this one is available you will be immediatly redirected by the server (http redirect, so the page does change) to the InsertCardReaderPage. Now, my problem is that the to statement performs an implicit assertion on the at closure. This one fails because you have been redirected away from the page already.

Is there a way to conditionally disable this implicit assertion in this case? Or any other proposal how to setup the pages? I'm pretty new to Geband can't find any documentation that seems to help me in this case.

ChristopherS
  • 853
  • 4
  • 16
  • Would using a page without an at assertion do the trick? – twinj Nov 10 '14 at 04:14
  • I don't see that as a viable option. In 99% of my tests I want to make sure that you start from the `LanguageSelectionPage`. I like the feature that I don't always need to make an explicit assertion to check that. – ChristopherS Nov 10 '14 at 08:35
  • Just a small note, cache: false is the default, you don't need to explicitly specify it – erdi Nov 11 '14 at 08:12

1 Answers1

6

Use via instead of to

given:
via LanguageSelectionPage, "09";

expect:
at InsertCardReaderPage;

Geb Manual

Kevan Ahlquist
  • 5,375
  • 1
  • 17
  • 25
twinj
  • 2,009
  • 18
  • 10