Search code examples
geb

Handle redirects and implicit at assertions


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.


Solution

  • Use via instead of to

    given:
    via LanguageSelectionPage, "09";
    
    expect:
    at InsertCardReaderPage;
    

    Geb Manual