DevExpress / testcafe

A Node.js tool to automate end-to-end web testing.
https://testcafe.io
MIT License
9.82k stars 671 forks source link

Provide option to turn off chrome headless=new feature #8199

Closed Makavelic closed 4 months ago

Makavelic commented 4 months ago

What is your Scenario?

Testcafe 3.6.0 introduced a feature to use chrome's new headless feature: https://github.com/DevExpress/testcafe/pull/8151/files.

This unfortunately adds more instability where the browser is not always initialized properly. It's possible this only happens in non native mode but because of the several issues regarding iframes and native automation, I can't use that either right now.

This is the error:

BrowserConnectionError: Cannot establish one or more browser connections.

Note: My tests run with concurrency = 3 which might contribute to this problem (works fine in testcafe 3.5.0 though). The failure is intermittent though.

What are you suggesting?

Provide some sort of flag that I can add to testcaferc.json so I can use --headless instead of --headless=new.

What alternatives have you considered?

Upgrading chrome to the latest version (did not help)

Additional context

I'm not logging this as a bug since I have no way to create a reproducible project for this problem. And it is likely an issue with the chrome feature itself so it would be good to have a way to turn it off until things become more stable. If you want to instead default it to --headless but provide a flag to turn it on, that would also work.

PavelMor25 commented 4 months ago

Hello @Makavelic,

You can also run your tests in the old headless mode. To do this, append an additional command line flag --headless=old after the chrome alias when specifying browsers:

CLI:

testcafe 'chrome --headless=old' test.js

Test Runner API:

await runner
    .browsers('chrome --headless=old')
    .src('./tests/')
    .run();

Configuration-file:

{
    "browsers": "chrome --headless=old"
}

Please let us know your results.

Makavelic commented 4 months ago

Thanks for the info! Your example didn't work because we use the full path to binary but was able to get it to use the old headless mode by attaching an additional --headless. Here's some info for anyone else encountering the same problem:

chrome:\somepath\GoogleChrome-125.0.6422.77\chrome.exe:headless --headless

You can confirm whether it runs new headless or old headless with the following command:

const getUserAgent = ClientFunction(() => window.navigator.userAgent); const userAgent = await getUserAgent(); console.log(userAgent);

When using old headless mode userAgent will contain HeadlessChrome