testcafe icon indicating copy to clipboard operation
testcafe copied to clipboard

New window immediately closes in Testcafe

Open RandomNonameDude opened this issue 3 years ago • 9 comments

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 (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.

RandomNonameDude avatar Mar 15 '22 14:03 RandomNonameDude

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).

VasilyStrelyaev avatar Mar 16 '22 12:03 VasilyStrelyaev

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'

Gjodim avatar Mar 23 '22 18:03 Gjodim

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.

VasilyStrelyaev avatar Mar 24 '22 07:03 VasilyStrelyaev

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.

andreeaminea avatar Apr 06 '22 09:04 andreeaminea

No updates yet. Once we get any results, we will post them in this thread.

testcafe-build-bot avatar Apr 07 '22 06:04 testcafe-build-bot

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

ayemel22 avatar Jun 02 '22 20:06 ayemel22

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.

Aleksey28 avatar Jun 03 '22 07:06 Aleksey28

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.

vikaschoudhary89 avatar Jul 14 '22 02:07 vikaschoudhary89

No updates yet. Once we get any results, we will post them in this thread.

github-actions[bot] avatar Jul 18 '22 06:07 github-actions[bot]

still no updates?

wjcheng1 avatar Nov 02 '22 23:11 wjcheng1

There are no updates. We'll update this thread once we have any news.

Aleksey28 avatar Nov 04 '22 07:11 Aleksey28

Unfortunately, this issue is happening for a really long time. Is it possible to prioritize it somehow?

marinamarin91 avatar Nov 04 '22 07:11 marinamarin91

Hi @marinamarin91,

I increased the priority of the issue. However, I cannot give you a precise date because it may be misleading.

Aleksey28 avatar Nov 07 '22 07:11 Aleksey28

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!

MeScofield avatar Dec 20 '22 21:12 MeScofield

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 avatar Dec 22 '22 07:12 Aleksey28

@Aleksey28 , thanks for the workaround, it worked for me.

MeScofield avatar Dec 22 '22 17:12 MeScofield

This issue still exists

pranabkdas85 avatar Apr 04 '23 07:04 pranabkdas85

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.

Aleksey28 avatar Apr 05 '23 07:04 Aleksey28

having this problem too. I'm on Windows 10. External who uses MacOS don't have this issue.

olivier-voutat avatar Apr 26 '23 14:04 olivier-voutat

and the click twice work arround doesn't work for me.

olivier-voutat avatar Apr 26 '23 14:04 olivier-voutat

@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

AlexKamaev avatar Apr 27 '23 07:04 AlexKamaev