The Wayback Machine - https://web.archive.org/web/20220417104604/https://github.com/karatelabs/karate/issues/1606
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

driver.url still reporting URL of original tab after using switchPage #1606

Closed
nathanchilton opened this issue May 20, 2021 · 12 comments
Closed

driver.url still reporting URL of original tab after using switchPage #1606

nathanchilton opened this issue May 20, 2021 · 12 comments
Assignees
Milestone

Comments

@nathanchilton
Copy link

@nathanchilton nathanchilton commented May 20, 2021

We have a workflow in our web app which opens in a second tab. We had a test which was able to verify the correct behavior.

This test was working with Karate version 0.9.6. We have since upgraded to version 1.0.1 and this test is now failing. Visually, I can see the browser switch between tabs, but driver.url is still reporting the URL of the original tab.

I put together a simple demonstration of the problem, which does not use our website. This test passes with Karate version 0.9.6, but fails with version 1.0.1.

Feature: Second Tab Demo

  Passes with Karate version: 0.9.6
  Fails with Karate version: 1.0.1

  Scenario: Verify link opens in new tab
    * driver 'https://google.com'

    * text replaceLink =
      """
        document.querySelectorAll('a')[0].innerHTML = '<a id="yahoo" href="https://yahoo.com" target="_blank">Yahoo!</a>'
      """

    * script(replaceLink)
    * click("#yahoo")
    * delay(5000)
    * switchPage('Yahoo')
    * karate.log("driver.url", driver.url)
    * match driver.url contains 'yahoo.com'

@ptrthomas
Copy link
Member

@ptrthomas ptrthomas commented May 20, 2021

@nathanchilton should be simple to fix, but tagging as help wanted, trying to boost contributions.

a workaround could be to do * var theUrl = script('window.location.href') or equiv

@nathanchilton
Copy link
Author

@nathanchilton nathanchilton commented May 20, 2021

@ptrthomas Thank you for your prompt response!

I tried * def theUrl = script('window.location.href'), but it returns the same value as driver.url. I can run switchPage('Yahoo') and switchPage('Google') in the debug console and see the active tab switching in the browser, but no matter which tab appears to be active, the responses from the driver object's methods and from executing JavaScript, still indicate that they are interacting with the original tab:
image

@ptrthomas
Copy link
Member

@ptrthomas ptrthomas commented May 20, 2021

@nathanchilton okay, we'll look at it, and hope someone picks it up sooner

@nathanchilton
Copy link
Author

@nathanchilton nathanchilton commented May 20, 2021

Thank you, @ptrthomas!

@ptrthomas
Copy link
Member

@ptrthomas ptrthomas commented May 22, 2021

@nathanchilton it should be fixed. it would be great if you can build from source as I tried to make some fundamental improvements. and note that switchPage(string) is now "retry aware" so you don't need to use a delay. let me know how it goes !

@nathanchilton
Copy link
Author

@nathanchilton nathanchilton commented Jun 3, 2021

@ptrthomas I just confirmed that this is fixed in v1.1.0.RC2
Thank you!

@janmenezes28
Copy link

@janmenezes28 janmenezes28 commented Jun 7, 2021

@nathanchilton Could you please provide details of your POM file as I am facing similar too issue..I havent updated to a latest version before and I am unable to do so..Would be of much help if I know what I am doing wrong.
Thanks!

@nathanchilton
Copy link
Author

@nathanchilton nathanchilton commented Jun 29, 2021

@nathanchilton Could you please provide details of your POM file as I am facing similar too issue..I havent updated to a latest version before and I am unable to do so..Would be of much help if I know what I am doing wrong.
Thanks!

@janmenezes28, I'm sorry to be so late to reply to your comment. I learned Java back in the late 90s, before the magic of Maven, and I haven't dedicated the time to learning it yet.

I actually have filed an issue in my backlog to move to using Maven to manage dependencies.

Currently, I am using the stand-alone executable (.jar file) for Karate, and I maintain a directory full of other .jar files for all of our dependencies. So, unfortunately, I do not have a POM file to share with you at this time. I hope you have managed to find a solution by now.

@janmenezes28
Copy link

@janmenezes28 janmenezes28 commented Jun 30, 2021

@nathanchilton Thank you for the response and yes I am able to proceed after switching to a newer version..

@ptrthomas
Copy link
Member

@ptrthomas ptrthomas commented Aug 4, 2021

1.1.0 released

@ptrthomas ptrthomas closed this Aug 4, 2021
@subra86
Copy link

@subra86 subra86 commented Sep 2, 2021

switchpage is still not working even after the 1.1.0 fix . I also validated the same with the older versions 1.1.0.RC4,RC3,RC2 and latest version 1.2.0.RC1 none of them seems working ! Below is the sample script , even after the switchpage statement it return the url of the original tab and none of the element being identified from the new tab !

Script

 Given driver 'https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_win_open'
Then maximize()
When switchFrame('#iframeResult')
 * print 'driver.url before switch----------------', driver.url
And highlight("{}Try it")
And click("{}Try it")
* delay(2000)
And switchPage('https://www.w3schools.com/')
* delay(2000)
* print 'driver.url after switch----------------', driver.url
* highlight("//a[@href='https://www.w3schools.com ']")
* delay(5000) 

Console Log:

15:26:36.385 [pool-1-thread-1] INFO com.intuit.karate - [print] driver.url before switch---------------- https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_win_open
15:26:43.818 [pool-1-thread-1] INFO com.intuit.karate - [print] driver.url after switch---------------- https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_win_open

@ptrthomas
Copy link
Member

@ptrthomas ptrthomas commented Sep 3, 2021

@subra86 please contribute code ! or for now at lease follow this process and open a new issue: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
4 participants