New window immediately closes in Testcafe
See original GitHub issueWhat 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
-
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
- Have something like this on a page:
<div>
<a id="myLink" href="https://www.google.com/" target="_blank">click me</a>
</div>
- Run a test which clicks on the link and tries to read the url of the newly opened window and check it
- 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:
- Created 2 years ago
- Comments:16
Top GitHub Comments
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.
Seeing the same issue with TestCafe 1.18.6 and Node 12.22.5 as well. Happens 100% of the time.