running-webdriverio-tests

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Running WebdriverIO Tests

运行WebdriverIO测试

Main Command

主命令

bash
npx wdio
Config is in
wdio.conf.js
by default.
bash
npx wdio
默认配置文件为
wdio.conf.js

Duration

测试时长

Tests take 20 seconds to 5 minutes. Do not treat a slow test as a failure.
测试耗时在20秒到5分钟之间。不要将运行缓慢的测试视为失败。

Selecting Tests to Run

选择要运行的测试

By spec file

通过测试文件(spec file)

bash
undefined
bash
undefined

Single file

单个文件

npx wdio --spec=test/specs/home.js
npx wdio --spec=test/specs/home.js

Multiple files

多个文件

npx wdio --spec=test/specs/home.js --spec=test/specs/register.js
undefined
npx wdio --spec=test/specs/home.js --spec=test/specs/register.js
undefined

By suite

通过测试套件(suite)

Suite names are defined in the WebdriverIO config file under the
suites
property.
bash
npx wdio --suite=auth
套件名称在WebdriverIO配置文件的
suites
属性中定义。
bash
npx wdio --suite=auth

Excluding files

排除文件

bash
npx wdio --exclude=test/specs/home.js
Can be mixed with
--spec
or
--suite
.
bash
npx wdio --exclude=test/specs/home.js
可与
--spec
--suite
搭配使用。

Key CLI Options

关键CLI选项

OptionDescription
--spec
Run specific spec file(s) or wildcard
--suite
Run a named suite from wdio.conf.js
--exclude
Exclude spec file(s) from run
--logLevel
trace
,
debug
,
info
,
warn
,
error
,
silent
--bail
Stop after N failures (default: 0 = run all)
--maxInstances
Number of parallel browser instances (2–10)
--baseUrl
Override base URL for
browser.url()
calls
--repeat
Repeat specs/suites N times
选项描述
--spec
运行指定的测试文件或使用通配符
--suite
运行wdio.conf.js中定义的命名测试套件
--exclude
从运行中排除指定测试文件
--logLevel
日志级别:
trace
debug
info
warn
error
silent
--bail
出现N次失败后停止测试(默认值:0 = 运行全部测试)
--maxInstances
并行浏览器实例数量(2–10)
--baseUrl
覆盖
browser.url()
调用使用的基础URL
--repeat
重复运行测试文件/套件N次

Log Level

日志级别

  • Use
    --logLevel=trace
    when debugging (maximum output)
  • Use default (
    info
    ) when confirming tests pass (less noise)
bash
npx wdio --logLevel=trace --spec=test/specs/home.js
  • 调试时使用
    --logLevel=trace
    (输出最详细信息)
  • 确认测试通过时使用默认值(
    info
    ,减少冗余输出)
bash
npx wdio --logLevel=trace --spec=test/specs/home.js

Bail

失败停止

bash
npx wdio --bail=1
bash
npx wdio --bail=1

Max Instances

最大并行实例数

bash
npx wdio --maxInstances=3
bash
npx wdio --maxInstances=3

Base URL

基础URL

Changes the base server used with relative paths (e.g.,
browser.url('./homepage.html')
).
bash
npx wdio --baseUrl=https://example.com/
修改相对路径使用的基础服务器(例如,
browser.url('./homepage.html')
)。
bash
npx wdio --baseUrl=https://example.com/

Isolating Individual Tests (Mocha)

隔离单个测试(Mocha)

Edit the test file temporarily to add
.only
or
.skip
.
临时编辑测试文件,添加
.only
.skip

Run only specific tests

仅运行特定测试

js
describe.only("Form Fields", function () { ... });
it.only("should submit form", function () { ... });
js
describe.only("Form Fields", function () { ... });
it.only("should submit form", function () { ... });

Skip specific tests

跳过特定测试

js
it.skip("should return -1 unless present", function () { ... });
Remember to revert
.only
/
.skip
changes after debugging.
js
it.skip("should return -1 unless present", function () { ... });
调试完成后,请记得还原
.only
/
.skip
的修改。