跳转到主要内容

Suite

Suite 是一组测试。Playwright Test 中的所有测试构成了以下层级结构:

  • 根套件(Root suite),每个 FullProject 都有一个对应的子套件。
    • 项目套件(Project suite)#1。项目中的每个测试文件都有一个对应的子套件。
    • 项目套件(Project suite)#2
    • < 更多项目套件 ... >

Reporter 在 reporter.onBegin() 方法中会接收到一个根套件。


方法

allTests

新增于: v1.10 suite.allTests

返回此套件及其所有后代套件中所有测试用例的列表,与 suite.tests 不同。

用法

suite.allTests();

返回


entries

新增于:v1.44 suite.entries

直接定义在此套件中的测试用例和套件。元素按照其声明顺序返回。你可以通过使用 testCase.typesuite.type 来区分不同的条目类型。

用法

suite.entries();

返回


project

新增于: v1.10 suite.project

该套件所属项目的配置;对于根套件,则为 void

用法

suite.project();

返回


titlePath

新增于: v1.10 suite.titlePath

返回从根套件到当前套件的标题列表。

用法

suite.titlePath();

返回


属性

location

新增于: v1.10 suite.location

套件在源代码中的定义位置。根套件和项目套件缺失此属性。

用法

suite.location

类型


parent

新增于: v1.10 suite.parent

父套件;根套件缺失此属性。

用法

suite.parent

类型


suites

新增于: v1.10 suite.suites

子套件。有关套件的层级结构,请参阅 Suite

用法

suite.suites

类型


tests

新增于: v1.10 suite.tests

套件中的测试用例。请注意,列表中仅包含直接定义在此套件中的测试用例。任何定义在嵌套 test.describe() 分组中的测试用例都列在子 suite.suites 中。

用法

suite.tests

类型


title

新增于: v1.10 suite.title

套件标题。

  • 对于根套件,此项为空。
  • 对于项目套件,此项为项目名称。
  • 对于文件套件,此项为文件路径。
  • 对于分组套件,此项为传给 test.describe() 的标题。

用法

suite.title

类型


type

新增于:v1.44 suite.type

返回套件的类型。套件的层级结构如下:root -> project -> file -> describe -> ...describe -> test

用法

suite.type

类型

  • "root" | "project" | "file" | "describe"