4

I am working on a TestCafe proof of concept. I have a few tests working in one test environment. I need a way to run the same tests in up to 3 different test environments that have different URLs. Is there a best practice for this scenario?

Alex Skorkin
  • 4,264
  • 3
  • 25
  • 47
bdrobiso1
  • 71
  • 2

2 Answers2

3

A solution is to add custom options on the testcafe command-line like for example : --env=uat.

Use minimist to read all custom options that you have added to the TestCafe command-line and export a config object like this:

import * as minimist from 'minimist';

const args = minimist(process.argv.slice(2));

// get the options --env=xxx --user=yyy from the command line
export const config = {
  env: args.env,
  user: args.user,
};

Then import that config object wherever you need it in the test code.

see How do I work with configuration files and environment variables? for more details.

hdorgeval
  • 3,000
  • 8
  • 17
0

In v1.20.0 and later, TestCafe offers a way to specify the baseUrl in the test run setup:

You can use this approach along with environment variables or custom command line arguments to determine what url should be assigned to the baseUrl option. Alternatively, you can have a different configuration file for each test run setup and switch between these files using the --config-file option.

Helen Dikareva
  • 1,026
  • 6
  • 7