跳至主要內容

Sauce Labs

所有命令僅在使用 Sauce Labs 擴充除錯功能時,在 Chrome 上支援。 您可以設定以下 Sauce 選項來啟用這些功能

{
browserName: 'Chrome',
browserVersion: 'latest',
platformName: 'Windows 10',
'sauce:options': {
extendedDebugging: true
}
}

getPageLogs

取得根據上次頁面載入的網頁特定日誌資訊。

Sauce Labs 命令。 更多詳細資訊可以在官方協定文件中找到。

用法
browser.getPageLogs(type)
參數
名稱類型詳細資訊
typestring日誌類型(例如 sauce:network、'sauce:performance')
範例
// Get Network Logs
console.log(browser.getPageLogs('sauce:network'));
/**
* outputs:
* [{
* "url": "https://app.saucelabs.com/dashboard",
* "statusCode": 200,
* "method": "GET",
* "requestHeaders": {
* ...
* },
* "responseHeaders": {
* ...
* },
* "timing": {
* ...
* }
* }, {,
* ...
* }]
*/
// Get Performance Logs (needs capturePerformance capability see: https://wiki.saucelabs.com/display/DOCS/Measure+Page+Load+Performance+Using+Test+Automation#MeasurePageLoadPerformanceUsingTestAutomation-EnableYourScript)
console.log(browser.getPageLogs('sauce:performance'));
/**
* outputs:
* {
* "speedIndex": 1472.023,
* "timeToFirstInteractive": 1243.214,
* "firstMeaningfulPaint": 892.643,
* ...
* }
*/
傳回
  • <object> log所需類型的日誌輸出(請參閱範例)

sauceThrottleNetwork

透過網路條件設定,您可以在各種網路連線上測試您的網站,包括 Edge、3G,甚至離線。 您可以節流資料輸送量,包括最大下載和上傳輸送量,並使用延遲操作來強制連接來回時間 (RTT) 的最短延遲。

Sauce Labs 命令。 更多詳細資訊可以在官方協定文件中找到。

用法
browser.sauceThrottleNetwork(condition)
參數
名稱類型詳細資訊
conditionstring, object要設定的網路條件(例如 'online'、'offline'、'GPRS'、'Regular 2G'、'Good 2G'、'Regular 3G'、'Good 3G'、'Regular 4G'、'DSL'、'Wifi')
範例
// predefined network condition
browser.sauceThrottleNetwork('offline')
// custom network condition
browser.sauceThrottleNetwork({
download: 1000,
upload: 500,
latency: 40'
})

throttleCPU

您可以在 DevTools 中節流 CPU,以了解您的頁面在該限制下的效能表現。

Sauce Labs 命令。 更多詳細資訊可以在官方協定文件中找到。

用法
browser.throttleCPU(rate)
參數
名稱類型詳細資訊
ratenumberCPU 應節流多少的比率。
範例
// throttle CPU and make it run 4x slower
browser.throttleCPU(4)
// reset CPU throttling
browser.throttleCPU(0)

interceptRequest

允許修改瀏覽器發出的任何要求。 您可以根據測試需要將這些要求加入黑名單、修改或重新導向。

Sauce Labs 命令。 更多詳細資訊可以在官方協定文件中找到。

用法
browser.interceptRequest(rule)
參數
名稱類型詳細資訊
ruleobject描述要求攔截的規則。
範例
// redirect a request
browser.interceptRequest({
url: 'https://saucelabs.com',
redirect: 'https://google.com'
})
// Blacklist requests to 3rd party vendors
browser.interceptRequest({
url: 'https://api.segment.io/v1/p',
error: 'Failed'
})
// Modify requests to REST API (Mock REST API response)
browser.interceptRequest({
url: 'http://sampleapp.appspot.com/api/todos',
response: {
headers: {
'x-custom-headers': 'foobar'
},
body: [{
title: 'My custom todo',
order: 1,
completed: false,
url: 'http://todo-backend-express.herokuapp.com/15727'
}]
}
})

assertPerformance

根據應用程式的效能基準進行判斷提示。

Sauce Labs 命令。 更多詳細資訊可以在官方協定文件中找到。

用法
browser.assertPerformance(name, metrics)
參數
名稱類型詳細資訊
namestring您建立基準時所用工作的名稱。
metrics
optional
string[]您要根據基準判斷提示的量測名稱。
範例
// test performance for a page
browser.url('https://webdriverio.dev.org.tw')
const hasRegression = browser.assertPerformance({
name: 'my performance test', // make sure that the name is also set in the sauce options in your capabilities
metrics: ['score', 'firstPaint']
})
傳回
  • <object> hasRegression包含結果以及結果相關量測的物件。

jankinessCheck

執行捲動測試,以評估應用程式的抖動程度。

Sauce Labs 命令。 更多詳細資訊可以在官方協定文件中找到。

用法
browser.jankinessCheck()
範例
// test performance for a page
browser.url('https://webdriverio.dev.org.tw')
browser.jankinessCheck()
傳回
  • <object> testResults包含分數以及測試期間頁面 UX 流暢度相關量測的物件。

mockRequest

模擬網路資源。

Sauce Labs 命令。 更多詳細資訊可以在官方協定文件中找到。

用法
browser.mockRequest(url, filterOptions)
參數
名稱類型詳細資訊
urlstring要比對模擬 URL 的 URL glob。
filterOptions
optional
object要模擬 URL 的其他篩選選項(例如標頭、方法)。
傳回
  • <object> mockId包含模擬資源 ID 的物件。

getMockCalls

接收符合模擬資源的要求相關要求資訊。

Sauce Labs 命令。 更多詳細資訊可以在官方協定文件中找到。

用法
browser.getMockCalls(mockId)
參數
名稱類型詳細資訊
mockIdString模擬的 ID
傳回
  • <object> requests要求資訊的清單。

clearMockCalls

清除模擬呼叫的清單。

Sauce Labs 命令。 更多詳細資訊可以在官方協定文件中找到。

用法
browser.clearMockCalls(mockId, restore)
參數
名稱類型詳細資訊
mockIdString模擬的 ID
restore
optional
boolean如果也應該還原模擬,請設定為 true。

respondMock

如果模擬符合特定資源,則回應。

Sauce Labs 命令。 更多詳細資訊可以在官方協定文件中找到。

用法
browser.respondMock(mockId, payload)
參數
名稱類型詳細資訊
mockIdString模擬的 ID
酬載 (payload)
optional
object關於模擬回應的資訊。

歡迎!請問有什麼可以幫您?

WebdriverIO AI Copilot