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.
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",