e2e-testingnuxt3.jstestcafe

How to recognize within application that i am within an testcafe e2e test


We are within a big project migration. Old pages written in php and tested with testcafe. New pages written with Nuxt and tested with playwright.

I need to know on nuxt pages if i am running an e2e test with testcafe. Dependant on the result i need to guide the user to old version of checkout instead of new version when clicking on a button.

Within the documentation or by googling around i cannot find any way to know within my application if i am currently within the testcafe tests.

Can anyone help?

I tried setting an env var for testcafe, but its not recognized by the nuxt application.

I tried working with a window object, like window._isTestcafe but also this does not work.

I found this thread: How can my application code know whether the app is being tested with testcafe? and tried the window['%hammerhead%'] which is also not working.

I know in Cypress there is the possibility to access window.Cypress within your application and access env vars from cypress. Is there maybe any equivalent for testcafe?


Solution

  • The answer is that window?.['%hammerhead%'] works. But i need to wait until onMounted in nuxt, because before on mounted the value ist not set.