TestCase
TestCase
對應到每個 test() 在測試檔案中的呼叫。當單個 test() 在多個專案中運行或重複多次時,它將在相應專案的套件中擁有多個 TestCase
物件。
方法
ok
新增於:v1.10測試是否被認為運行良好。非 ok 測試會使測試運行失敗並返回非零退出代碼。
用法
testCase.ok();
返回
結果
新增於:v1.10此測試的測試結果。請注意,結果與 testResult.status 不同
- 預期會失敗且實際失敗的測試是
'expected'
。 - 在第二次重試中通過的測試是
'flaky'
。
用法
testCase.outcome();
返回
- "skipped" | "expected" | "unexpected" | "flaky"#
titlePath
新增於:v1.10返回從根目錄到此測試的標題列表。
用法
testCase.titlePath();
返回
屬性
annotations
新增於:v1.10適用於目前測試的註解列表。包括
- 通過 test() 和 test.describe() 在測試或套件上定義的註解;
- 由方法 test.skip(), test.fixme() 和 test.fail() 隱式添加的註解;
- 附加到 testInfo.annotations 在測試執行期間的註解。
註解在測試執行期間可通過 testInfo.annotations 取得。
了解更多關於 測試註解。
用法
testCase.annotations
類型
expectedStatus
新增於:v1.10預期測試狀態。
- 標記為 test.skip() 或 test.fixme() 的測試預期為
'skipped'
。 - 標記為 test.fail() 的測試預期為
'failed'
。 - 其他測試預期為
'passed'
。
另請參閱 testResult.status 以獲取實際狀態。
用法
testCase.expectedStatus
類型
- "passed" | "failed" | "timedOut" | "skipped" | "interrupted"
id
新增於:v1.25基於測試檔案名、測試標題和專案名稱計算的測試 ID。該 ID 在 Playwright 會話中是唯一的。
用法
testCase.id
類型
location
新增於:v1.10測試定義在原始碼中的位置。
用法
testCase.location
類型
parent
新增於:v1.10此測試案例所屬的套件。
用法
testCase.parent
類型
repeatEachIndex
新增於:v1.10在“repeat each”模式下運行時,包含重複索引。此模式通過將 --repeat-each
傳遞到 命令列 來啟用。
用法
testCase.repeatEachIndex
類型
results
新增於:v1.10此測試每次運行的結果。
用法
testCase.results
類型
retries
新增於:v1.10配置中給予此測試的最大重試次數。
了解更多關於 測試重試。
用法
testCase.retries
類型
tags
新增於:v1.42通過 test() 或 test.describe() 在測試或套件上定義的標籤列表,以及從測試和套件標題中提取的 @
-tokens。
了解更多關於 測試標籤。
用法
testCase.tags
類型
timeout
新增於:v1.10給予測試的超時時間。受 testConfig.timeout, testProject.timeout, test.setTimeout(), test.slow() 和 testInfo.setTimeout() 的影響。
用法
testCase.timeout
類型
title
新增於:v1.10傳遞給 test() 呼叫的測試標題。
用法
testCase.title
類型
type
新增於:v1.44返回 "test"。用於在 suite.entries() 中檢測測試案例。
用法
testCase.type
類型
- "test"