withNewWindow throws NoNewWindowException for click of href="#" target="_blank"

222 views
Skip to first unread message

Brett Randall

unread,
Mar 22, 2018, 8:23:10 PM3/22/18
to Geb User Mailing List
Cross-posted to SO: https://stackoverflow.com/questions/49440479/withnewwindow-throws-nonewwindowexception-for-click-of-href-target-blank

Recently upgraded testing-stack:

- Selenium 3.11.0
- Gecko Driver 0.20.0
- Geb 2.1

I have an `index.html` with this link:


<div><a id="openNewChat" href="#" target="_blank">Open new chat</a></div>


Manual browsing with current Chrome or Firefox on MacOS, clicking this link opens a new tab containing the same page.

With this Geb code:


withNewWindow({ $('#openNewChat').click() }, close: false) {
       $
('#username').value('a')
       $
('#message').value('xxx')
       $
('#btnSend').click()
       otherBrowser
= getCurrentWindow()
     
}



... Geb throws a NoNewWindowException every execution.  If I change the target to target="otherBrowser", the exception is not thrown, and the test passes.

Is Geb/WebDriver/Gecko/Selenium doing something wrong here?  I'm guessing that the answer is going to come back that this is a problem upstream of Geb, and that Geb is just seeing the driver report the same set of availableWindows before and after the click.


Brett

Marcin Erdmann

unread,
Mar 23, 2018, 5:49:11 AM3/23/18
to Geb User Mailing List
Hi Brett,

You are correct in thinking that the problem is most likely upstream of Geb and Gecko is either not opening the new window or reporting that no new window has been opened. Let's try to find what exactly the problem is.

Some questions:
1. You said you recently upgraded the stack. Did the code in question used to work before? If so, which versions of libraries in the stack did it work on?
2. You said that changing the target of the link makes the test pass (I find it surprising that changing the target has an influence on the outcome) but what about leaving the target as is and changing the href? I have a suspicion that the behaviour you're seeing has something to do with using # as href because clicking on a link like that will not load/reload the url in the browser.
3. Do you see the new window opened if you put a breakpoint at https://github.com/geb/geb/blob/master/module/geb-core/src/main/groovy/geb/Browser.groovy#L828 and run the test? 

--
You received this message because you are subscribed to the Google Groups "Geb User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geb-user+unsubscribe@googlegroups.com.
To post to this group, send email to geb-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/geb-user/35ac97e3-f465-498e-b90c-f26453a29558%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Message has been deleted

Marcin Erdmann

unread,
Mar 28, 2018, 9:31:28 AM3/28/18
to Geb User Mailing List
Is that test passing locally on MacOS for you using the same version of selenium, gecko and Firefox? I'm wondering if the issue is in running it in headless mode. You did not mention in your original post that the tests are run in headless mode on Travis.

On Tue, Mar 27, 2018 at 3:42 AM, Brett Randall <java...@gmail.com> wrote:
Hi Marcin, thanks for the reply.

For 1 - it's a little hard to compare what worked with what did not, because I was trying to move the tests to another platform that was quite different to where the tests were working:

Working: MacOS, geckoDriverVersion = 0.17.0 (macos), seleniumVersion = 3.4.0, gebVersion=1.1.1
New Environment: Linux Ubuntu Trusty, headless on Travis, geckoDriverVersion = 0.20.0, seleniumclick target that opens the new windowVersion=3.11.0, gebVersion=2.1

The tests as they were hard-coded the Gecko driver to MacOS ... having fixed that, the tests did not run well on Travis.  In addition to the upgrades, I added a Selenium setHeadless(true) for the Firefox driver.

For 2 - changing the target certainly seemed to work.  With either "_blank" or "anythingelse" when clicking the link in a manual browser, a new tab opened fine.  For some reason in headless/test-run mode it did not like the _blank.  I'll see if I can come up with something different for the href="#", but since the link is just a JavaScript click target, I don't really see a problem with that link.

For 3 - I can't set a breakpoint in Travis at the moment.  I might try on a non-Travis Linux environment to do that.  What I can say is that there are either 0 or >1 windows created based on the code - those are the only possibilities.  Unfortunately I'm not getting the NoNewWindowException string message at the moment to clarify which it is, but I guess 0.

Brett
To unsubscribe from this group and stop receiving emails from it, send an email to geb-user+u...@googlegroups.com.

To post to this group, send email to geb-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/geb-user/35ac97e3-f465-498e-b90c-f26453a29558%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Geb User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geb-user+unsubscribe@googlegroups.com.
To post to this group, send email to geb-...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages