Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TestCafe: Tests don't pass with headless mode

I'm building a React app and write my functional tests using TestCafe. Here is my test script:

"functional-tests": "testcafe chrome src/functional-tests/ --app 'yarn start'",

These tests pass. But if I try to run them in headless mode:

"functional-tests": "testcafe 'chrome:headless' src/functional-tests/ --app 'yarn start'",

They fail with the following error.

1) Cannot obtain information about the node because the specified
      selector does not match any node in the DOM tree.

If I run yarn start manually in a seperate terminal (not using the --app flag) the headless tests pass.

How can I get the headless tests to pass using the --app flag? I need to run the functional tests in a CI/CD script which is why I need one command to start the server and run the tests.

like image 235
J. Hesters Avatar asked Oct 21 '25 06:10

J. Hesters


1 Answers

I got it working by adding a delay to launch the app.

"functional-tests": "testcafe 'chrome:headless' src/functional-tests/ --app 'yarn start' --app-init-delay 4000",
like image 156
J. Hesters Avatar answered Oct 24 '25 18:10

J. Hesters



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!