如何传入自定义参数以在特定环境中运行测试

问题描述

我正在使用-.testcaferc.json文件运行测试,而我正在运行的命令为:node node_modules/testcafe/bin/testcafe

我想传递一个附加参数,以便在不同的环境上运行不同的测试。当我尝试在命令node node_modules/testcafe/bin/testcafe production添加该参数时,由于它将它们视为测试,因此我无法使用它。

请让我知道我该如何处理。

解决方法

在这种情况下,您可以使用环境变量。

设置环境变量

// Enviroment variable set is platform specific
// See https://devexpress.github.io/testcafe/documentation/recipes/configuration/access-environment-variables-in-tests.html#set-environment-variables

export production=true

testcafe chrome test.js

并在测试中使用它

fixture ('Fixture');

test('test',async t => {
   console.log(process.env.production);
});