Having an issue with a particular webpage using withWindow and withNewWindow. I can't post the sites because they are internal sites, but what is happening on one particular link is it opens a new tab and it takes about 3 seconds for the page to load and it looks like there is a redirect happening. I thought I could just bypass the redirect and using a waitFor and waiting for the URL of the final page.
def "click 'wellness articles and videos' link"(){
given:
at HomePage
when:
withNewWindow({ click(page.wellnessArticlesLink)},wait: true ) {
waitFor {currentUrl.contains("url-here")}
}
then:
at HomePage
}
What is happening is it clicks the link and opens a new tab and then the page stops loading after about 2 seconds, as if I am sending some kind of stop command. It then sits there for about 5 minutes until the test fails. I noticed if I only put a println statement in the withNewWindow block instead of a waitFor or an assert then it works. So it seems like the driver switching to the new tab is actually stopping the loading somehow. The same thing happens when I use withWindow.
Right now I have to resort to this:
def "click 'wellness articles and videos' link"(){
given:
page = at HomePage
when:
withNewWindow({ click(page.wellnessArticlesLink)},wait: true ) {
sleep(3000)
assert currentUrl.contains("url-here")
}
then:
at HomePage
}
That 3 second hard sleep prevents this issue from happening. I HATE using hard sleeps though so this is not my preferred way. I haven't had any issue with the withNewWindow function until now and in fact I am using it in about 6 other tests just fine, but those sites don't seem to have a redirect or anything.
Any help is appreciated.