我想在本机自动化模式下运行sampleTest.ts,在非本机自动化模式下运行sampleTest2.ts。
这是我在终端中运行的命令,但它以非本机模式运行两个测试文件:
node --max-http-header-size=9999999 node_modules/testcafe/bin/testcafe -c 2 'chrome --no-sandbox --disable-dev-shm-usage' testcafe/tests/sampleTest.ts testcafe/测试/sampleTest2.ts --disable-native-automation
是否可以通过一个命令在本机模式下运行sampleTest.ts并在非本机模式下运行sampleTest2.ts?
在单个命令中使用不同配置运行 TestCafe 测试(例如启用或禁用特定测试的本机自动化)并不简单。 TestCafe 的命令行界面 (CLI) 不提供对单个测试文件级别的这种选择性配置的直接支持。
您可以编写自定义 Node.js 脚本来为每个测试使用不同的设置来执行 TestCafe。
创建 Node.js 脚本(例如 runTests.js):
const createTestCafe = require('testcafe');
async function runTests() {
const testcafe = await createTestCafe();
try {
// Running the first test with native automation
await testcafe.createRunner()
.src(['testcafe/tests/sampleTest.ts'])
.browsers(['chrome --no-sandbox --disable-dev-shm-usage'])
.run();
// Running the second test without native automation
await testcafe.createRunner()
.src(['testcafe/tests/sampleTest2.ts'])
.browsers(['chrome --no-sandbox --disable-dev-shm-usage --disable-native-automation'])
.run();
} finally {
await testcafe.close();
}
}
runTests();
运行脚本:
node --max-http-header-size=9999999 runTests.js
此脚本使用 TestCafe API 创建两个单独的测试运行程序,每个测试运行程序都有自己的配置。
我希望这有帮助!