Sauce 服务
WebdriverIO服务,提供与Sauce Labs更好的集成。此服务可用于:
- Sauce Labs虚拟机云(桌面网页/模拟器/仿真器)
- Sauce Labs真机云(iOS和Android)
它可以更新任务元数据('name'*、'passed'、'tags'、'public'、'build'、'custom-data'),并根据需要运行Sauce Connect。
此服务还能为您做什么:
- 默认情况下,Sauce服务会在任务开始时 更新任务的"name"。这将使您能够在任何给定时间点更新名称。
- 您可以定义一个
setJobName参数,并根据您的capabilities、选项和套件标题自定义任务名称 - Sauce服务还会将失败测试的错误堆栈推送到Sauce Labs的命令选项卡
- 它允许您自动配置和启动Sauce Connect
- 它会在您的命令列表中设置上下文点,以识别在哪个测试中执行了哪些命令
安装
最简单的方法是通过以下方式将@wdio/sauce-service作为devDependency保留在您的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', // 或 'eu'
services: [
['sauce', {
sauceConnect: true,
sauceConnectOpts: {
// ...
}
}]
],
// ...
};
如果您想使用现有的Sauce Connect隧道,您只需要提供一个tunnelName。如果您使用的是共享隧道,并且您不是创建隧道的用户,则必须识别创建隧道的Sauce Labs用户,以便在测试中使用它。在capabilities中包含tunnelOwner,如下所示:
- Tunnel Name
- Tunnel Owner
export const config = {
// ...
{
browserName: 'chrome',
platformName: 'Windows 10',
browserVersion: 'latest',
// Sauce options can be found here https://docs.saucelabs.com/dev/test-configuration-options/
'sauce:options': {
tunnelName: '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://docs.saucelabs.com/dev/test-configuration-options/
'sauce:options': {
tunnelName: 'TunnelName',
tunnelOwner: '<username of owner>,
// Example options
build: 'your-build-name',
screenResolution: '1600x1200',
// ...
},
},
// ...
};