Skip to content

Automation with Playwright

Playwright support is available starting with Squash TM 7.0.

Configuration of the execution environment

Playwright must be present in the execution environment.

It should be installed globally with the following command:

npm install -g playwright

The execution environment must be configured in such a way that tests can be launched using npx playwright test [folder]/[test_file] command. In most cases, the @playwright/test module needs also to be installed:

npm i -D @playwright/test

Test reference in Squash TM

In order to bind a Squash TM test case to a Playwright automated test, the content of the Automated test reference field of the Automation block of a test case must have the following format:

[repository]/[folder]#[test_file]#[test_case]
(The reference contains one or two # characters.)

with:

  • [repository]: Name of the Git repository.

  • [folder]: Path to the Playwright test file (.spec.ts or .spec.js file) from the root of the project. This parameter is optional.

  • [test_file]: Name of the Playwright test file or a regular expression to filter executable test files in the folder.

  • [test_case]: Optional regular expression to filter which test cases are executed from the test file(s). This expression is passed to the npx playwright test command --grep option. See Playwright documentation for details.

Regular expressions

[test_file] and [test_case] may both be regular expressions. These expressions are passed to the npx playwright test command and should therefore be properly escaped depending on the execution environment. Most often, you have just to quote them (see example 3 below).

Example 1: my_repo/test/folder#testfile.spec.ts#tnr runs, from testfile.spec.ts, all test cases containing a tnr string in their title, their tags or their test.describe title.

Example 2: my_repo/test#ihm_test runs all test cases from all .spec.ts files that start with ihm_test in the test folder of the Git repository.

Example 3: my_repo#"(login|profile)/.*"#"(view|edit)" runs all tests containing a view or an edit string from login or profile folder of the Git repository.

Determination of the result of the test case

If the [test_case] parameter is not specified or if it is a regular expression that selects more than one test case, the result of the Squash TM test case is calculated by taking into account the individual results of each executed test:

  • If at least one test has an Error status (in case of a technical issue), the status of the execution will be Blocked.
  • If at least one test fails functionally and none of the other ones has an Error status, the status of the execution will be Failed.
  • If all tests succeed, the status of the execution will be Success.

Nature of the exploitable Squash TM parameters

The exploitable Squash TM parameters will differ depending on whether you're using the Community/Premium or Ultimate version of Squash.

Here is a table showing the exploitable parameters (these parameters are transmitted as test parameters, see below, Squash TM does not generate global parameters):

Nature Key Community/Premium Ultimate
Name of the dataset DSNAME
Dataset parameter DS_[name]
Test case reference TC_REFERENCE
Test case internal UUID TC_UUID
Test case custom field TC_CUF_[code]
Iteration custom field IT_CUF_[code]
Campaign custom field CPG_CUF_[code]
Test suite custom field TS_CUF_[code]

Legend:

  • [code]: Value of the "Code" of a custom field
  • [name]: Parameter name as filled in Squash TM

As indicated, Squash TM adds a prefix to the code of the transmitted custom field. Make sure to take it into account.

Refer to the Squash TM documentation for more information about custom fields.

Parameters usage

It is possible, when running Playwright tests, to exploit parameters within it. A parameter can be a test parameter or a global parameter. Squash TM transmits only test parameters. Test parameters and global parameters can be used in the case of a launch from a CI/CD pipeline with the playwright/params action.

The parameters are available as environment variables and can be retrieved using the process.env.VAR syntax (see Playwright documentation for details).

Example

Below is an example of a Playwright test file and the corresponding Squash TM test case automation:

Playwright example

Playwright example

Adding parameters to the test launch command line

You can pass additional parameters to the npx playwright test command using the PLAYWRIGHT_EXTRA_OPTIONS environment variable. Here is an example of how to define an environment variable in Squash TM and associate it with the orchestrator.

Some parameters are already defined in the npx playwright test command used to launch tests:

export PW_TEST_HTML_REPORT_OPEN=never \
export PLAYWRIGHT_HTML_REPORT=playwright-report \
export PLAYWRIGHT_JUNIT_OUTPUT_NAME=pw_junit_report.xml \
npx playwright test {project}[/{directory}]/{specfile} \
  --grep="{grep}" \
  --reporter=html,junit \
  $PLAYWRIGHT_EXTRA_OPTIONS \

You must avoid passing, via the PLAYWRIGHT_EXTRA_OPTIONS variable, the command line parameters that conflict with the parameters already used, or the parameters that impact the generation or alter the path of the reports expected by the orchestrator (view the report list).

Non-support of the space character on Linux

Squash Orchestrator currently does not support the space character () in the PLAYWRIGHT_EXTRA_OPTIONS environment variable for tests executed in a Linux execution environment.

Supported versions

Squash has been validated with Playwright 1.41. Any recent version should work properly.