我正在研究TestCafe的概念证明。我在一个测试环境中有一些测试。我需要一种方法,以在最多3个具有不同URL的不同测试环境中运行相同的测试。这种情况下有最佳实践吗?
一种解决方案是在testcafe命令行上添加自定义选项,例如:--env=uat
。
使用minimist
读取已添加到TestCafe命令行的所有自定义选项,并像这样导出配置对象:
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,
};
然后将您需要的config
对象导入测试代码中。
请参阅How do I work with configuration files and environment variables?了解更多详细信息。