在每个环境中使用不同的 URL 运行相同的 Testcafe 测试 [英] Run Same Testcafe tests with different URLs per environment

查看:18
本文介绍了在每个环境中使用不同的 URL 运行相同的 Testcafe 测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个 TestCafe 概念验证.我在一个测试环境中进行了一些测试.我需要一种在最多 3 个具有不同 URL 的不同测试环境中运行相同测试的方法.这种情况有最佳实践吗?

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?

推荐答案

解决方案是在 testcafe 命令行中添加自定义选项,例如:--env=uat.

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

使用 minimist 读取您添加到 TestCafe 命令行的所有自定义选项,并像这样导出配置对象:

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,
};

然后将该 config 对象导入到测试代码中您需要的任何位置.

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.

这篇关于在每个环境中使用不同的 URL 运行相同的 Testcafe 测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆