testcafe
testcafe copied to clipboard
New window immediately closes in Testcafe
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
-
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
(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.
Thank you for your report. I have reproduced the described behavior. We will update this thread once we have any news.
Note for the team: This issue manifests intermittently on my machine, during about 10-30% of test runs. I managed to reproduce this issue with Node.js v14.16.1, as well as the LTS version (currently 16.14.1). The issue occurs more often if you focus a different window (for instance, a terminal) after Chrome launches, but before the child window is opened (60-80% runs).
Hello. I have the same issue. I use environment variables as well.
I want to access a certain URL (with input through the command line), and for one of the environments (not all), i get: AssertionError: expected 'about:blank' to include 'url'
Not sure why the getLocation() method returns 'about:blank'
Thank you for the information!
Please clarify whether the behavior you are referring to occurs when you open a child window. If there was an unsuccessful navigation attempt when the about:blank page was opened instead of the URL passed through an environment variable, I cannot be sure that it is the same issue. In this instance, please create a new GitHub issue and include a complete example that reproduces the problematic behavior.
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.
No updates yet. Once we get any results, we will post them in this thread.
Seeing the same issue with TestCafe 1.18.6 and Node 12.22.5 as well. Happens 100% of the time.
Hi @ayemel22,
I reproduced the author's issue, and I saw the same behavior as @VasilyStrelyaev described. Please share your case details.
Also, I recommend updating the node to version 14 or 16 because v12 is not supported anymore.
facing same issue, is there any update on this issue yet. In my case, it is launching a AD authentication page, so it is not about:blank but same behaviour is observed and the window is closing immediately after it's open on click.
No updates yet. Once we get any results, we will post them in this thread.
still no updates?
There are no updates. We'll update this thread once we have any news.
Unfortunately, this issue is happening for a really long time. Is it possible to prioritize it somehow?
Hi @marinamarin91,
I increased the priority of the issue. However, I cannot give you a precise date because it may be misleading.
Hi, any updates on this issue? We have updated TestCafe to version 1.18.6 and have this problem. The window is closing immediately after it's open on click. Can someone help? Or anyone has "work around" we can try? Thanks a lot!
Hi @MeScofield,
We don't have any updates yet. As a workaround, you can click twice:
await t.click(Selector('#myLink'));
await t.click(Selector('#myLink'));
A new window will open correctly after the second action.
@Aleksey28 , thanks for the workaround, it worked for me.
This issue still exists
Hi @pranabkdas85,
I double-checked the initial example from this thread and didn't reproduce the issue. Perhaps, this behavior is affected by other aspects in your case. Please create a new issue and share your simple sample there.
having this problem too. I'm on Windows 10. External who uses MacOS don't have this issue.
and the click twice work arround doesn't work for me.
@olivier-voutat The original issue was fixed and closed. If you still encounter a similar issue, please create a separated thread using the following link: https://github.com/DevExpress/testcafe/issues/new?assignees=&labels=TYPE%3A+bug&template=bug_report.yaml