Question

We are using Geb for our functional tests. In our app, clicking a link opens a new window. Inside our "when:" clause, we are able to use withNewWindow() to click the link and open the new window, and make a few quick assertions. The problem is that we want to make more assertions and do more things within the "then:" clause, but our window closes before we can get there.

when: "I navigate to the link"
        JQInstaller jq = new JQInstaller()
        jq.installJQ(browser)
        homeTab.jquery.mouseover()
        report "Mouse Over1"
        waitFor {HealthPageLink.present}
        withNewWindow({HealthPageLink.click() },{
            assert (title.toString() == 'Patient Financing Portal')
            at LoginPage
            report "Login Page"
        }
    )

   then:  "I am at the Login Page"
       at LoginPage
       report "Login Page"

In the then: clause, "LoginPage" comes out null, because our new window has been closed after the "when:" clause.

How do we keep this window context open to run some more tests on it?

Was it helpful?

Solution

By default Geb will close the window opened using withNewWindow(). You can suppress this default behaviour using close option:

withNewWindow(close: false, { HealthPageLink.click() }) {
    ...
}

The window won't be closed but you will be outside of its context in then: block. You can use `withWindow()' for getting back into its context.

withWindow({ title.toString() == 'Patient Financing Portal }) {
    ...
}

You might actually consider not using withNewWindow() in the first place in your when: block but simply clicking the health page link and using withWindow() in the then: block where you would perform all the necessary assertions.

EDIT: This isn't documented anywhere but after leaving the context of withNewWindow() (and withWindow() as well) the page is switched back to the original one. You can use page option to switch it back to LoginPage:

withWindow({ title.toString() == 'Patient Financing Portal }, page: LoginPage) {
    ...
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top