Sauce 服务
WebdriverIO 服务,提供更好的 Sauce Labs 集成。此服务可用于
- Sauce Labs 虚拟机云(桌面 Web/模拟器)
- Sauce Labs 真机云(iOS 和 Android)
它可以更新作业元数据('name'、'passed'、'tags'、'public'、'build'、'custom-data')并在需要时运行 Sauce Connect。
此服务还能为您做什么
- 默认情况下,Sauce 服务会在作业开始时更新作业的“name”。这将使您能够随时更新名称。
- 您可以定义一个
setJobName
参数,并根据您的功能、选项和套件标题自定义作业名称。 - Sauce 服务还会将失败测试的错误堆栈推送到 Sauce Labs 命令选项卡。
- 它将允许您自动配置和启动Sauce Connect
- 它将在您的命令列表中设置上下文点,以识别哪些命令在哪个测试中执行。
安装
最简单的方法是将 @wdio/sauce-service
作为开发依赖项保存在您的 package.json
中,通过
npm install @wdio/sauce-service --save-dev
有关如何安装 WebdriverIO
的说明,请参见此处。
配置
要将此服务用于虚拟桌面/模拟器和真机云,您需要在 wdio.conf.js
文件中设置 user
和 key
。它将自动使用 Sauce Labs 运行您的集成测试。如果您在 Sauce Labs 上运行测试,则可以通过 region
属性指定您想要运行测试的区域。区域的可用简写为 us
(默认)和 eu
。这些区域用于 Sauce Labs VM 云和 Sauce Labs 真机云。如果您未提供区域,则默认为 us
。
如果您希望 WebdriverIO 自动启动Sauce Connect 隧道,您需要设置 sauceConnect: true
。如果您想将数据中心更改为 EU,请添加 region:'eu'
,因为 US 数据中心设置为默认值。
// wdio.conf.js
export const config = {
// ...
user: process.env.SAUCE_USERNAME,
key: process.env.SAUCE_ACCESS_KEY,
region: 'us', // or 'eu'
services: [
['sauce', {
sauceConnect: true,
sauceConnectOpts: {
// ...
}
}]
],
// ...
};
如果您想使用现有的 Sauce Connect 隧道,您只需要提供一个 tunnelIdentifier
,或者如果您正在使用父隧道,请在功能中包含 parentTunnel
,如下所示
- 隧道标识符
- 父隧道
export const config = {
// ...
{
browserName: 'chrome',
platformName: 'Windows 10',
browserVersion: 'latest',
// Sauce options can be found here https://wiki.saucelabs.com/display/DOCS/Test+Configuration+Options
'sauce:options': {
tunnelIdentifier: 'YourTunnelName',
// Example options
build: 'your-build-name',
screenResolution: '1600x1200',
// ...
},
},
// ...
};
export const config = {
// ...
{
browserName: 'chrome',
platformName: 'Windows 10',
browserVersion: 'latest',
// Sauce options can be found here https://wiki.saucelabs.com/display/DOCS/Test+Configuration+Options
'sauce:options': {
tunnelIdentifier: 'ParentTunnelName',
parentTunnel: '<username of parent>,
// Example options
build: 'your-build-name',
screenResolution: '1600x1200',
// ...
},
},
// ...
};
## Sauce Service Options
To authorize the Sauce Labs service your config needs to contain a [`user`](https://webdriverio.node.org.cn/docs/options#user) and [`key`](https://webdriverio.node.org.cn/docs/options#key) option.
### maxErrorStackLength
This service will automatically push the error stack to Sauce Labs when a test fails. By default, it will only push the first 5 lines, but if needed this can be changed. Be aware that more lines will result in more WebDriver calls which might slow down the execution.
Type: `number`<br />
Default: `5`
### sauceConnect
If `true` it runs Sauce Connect and opens a secure connection between a Sauce Labs virtual machine running your browser tests.
Type: `Boolean`<br />
Default: `false`
### sauceConnectOpts
Apply Sauce Connect options (e.g. to change port number or logFile settings). See [this list](https://wiki.saucelabs.com/display/DOCS/Sauce+Connect+Proxy+Command-Line+Quick+Reference+Guide) for more information. Per default, the service disables SC proxy auto-detection via `noAutodetect`` as this can be unreliable for some machines.
NOTE: When specifying the options the `--` should be omitted. It can also be turned into camelCase (e.g. `shared-tunnel` or `sharedTunnel`).
Type: `Object`<br />
Default: `{ noAutodetect: true }`
### uploadLogs
If `true` this option uploads all WebdriverIO log files to the Sauce Labs platform for further inspection. Make sure you have [`outputDir`](https://webdriverio.node.org.cn/docs/options#outputdir) set in your wdio config to write logs into files, otherwise data will be streamed to stdout and can't get uploaded.
Type: `Boolean`<br />
Default: `true`
### setJobName
Allows users to dynamically set the job name based on worker parameters such as WebdriverIO configuration, used capabilities and the original suite title.
Type: `Function`<br />
Default: `(config, capabilities, suiteTitle) => suiteTitle`
----
## Overriding generated name metadata
The service automatically generates a name for each test from the suite name, browser name and other information.
You can override this by providing a value for the `name` desired capability, but this will have the side effect of giving all tests the same name.
----
For more information on WebdriverIO see the [homepage](https://webdriverio.node.org.cn).