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

Testcafe fails when using t.navigateTo() in latest chromium based browsers. #8153

Closed
Ilie-c opened this issue Mar 1, 2024 · 2 comments
Closed
Labels
TYPE: bug The described behavior is considered as wrong (bug).

Comments

@Ilie-c
Copy link

Ilie-c commented Mar 1, 2024

What is your Scenario?

I am trying to create a test that contains an after each to clean the instance using t.navigateTo() or a test to go to an inexistent product in the swag labs testing site as a learning path.

The navigateTo() function will hang the test in chromium type browsers, forcing the test and runtime to fail.
If runned in firefox, the test will succeed without any issues.

What is the Current behavior?

Chromium browsers

Test run smoothly until it hits the t.navigateTo(url).
Testcafe navigates to the specified url however after that it hangs until the timeout is reached and it retries 2 more times, failing on all of them and the terminal returns:

\TestCafe> npm run test:firefox

> testcafephptravels@1.0.0 test:firefox
> testcafe edge ./tests -s takeOnFails=true

 Running tests in:
 - Microsoft Edge 122.0.0.0 / Windows 11

 checkout test
[percy] Percy is not running, disabling snapshots


 1/1 failed (6m 23s)
ERROR The Microsoft Edge 122.0.0.0 / Windows 11 browser disconnected. If you did not close the browser yourself, browser performance or network issues may be at fault.

Non-chromium browsers -> firefox

Test to run smoothly,
When it reaches the t.navigateTo(url) to perform it, see that it was succeeded and go to the next commands/method calls

What is the Expected behavior?

Test to run smoothly,
When it reaches the t.navigateTo(url) to perform it, see that it was succeeded and go to the next commands/method calls

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

https://www.saucedemo.com/

What is your TestCafe test code?


import { Selector } from 'testcafe';

//prettier-ignore
fixture.only `testcafe tests`
    .page`https://www.saucedemo.com/`
    .beforeEach(async(t) =>{
        await t.maximizeWindow();
    })
    .afterEach(async t =>{
        await t.navigateTo(`/inventory.html`) // or https://www.saucedemo.com/inventory.html
        await t.click(Selector('#react-burger-menu-btn'))
            .click(Selector('a#reset_sidebar_link'))
            .click(Selector('#shopping_cart_container'));
    });

test('login with valid credentials: username: standard_user ; password: secret_sauce', async t => {
    await t
        .typeText(Selector('#user-name'), 'standard_user')
        .typeText(Selector('#password'), 'secret_sauce')
        .click(Selector('#login-button'));
});

Your complete configuration file

{
"screenshots": {
"path":"./screenshots",
"pathPatternOnFails": "fails/${DATE}_${TIME}/${FIXTURE}.png"
}
}

Your complete test report

Screenshots

image

Steps to Reproduce

  1. run : testcafe chrome ./tests -s takeOnFails=true // can also be with edge

TestCafe version

3.5.0

Node.js version

v20.9.0

Command-line arguments

testcafe chrome ./tests -s takeOnFails=true

Browser name(s) and version(s)

Edge & Chrome 122.0.0.0 ; Firefox 123.0

Platform(s) and version(s)

Windows 11 22H2 build: 22621.3155

Other

No response

@Ilie-c Ilie-c added the TYPE: bug The described behavior is considered as wrong (bug). label Mar 1, 2024
@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Mar 1, 2024
@Bayheck
Copy link
Collaborator

Bayheck commented Mar 4, 2024

Hello, I managed to reproduce the issue.

It is similar to the following issue and is caused by 'service worker': #8123.

As a workaround, you can run your test as follows:

import { Selector, Role } from 'testcafe';

const role = Role('https://www.saucedemo.com/', async t => {
await t
.typeText(Selector('[data-test="username"]'), 'standard_user')
.typeText(Selector('#password'), 'secret_sauce')
.click(Selector('#login-button'))

}, { "preserveurl": true});

fixtureMy fixture
.pagehttps://www.saucedemo.com/
.beforeEach(async t => {
const idConnection = t.testRun.browserConnection.id;
const cdpClient = t.testRun.browserConnection.getNativeAutomation(idConnection)._client;
await cdpClient.Network.setBypassServiceWorker({bypass: true})
await t.useRole(role);
});

test('test1', async t => {
await t.navigateTo(/inventory.html) // or https://www.saucedemo.com/inventory.html
await t.click(Selector('#react-burger-menu-btn'))
.click(Selector('a#reset_sidebar_link'))
.click(Selector('#shopping_cart_container'));
});

@Bayheck Bayheck removed the STATE: Need response An issue that requires a response or attention from the team. label Mar 4, 2024
@Ilie-c
Copy link
Author

Ilie-c commented Mar 4, 2024

Hello @Bayheck ,

Thank you for the response. The workaround with cpdClient did indeed work.

@Ilie-c Ilie-c closed this as completed Mar 4, 2024
@need-response-app need-response-app 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 Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TYPE: bug The described behavior is considered as wrong (bug).
Projects
None yet
Development

No branches or pull requests

2 participants