Sauce 服務
WebdriverIO 服務,可更好地整合至 Sauce Labs。此服務可用於
- Sauce Labs 虛擬機器雲端(桌面 Web/模擬器/模擬器)
- Sauce Labs 真實裝置雲端(iOS 和 Android)
它可以更新工作元數據(「名稱」*、「已通過」、「標籤」、「公開」、「建置」、「自訂數據」),並在需要時執行 Sauce Connect。
此服務還會為您做什麼
- 預設情況下,Sauce 服務會在工作開始時更新工作的「名稱」。這將讓您可以在任何給定時間點更新名稱。
- 您可以定義
setJobName
參數,並根據您的功能、選項和套件標題自訂工作名稱 - Sauce 服務也會將失敗測試的錯誤堆疊推送至 Sauce Labs 命令標籤
- 它允許您自動設定並啟動Sauce Connect
- 它會在您的命令清單中設定內容點,以識別哪些命令在哪些測試中執行
安裝
最簡單的方法是透過以下方式,將 @wdio/sauce-service
保留在 package.json
中作為 devDependency:
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
。如果您想要將資料中心變更為歐盟,請新增 region:'eu'
,因為美國資料中心設定為預設值。
// 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.dev.org.tw/docs/options#user) and [`key`](https://webdriverio.dev.org.tw/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.dev.org.tw/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.dev.org.tw).