question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

New window immediately closes in Testcafe

See original GitHub issue

What is your Scenario?

I have simple case where I need to check url of a link opened in a new window. Nothing special there, just html tag with blank target. Testcafe clicks on it, opens the new window, and closes it immediately.

What is the Current behavior?

Testcafe opens and immediately closes a newly opened window.

What is the Expected behavior?

The newly opened window should not closes right away.

What is your public website URL? (or attach your complete example)

Here’s an Angular app where the issue occurs: https://github.com/vizdatom/testcafe-anchor-error

What is your TestCafe test code?

fixtureBlank target .page(http://localhost:4200); test.only(‘Should test blank link’, async () => { await t .wait(1000).click(Selector(‘#myLink’)); const getLocation = ClientFunction(() => { return window.location.href; }); await t.expect(getLocation()).contains(‘https://www.google.com/’); });

Your complete configuration file

No response

Your complete test report

$ testcafe chrome test-app.e2e-spec.ts Running tests in:

  • Chrome 99.0.4844.51 / Windows 10

Blank target × Should test blank link

  1. AssertionError: expected ‘http://localhost:4200/’ to include ‘https://www.google.com/

    Browser: Chrome 99.0.4844.51 / Windows 10

    14 | await t 15 | .wait(1000).click(Selector(‘#myLink’)); 16 | const getLocation = ClientFunction(() => { 17 | return window.location.href; 18 | });

    19 | await t.expect(getLocation()).contains(‘https://www.google.com/’); 20 |}); 21 |

    at <anonymous> (C:\Users\jzachrl\WebstormProjects\testcafe-test-app\e2e\test-app.e2e-spec.ts:19:35) at fulfilled (C:\Users\jzachrl\WebstormProjects\testcafe-test-app\e2e\test-app.e2e-spec.ts:5:58)

1/1 failed (15s)

Screenshots

No response

Steps to Reproduce

  1. Have something like this on a page:
<div>
  <a id="myLink" href="https://www.google.com/" target="_blank">click me</a>
</div>
  1. Run a test which clicks on the link and tries to read the url of the newly opened window and check it
  2. See that the test fails because the read value is the url of the old window, not the newly opened one

TestCafe version

1.18.4

Node.js version

14.16.1

Command-line arguments

testcafe chrome e2e/test-app.e2e-spec.ts

Browser name(s) and version(s)

tested on Chrome 99

Platform(s) and version(s)

Windows 10

Other

The similar (same?) problem was reported just recently, see https://github.com/DevExpress/testcafe/issues/6705, and should have been fixed in 1.18.0. However, it still fails for me with 1.18.4. The issue happens only when I serve an Angular application locally. When I try opening a link with blank target on a random internet website using Testcafe, everything works fine.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:16

github_iconTop GitHub Comments

2reactions
andreeamineacommented, Apr 6, 2022

Hi 😃 are there any updates on this issue? We have updated to version 1.18.5 and still have this problem. The window is closing immediately after it’s open on click ( we can see that the window is opening but it’s closed in a second) 😃 Can someone help? We expect to open a new page on click but it should remain open in order to continue our test in there.

1reaction
ayemel22commented, Jun 2, 2022

Seeing the same issue with TestCafe 1.18.6 and Node 12.22.5 as well. Happens 100% of the time.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Testcafe close window - Stack Overflow
I am not able to understand what should I do in order to get hold of the window oppened from js code. How...
Read more >
Multiple Browser Windows | Advanced Guides - TestCafe
When your page launches a new window, the test automatically continues in the newly opened window. When that window is closed, the test...
Read more >
Testing with TestCafe - CodeceptJS
All you need is just a browser installed, and you are ready to go. ... TestCafe can't open new tabs or open a...
Read more >
testcafe | Yarn - Package Manager
You can change the maximum wait time. If elements load faster, tests skip the timeout and continue. ... Changes in test code immediately...
Read more >
Automation Testing (UI + API) with TestCafe 2.0+ - YouTube
TestCafe Repo: https://github.com/JoanEsquivel/ testcafe -e2e-testing-boilerplate-project More about TestCafe : ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found