
- WebdriverIO 教程
- WebdriverIO - 主页
- WebdriverIO - 简介
- WebdriverIO - 先决条件
- WebdriverIO - 架构
- WebdriverIO - NodeJS 入门
- WebdriverIO - NPM 的安装
- WebdriverIO - VS 代码安装
- WebdriverIO - Package.json
- WebdriverIO - 摩卡安装
- Selenium 独立服务器安装
- WebdriverIO - 配置文件生成
- WebdriverIO - VS Code 智能感知
- WebdriverIO - Wdio.conf.js 文件
- WebdriverIO - Xpath 定位器
- WebdriverIO - CSS 定位器
- WebdriverIO - 链接文本定位器
- WebdriverIO - ID 定位器
- WebdriverIO - 标签名称定位器
- WebdriverIO - 类名定位器
- WebdriverIO - 名称定位器
- Expect 断言声明
- WebdriverIO - 快乐路径流
- WebdriverIO - 通用浏览器命令
- WebdriverIO - 处理浏览器大小
- WebdriverIO - 浏览器导航命令
- 处理复选框和下拉菜单
- WebdriverIO - 鼠标操作
- 处理子窗口/弹出窗口
- WebdriverIO - 隐藏元素
- WebdriverIO - 框架
- WebdriverIO - 拖放
- WebdriverIO - 双击
- WebdriverIO - Cookie
- WebdriverIO - 处理单选按钮
- webelements 上的 Chai 断言
- WebdriverIO - 多个窗口/选项卡
- WebdriverIO - 滚动操作
- WebdriverIO - 警报
- WebdriverIO - 调试代码
- WebdriverIO - 捕获屏幕截图
- WebdriverIO - JavaScript 执行器
- WebdriverIO - 等待
- WebdriverIO - 并行运行测试
- WebdriverIO - 数据驱动测试
- 从命令行参数运行测试
- 使用 Mocha 选项执行测试
- 从 Allure 生成 HTML 报告
- WebdriverIO 有用资源
- WebdriverIO - 快速指南
- WebdriverIO - 有用的资源
- WebdriverIO - 讨论
从命令行参数运行测试
我们可以使用命令行参数来控制运行测试。让我们看一个场景,WebdriverIO 项目的 spec 文件夹中有四个测试文件。
您的计算机上将出现以下屏幕 -

假设我们只想使用命令行参数触发文件 testcase1.js 和 testcase2.js。为此,我们必须在配置文件 wdio.conf.js 文件中添加一个名为 suites 的参数。
有关如何创建配置文件的详细信息将在标题为 Wdio.conf.js 文件的章节和标题为配置文件生成的章节中详细讨论。
让我们假设文件 testcase1.js 和 testcase2.js 属于名为 group1 的套件,文件 testcase3.js 和 testcase4.js 属于名为 group2 的套件。我们需要将此信息添加到 suite 参数下的 wdio.conf.js 文件中,如下所示。
suites: { group1: ['test/specs/testcase1.js', 'test/specs/testcase2.js'], group2: ['test/specs/testcase3.js', 'test/specs/testcase4.js'] },
您的计算机上将出现以下屏幕 -

要触发属于 group1 的测试文件 testcase1.js 和 testcase2.js,我们必须运行下面给出的命令 -
npx wdio run wdio.conf.js --suite group1
您的计算机上将出现以下屏幕 -

命令执行成功后,我们看到只有specs文件夹下的testcase1.js和testcase2.js两个测试文件被触发执行。
假设我们只想使用命令行参数触发文件 testcase3.js。要仅触发测试文件 testcase3.js,我们必须运行以下命令 -
npx wdio run wdio.conf.js --spec test/specs/testcase3.js
您的计算机上将出现以下屏幕 -

命令执行成功后,我们看到只有specs文件夹下的测试文件testcase3.js被触发执行。
此外,如果我们想触发多个测试文件 testcase3.js 和 testcase4.js,命令应如下 -
npx wdio run wdio.conf.js --spec test/specs/testcase3.js, test/specs/testcase4.js
假设我们只想从执行中排除文件 testcase4.js。为此,我们必须在配置文件 wdio.conf.js 文件中的排除参数下添加要排除的文件的相对路径,如下所示。
exclude: [ // 'path/to/excluded/files' 'test/specs/testcase4.js' ],
您的计算机上将出现以下屏幕 -

然后,我们必须运行以下命令 -
npx wdio run wdio.conf.js
您的计算机上将出现以下屏幕 -

命令执行成功后,我们可以看到specs文件夹下的测试文件testcase4.js已被排除在执行之外。