Skip to content

Cannot close the window because it does not have a parent. The parent window was closed or you are attempting to close the root browser window where tests were launched. #5597

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

Closed
hinok opened this issue Oct 1, 2020 · 2 comments
Labels
SYSTEM: window management TYPE: bug The described behavior is considered as wrong (bug).
Milestone

Comments

@hinok
Copy link

hinok commented Oct 1, 2020

What is your Test Scenario?

I would like to open a new window with a different application under different url. Sign in there and do some actions then return to the parent window to continue my test.

As an example the code below uses github as a platform to sign in.

What is the Current behavior?

The test fails because the window cannot be closed.

1) Cannot close the window because it does not have a parent. The parent window was closed or
      you are attempting to close the root browser window where tests were launched.

What is the Expected behavior?

The test should succeed and close the recently opened window.

What is your web application and your TestCafe test code?

Your complete test code (or attach your test files):
import { Selector, t } from 'testcafe';

const GITHUB_LOGIN = 'YOUR GITHUB LOGIN';
const GITHUB_PASSWORD = 'YOUR GITHUB PASSWORD';

export const resize = () => t.resizeWindow(1366, 700);

const getWindowUrl = () => t.eval(() => document.documentURI) as Promise<string>;

async function openAsNewWindow(windowUrl: string) {
  const parentUrl = await getWindowUrl();

  const childWindow = await t.openWindow(windowUrl);
  const childUrl = await getWindowUrl();

  await t.expect(childUrl).eql(windowUrl);

  return async () => {
    await t.closeWindow(childWindow);
    await t.expect(getWindowUrl()).eql(parentUrl);
  };
}

fixture('New window')
  .page('https://github.com/join?source=login')
  .beforeEach(resize);

test.only('should open a new window', async () => {
  await t.typeText(Selector('input[type="text"][name="user[login]"]'), 'TestCafe');

  const closeWindow = await openAsNewWindow('https://github.com/login');

  await t
    .typeText(Selector('input[type="text"][name="login"]'), GITHUB_LOGIN)
    .typeText(Selector('input[type="password"][name="password"]'), GITHUB_PASSWORD)
    .click(Selector('input[type="submit"][value="Sign in"]'));

  await closeWindow();

  await t.click(Selector('input[type="submit"][value="Sign in"]'));
});
Your complete test report:
15:32 $ npm run test

> e2e@1.0.0 test /Users/john/Desktop/Dev/myApp/e2e
> npm run clean && npm run env && testcafe chrome src -S -s screenshots


> e2e@1.0.0 clean /Users/john/Desktop/Dev/myApp/e2e
> rm -rf ./screenshots && mkdir screenshots


> e2e@1.0.0 env /Users/john/Desktop/Dev/myApp/e2e
> rm -rf ./.env && cp ./.env.dev ./.env

 Running tests in:
 - Chrome 85.0.4183.121 / macOS 10.14.6

New window
 ✖ should open a new window
  (screenshots:
 /Users/john/Desktop/Dev/myApp/e2e/screenshots/2020-10-01_15-32-55/test-1/Chrome_85.0.4183.121_macOS_10.14.6/errors/1.png)

   1) Cannot close the window because it does not have a parent. The parent window was closed or
      you are attempting to close the root browser window where tests were launched.

      Browser: Chrome 85.0.4183.121 / macOS 10.14.6
      Screenshot:

   /Users/john/Desktop/Dev/myApp/e2e/screenshots/2020-10-01_15-32-55/test-1/Chrome_85.0.4183.121_macOS_10.14.6/errors/1.png

         19 |    const pageWindowUrl = await getWindowUrl();
         20 |
         21 |    await t.expect(pageWindowUrl).eql(loginUrl);
         22 |
         23 |    return async () => {
       > 24 |      await t.closeWindow(pageWindow);
         25 |
         26 |      const currentMainWindowUrl = await getWindowUrl();
         27 |      await t.expect(currentMainWindowUrl).eql(mainWindowUrl);
         28 |    };
         29 |  }

         at PageObject.<anonymous>

   (/Users/john/Desktop/Dev/myApp/e2e/src/PageObject.ts:24:15)
         at <anonymous>

   (/Users/john/Desktop/Dev/myApp/e2e/src/PageObject.ts:7:71)
         at __awaiter

   (/Users/john/Desktop/Dev/myApp/e2e/src/PageObject.ts:3:12)
         at <anonymous>

   (/Users/john/Desktop/Dev/myApp/e2e/src/PageObject.ts:23:23)
         at Object.<anonymous>

   (/Users/john/Desktop/Dev/myApp/e2e/src/myTest.spec.ts:47:9)
         at fulfilled
      (/Users/john/Desktop/Dev/myApp/e2e/src/myTest.spec.ts:4:58)



 1/1 failed (34s)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! e2e@1.0.0 test: `npm run clean && npm run env && testcafe chrome src -S -s screenshots`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the e2e@1.0.0 test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/john/.npm/_logs/2020-10-01T13_33_33_023Z-debug.log

Steps to Reproduce:

  1. Use your own login / password to be able to login to github in the test.

The problem doesn't occur if a form is not submitted in the freshly opened window.
Is there anything specific that could break TestCafe window management mechanism?

Your Environment details:

  • testcafe version: 1.9.3
  • node.js version: v12.18.3
  • command-line arguments: testcafe chrome src -S -s screenshots
  • browser name and version: Chrome 85.0.4183.121
  • platform and version: macOS 10.14.6
  • other: n/a
@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Oct 1, 2020
@AlexKamaev
Copy link
Contributor

Hello. Thank you for your input. I was able to reproduce the issue.

I examined our code, and it looks like your assumption is correct. The issue occurs only after the form is submitted in the child window. We'll try to fix the issue in the near future.

@need-response-app need-response-app bot removed the STATE: Need response An issue that requires a response or attention from the team. label Oct 2, 2020
@AlexKamaev AlexKamaev added this to the Planned milestone Oct 2, 2020
@AlexKamaev AlexKamaev added TYPE: bug The described behavior is considered as wrong (bug). SYSTEM: window management labels Oct 2, 2020
AlexKamaev added a commit to AlexKamaev/testcafe that referenced this issue Oct 8, 2020
AndreyBelym pushed a commit that referenced this issue Oct 20, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
* fix issues with window search (closes #5463, #5597)

* attempt to fix functional tests

* add missing tests

* try to fix FF tests

* try fix tests

* add more comments

* add fixes after review

* fix server tests
@hinok
Copy link
Author

hinok commented Nov 13, 2020

@Farfurix @AlexKamaev Many thanks guys for fixing the bug!

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Nov 13, 2020
@Farfurix Farfurix removed the STATE: Need response An issue that requires a response or attention from the team. label Nov 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
SYSTEM: window management TYPE: bug The described behavior is considered as wrong (bug).
Projects
None yet
Development

No branches or pull requests

3 participants