Javascript 仅在Cypress中的特定环境中运行部分测试套件
我有一个测试套件,它在4种环境中运行:Javascript 仅在Cypress中的特定环境中运行部分测试套件,javascript,testing,automated-tests,cypress,Javascript,Testing,Automated Tests,Cypress,我有一个测试套件,它在4种环境中运行:local、staging、production,比如说custom使用env变量。我想让一些测试只在生产上运行,一些测试只在暂存上运行,如何标记特定的描述/test/test文件才能做到这一点?在Cypress项目的根目录中,创建Cypress.json并添加您的生产url。例如: { "baseUrl": `https://www.production.com`, } CYPRESS_BASE_URL=https://www.d
local
、staging
、production
,比如说custom
使用env
变量。我想让一些测试只在生产上运行,一些测试只在暂存上运行,如何标记特定的描述/test/test文件才能做到这一点?在Cypress项目的根目录中,创建Cypress.json
并添加您的生产url。例如:
{
"baseUrl": `https://www.production.com`,
}
CYPRESS_BASE_URL=https://www.development.com cypress run
现在,如果在运行测试时未传递任何环境变量,则测试将针对生产环境运行
您还可以设置要运行的不同baseUrl。例如:
{
"baseUrl": `https://www.production.com`,
}
CYPRESS_BASE_URL=https://www.development.com cypress run
然后,您可以在测试中检索baseUrl:
const isProd = Cypress.config().baseUrl === "https://www.production.com";
const isDev = Cypress.config().baseUrl === "https://www.development.com";
const isStaging = Cypress.config().baseUrl === "https://www.staging.com";
const isCustom = Cypress.config().baseUrl === "https://www.custom.com";
根据您的测试设置,这里有不同的方法来构造它。根据上述变量向测试传递skip
参数,或者设置测试运行程序以按环境跳过/运行整批测试:
function runTests() {
if (isDev) {
runDevTests()
}
if (isStaging) {
runStagingTests()
}
if (isProd) {
runStagingTests()
}
if (isCustom) {
runCustomTests()
}
}