You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WebdriverIO如何先运行单个测试再并行执行其余测试?

WebdriverIO 实现先单独运行指定测试文件再并行执行其余文件的方案

有两种可行的实现方式,具体如下:

方法一:命令行组合执行

直接通过终端命令串联两个执行步骤,先单独跑目标文件,再并行执行剩余文件:

  1. 单独运行a.test.ts:
wdio run ./wdio.conf.ts --spec ./path/to/a.test.ts
  1. 并行执行b.test.ts、c.test.ts、d.test.ts:
wdio run ./wdio.conf.ts --spec ./path/to/b.test.ts ./path/to/c.test.ts ./path/to/d.test.ts

可以将两个命令用&&串联,一次性完成整个流程:

wdio run ./wdio.conf.ts --spec ./path/to/a.test.ts && wdio run ./wdio.conf.ts --spec ./path/to/b.test.ts ./path/to/c.test.ts ./path/to/d.test.ts

注意:需要确保你的wdio.conf.ts配置文件中,maxInstances参数设置为3或更高,这样三个文件才能真正并行执行。

方法二:Node.js脚本封装执行逻辑

如果需要更灵活的流程控制,可以写一个自定义脚本调用WebdriverIO的CLI API,按顺序执行测试:

创建run-tests.js文件,内容如下:

const { run } = require('@wdio/cli');

async function runTests() {
    // 先执行单独的测试文件
    console.log('开始执行a.test.ts...');
    await run({
        configPath: './wdio.conf.ts',
        specs: ['./path/to/a.test.ts']
    });

    // 再并行执行剩余文件
    console.log('开始并行执行b.test.ts、c.test.ts、d.test.ts...');
    await run({
        configPath: './wdio.conf.ts',
        specs: ['./path/to/b.test.ts', './path/to/c.test.ts', './path/to/d.test.ts'],
        maxInstances: 3 // 临时指定并行实例数,确保三个文件同时运行
    });
}

runTests().catch(err => {
    console.error('测试执行失败:', err);
    process.exit(1);
});

在终端运行该脚本即可:

node run-tests.js

如果使用TypeScript,可将脚本改为.ts格式,用ts-node运行:

ts-node run-tests.ts

内容的提问来源于stack exchange,提问作者Abhisar Tripathi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 06:32:11