Skip to content
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

Test cafe fails to switch to new Window #8270

Closed
pranabkdas85 opened this issue Sep 3, 2024 · 6 comments
Closed

Test cafe fails to switch to new Window #8270

pranabkdas85 opened this issue Sep 3, 2024 · 6 comments
Assignees
Labels
HAS WORKAROUND TYPE: bug The described behavior is considered as wrong (bug).

Comments

@pranabkdas85
Copy link

pranabkdas85 commented Sep 3, 2024

What is your Scenario?

Login to System after entering credentails
Clicks on the url to open a new Window.
The new window gets closed the moment it opens.
Got a work Around from the nelow Id
#6926
Again clicked on the same link.
The Test cafe fails to switch to new window and the window keeps on loading

What is the Current behavior?

The new window keeps on loading. but if you do it manually , the new window gets opened in 5 seconds.

What is the Expected behavior?

It should switch to new window and get the url , the system should match with expected url

What is the public URL of the test page? (attach your complete example)

https://mybhtest.bhdts.com/

What is your TestCafe test code?

import {
Selector,
} from 'testcafe';

fixtureCenter Finder test cases.beforeEach(async t => {
await t.maximizeWindow();
await t.navigateTo('https://mybhtest.bhdts.com/');
await t.expect(Selector('section.hero').filterVisible().exists).ok('Landing Page has not been displayed.', { timeout: 60000 });
await t.wait(4000)
await t.click(Selector('div#onetrust-banner-sdk').find('button#onetrust-accept-btn-handler'));
await t.click(Selector('header.header-container').find('button>span').withText(/Log [Ii]n/));
await t.click(Selector('div#onetrust-banner-sdk').find('button#onetrust-accept-btn-handler'));
await t.typeText(Selector('bh-employer-search').find('#employer'), "Roche")
await t.expect(Selector('div[role="listbox"]').filterVisible().exists).ok({ timeout: 20000 })
await t.click(Selector('div[role="listbox"]').find('mat-option').withExactText("Roche"))
await t.click(Selector('bh-employer-search').find('button[type="submit"]'))
await t.typeText(Selector('bh-credentials').find('#username'), "testroche")
await t.typeText(Selector('bh-credentials').find('#current-password'), "User123BH")
await t.click(Selector('bh-credentials').find('button').withAttribute('type', 'submit'));

await t.expect(Selector('app-top-picks').find('.carousel')().filterVisible().exists).ok({ timeout: 60000 })

})

test(1648 Verify the content of 'Learn more' menu - BH center, async t => {
// Display Child Care benefits (including center)
const getUrl = await t.eval(() => window.location);

await t.expect(getUrl.href).eql(`https://mybhtest.bhdts.com/home`, { timeout: 120000 })
await t.expect(Selector('#dashboard_walkthrough').filterVisible().exists).ok({ timeout: 120000 })
// Find a card and open the 'Learn more' menu
await t.click(Selector('app-recommended-centers').find('button.header__button'))
const card: Selector = Selector('app-recommended-centers').find('div.centers__wrapper>app-scroll-wrapper  div.wrapper__container').find('app-center-card').find('.center-card__center-name').withText('Bright Horizons at Cranberry').parent('app-center-card').nth(0);

await t.click(card.find('app-link span').withExactText('Learn more'));
// Verify the content of the menu
await t.click(Selector('mat-sidenav#rightsidenav').find('section.sidenav__section').nth(0).find('section.tile-accreditation').withText(/Health and [Ss]afety is [Oo]ur [Tt]op [Pp]riority/).find('a').withExactText('Read more'));
await t.click(Selector('mat-sidenav#rightsidenav').find('section.sidenav__section').nth(0).find('section.tile-accreditation').withText(/Health and [Ss]afety is [Oo]ur [Tt]op [Pp]riority/).find('a').withExactText('Read more'));
await t.expect(getUrl.href).eql(`https://www.brighthorizons.com/health-safety`, 'Redirected to the wrong URL.')
await t.closeWindow();

}).meta('testType', 'common');

Your complete configuration file

No response

Your complete test report

  1. AssertionError: Redirected to the wrong URL.: expected 'https://mybhtest.bhdts.com/home' to deeply equal
    'https://www.brighthorizons.com/health-safety'

    • expected - actual

    -https://mybhtest.bhdts.com/home
    +https://www.brighthorizons.com/health-safety

Screenshots

No response

Steps to Reproduce

1.launch "https://mybhtest.bhdts.com/".
2.Click on the accept cookies
3.click on the Login In Button
4. Enter "Roche" in the employer field.
5. Select Roche from the drop Down.
6. Click on the Continue Button.
7. Enter ID as "testroche"
8. Password as "User123BH"
9. Click on Login Button.
10. Scroll to Recommended Bright Horizons centers
11. Click on the header to expand.
12. for center named Bright Horizons at Cranberry, click on learn More.
13. A new side scroll nav window opens.
14. Under "Health and safety is our top priority" click on Read more button.

TestCafe version

3.6.5

Node.js version

v20.12.0

Command-line arguments

npx testcafe chrome .\tests\Functional\centers.ts --disable-native-automation

Browser name(s) and version(s)

chrome

Platform(s) and version(s)

Windows

Other

If you are not getting the center as "Bright Horizons at Cranberry" ,
click on account >> profile
Under Zip Code : 16066
click on the save button.
Click on Life Stages.
check if early years is checked and after making chnages, click on save button.
click on Intrerest.
check if Caring Responsibility is checked and after making chnages, click on save button.

This enables the system rto get the recommended BH center in the System.

@pranabkdas85 pranabkdas85 added the TYPE: bug The described behavior is considered as wrong (bug). label Sep 3, 2024
@testcafe-need-response-bot testcafe-need-response-bot bot added the STATE: Need response An issue that requires a response or attention from the team. label Sep 3, 2024
@pranabkdas85 pranabkdas85 changed the title Test cafe fails yp switch to new Window Test cafe fails to switch to new Window Sep 3, 2024
@PavelMor25 PavelMor25 added the STATE: Issue accepted An issue has been reproduced. label Sep 9, 2024
Copy link

github-actions bot commented Sep 9, 2024

We appreciate you taking the time to share information about this issue. We reproduced the bug and added this ticket to our internal task queue. We'll update this thread once we have news.

@github-actions github-actions bot removed STATE: Need response An issue that requires a response or attention from the team. STATE: Issue accepted An issue has been reproduced. labels Sep 9, 2024
@Bayheck Bayheck self-assigned this Sep 20, 2024
@Bayheck
Copy link
Collaborator

Bayheck commented Sep 25, 2024

Hello, after taking a closer look at your example, I found that the workaround with two clicks actually works. Your test failed because of the incorrect way of checking a new window URL.

You call the following method before a new window is opened, and it stores the value of the parent URL:

const getUrl = await t.eval(() => window.location);

It won't change after a click on the 'Read more' anchor element.

Instead, call the following method after clicking the 'Read more' anchor element:

const getUrl = await t.eval(() => window.location);

Please try this and let us know your results.

I will close this issue for now.

@Bayheck Bayheck closed this as completed Sep 25, 2024
@testcafe-need-response-bot testcafe-need-response-bot bot added STATE: Need response An issue that requires a response or attention from the team. and removed STATE: Need response An issue that requires a response or attention from the team. labels Sep 25, 2024
@pranabkdas85
Copy link
Author

I did the same with the const getUrl = await t.eval(() => window.location); after clicking,

The system gives the error saying

Cannot switch to the window.

@testcafe-need-response-bot testcafe-need-response-bot bot added the STATE: Need response An issue that requires a response or attention from the team. label Sep 25, 2024
@Bayheck
Copy link
Collaborator

Bayheck commented Oct 2, 2024

Hello,

Could you please elaborate on the following points:

The system gives the error saying
Cannot switch to the window

What command line did you use to run your test?

Also, at what point did you get the error message?

Did you use the workaround with two consecutive clicks instead of just one?

Please share as much details as possible. Thank you in advance.

@Bayheck Bayheck removed the STATE: Need response An issue that requires a response or attention from the team. label Oct 2, 2024
@pranabkdas85
Copy link
Author

The exact code

==

import {
Selector,
} from 'testcafe';

fixtureCenter Finder test cases.beforeEach(async t => {
await t.maximizeWindow();
await t.navigateTo('https://mybhtest.bhdts.com/');
await t.expect(Selector('section.hero').filterVisible().exists).ok('Landing Page has not been displayed.', { timeout: 60000 });
await t.wait(4000)
await t.click(Selector('div#onetrust-banner-sdk').find('button#onetrust-accept-btn-handler'));
await t.click(Selector('header.header-container').find('button>span').withText(/Log [Ii]n/));
await t.click(Selector('div#onetrust-banner-sdk').find('button#onetrust-accept-btn-handler'));
await t.typeText(Selector('bh-employer-search').find('#employer'), "Roche")
await t.expect(Selector('div[role="listbox"]').filterVisible().exists).ok({ timeout: 20000 })
await t.click(Selector('div[role="listbox"]').find('mat-option').withExactText("Roche"))
await t.click(Selector('bh-employer-search').find('button[type="submit"]'))
await t.typeText(Selector('bh-credentials').find('#username'), "testroche")
await t.typeText(Selector('bh-credentials').find('#current-password'), "User123BH")
await t.click(Selector('bh-credentials').find('button').withAttribute('type', 'submit'));

await t.expect(Selector('app-top-picks').find('.carousel')().filterVisible().exists).ok({ timeout: 60000 })

})

test(1648 Verify the content of 'Learn more' menu - BH center, async t => {
// Display Child Care benefits (including center)
let getUrl = await t.eval(() => window.location);

await t.expect(getUrl.href).eql(`https://mybhtest.bhdts.com/home`, { timeout: 120000 })
await t.expect(Selector('#dashboard_walkthrough').filterVisible().exists).ok({ timeout: 120000 })
// Find a card and open the 'Learn more' menu
await t.click(Selector('app-recommended-centers').find('button.header__button'))
const card: Selector = Selector('app-recommended-centers').find('div.centers__wrapper>app-scroll-wrapper  div.wrapper__container').find('app-center-card').find('.center-card__center-name').withText('Bright Horizons at Cranberry').parent('app-center-card').nth(0);

await t.click(card.find('app-link span').withExactText('Learn more'));
// Verify the content of the menu
await t.click(Selector('mat-sidenav#rightsidenav').find('section.sidenav__section').nth(0).find('section.tile-accreditation').withText(/Health and [Ss]afety is [Oo]ur [Tt]op [Pp]riority/).find('a').withExactText('Read more'));
await t.click(Selector('mat-sidenav#rightsidenav').find('section.sidenav__section').nth(0).find('section.tile-accreditation').withText(/Health and [Ss]afety is [Oo]ur [Tt]op [Pp]riority/).find('a').withExactText('Read more'));
getUrl = await t.eval(() => window.location);
await t.expect(getUrl.href).eql(`https://www.brighthorizons.com/health-safety`, 'Redirected to the wrong URL.')
await t.closeWindow();

}).meta('testType', 'common');

We are getting error on Line number 38.

getUrl = await t.eval(() => window.location);

error = Cannot switch to the window.

@testcafe-need-response-bot testcafe-need-response-bot bot added the STATE: Need response An issue that requires a response or attention from the team. label Oct 8, 2024
@Bayheck
Copy link
Collaborator

Bayheck commented Oct 14, 2024

Hello,

I did not manage to reproduce the issue.

Please provide your complete test report when getting the:

error = Cannot switch to the window.

Could you also record a video of your test run showing the error?

@Bayheck Bayheck removed the STATE: Need response An issue that requires a response or attention from the team. label Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
HAS WORKAROUND TYPE: bug The described behavior is considered as wrong (bug).
Projects
None yet
Development

No branches or pull requests

3 participants