How to check 'close' button on new tab via using 'withNewWindow' method

47 views
Skip to first unread message

Gordon Freeman

unread,
Mar 31, 2019, 4:22:27 PM3/31/19
to Geb User Mailing List
Hi! 
I am a new user of GEB framework and already got used to work with 'withNewWindow' method.

Scenario:
1. I am on the page 'A' pressing some link and automatically will be opened new Tab 'B' and I will be on tha tab 'B'
2. I am checking some elements on tab 'B' and also have to check 'Close' button on the page 'B'. 
We have such functionality in our system, after pressing 'Close' button - automatically will be closed tab 'B' and user will be on the tab 'A'

S, I have tried to use this code
       browser.withNewWindow({ $("someElement").click() }, wait: true) { //open new tab 'B'
            assert title == Some_Title

            //here checks for other elements on the page//

            closeButton.click // here I will get exception, because tab 'B' will be closed, but closure is still in progress
        }

But as I mentioned  in code - it will produce exception, because closure is still in progress but tab is already closed after pressing 'Close' button on the page.


How can I manage this? How do people work with such cases?

Of course, I can open new tab 'B' without Geb and this 'withNewWindow' method, take unique tab ID and after pressing 'Close' button - write assert that browser has not such tab ID. But I wanna use GEB.
Is it possible? 

jeremy...@gmail.com

unread,
Apr 1, 2019, 3:53:07 PM4/1/19
to Geb User Mailing List
Hi Gordon,

I am not sure I am understanding you correctly, but my interpretation is you have a popup window that you are trying to click the Close button in and that close button closes the window?  According to this section in The Book of Geb, you can pass close: false as an option to the closure.  This will stop the window from closing upon completion of the code in the closure.  However, when you click the close button in the window, you will then manually need to point the driver back to the main window if you have any part of the test that needs to continue.

I could be wrong but that was my interpretation of your issue.

Gordon Freeman

unread,
Apr 1, 2019, 4:19:28 PM4/1/19
to Geb User Mailing List
Hi! Not popup, just usual page, you know sometimes on the page you can have button for closing page (ex: term of use page).

Anyway, today I have found solution: I did not know about parameter 'close:false'
assert browser.availableWindows.size() == 1
        browser.withNewWindow({ openLink() }, wait: true,close:false) {
            waitFor{title == "Some_Title"}
            assert browser.availableWindows.size() == 2
            closeButton.click()
            assert browser.availableWindows.size() == 1
        }


Reply all
Reply to author
Forward
0 new messages