跳到主要內容

TestCase

TestCase 對應到每個 test() 在測試檔案中的呼叫。當單個 test() 在多個專案中運行或重複多次時,它將在相應專案的套件中擁有多個 TestCase 物件。


方法

ok

新增於:v1.10 testCase.ok

測試是否被認為運行良好。非 ok 測試會使測試運行失敗並返回非零退出代碼。

用法

testCase.ok();

返回


結果

新增於:v1.10 testCase.outcome

此測試的測試結果。請注意,結果與 testResult.status 不同

  • 預期會失敗且實際失敗的測試是 'expected'
  • 在第二次重試中通過的測試是 'flaky'

用法

testCase.outcome();

返回

  • "skipped" | "expected" | "unexpected" | "flaky"#

titlePath

新增於:v1.10 testCase.titlePath

返回從根目錄到此測試的標題列表。

用法

testCase.titlePath();

返回


屬性

annotations

新增於:v1.10 testCase.annotations

適用於目前測試的註解列表。包括

註解在測試執行期間可通過 testInfo.annotations 取得。

了解更多關於 測試註解

用法

testCase.annotations

類型


expectedStatus

新增於:v1.10 testCase.expectedStatus

預期測試狀態。

另請參閱 testResult.status 以獲取實際狀態。

用法

testCase.expectedStatus

類型

  • "passed" | "failed" | "timedOut" | "skipped" | "interrupted"

id

新增於:v1.25 testCase.id

基於測試檔案名、測試標題和專案名稱計算的測試 ID。該 ID 在 Playwright 會話中是唯一的。

用法

testCase.id

類型


location

新增於:v1.10 testCase.location

測試定義在原始碼中的位置。

用法

testCase.location

類型


parent

新增於:v1.10 testCase.parent

此測試案例所屬的套件。

用法

testCase.parent

類型


repeatEachIndex

新增於:v1.10 testCase.repeatEachIndex

在“repeat each”模式下運行時,包含重複索引。此模式通過將 --repeat-each 傳遞到 命令列 來啟用。

用法

testCase.repeatEachIndex

類型


results

新增於:v1.10 testCase.results

此測試每次運行的結果。

用法

testCase.results

類型


retries

新增於:v1.10 testCase.retries

配置中給予此測試的最大重試次數。

了解更多關於 測試重試

用法

testCase.retries

類型


tags

新增於:v1.42 testCase.tags

通過 test()test.describe() 在測試或套件上定義的標籤列表,以及從測試和套件標題中提取的 @-tokens。

了解更多關於 測試標籤

用法

testCase.tags

類型


timeout

新增於:v1.10 testCase.timeout

給予測試的超時時間。受 testConfig.timeout, testProject.timeout, test.setTimeout(), test.slow()testInfo.setTimeout() 的影響。

用法

testCase.timeout

類型


title

新增於:v1.10 testCase.title

傳遞給 test() 呼叫的測試標題。

用法

testCase.title

類型


type

新增於:v1.44 testCase.type

返回 "test"。用於在 suite.entries() 中檢測測試案例。

用法

testCase.type

類型

  • "test"