Skip to main content
Transform your testing process with: Real Device Features, Company-wide Licences, & Test Observability
No Result Found

Use setup & teardown in BrowserStack SDK

BrowserStack SDK for Playwright configures projects based on test specifications found in the test folder and platform combinations defined in the browserstack.yml file. With m test specs and n platform combinations, this results in the creation of m * n Playwright projects.

Using setup, teardown, testMatch, and testIgnore keys in playwrightConfigOptions, you can do the following:

These features are currently supported only on the BrowserStack Node SDK version (v1.31.16 or above).

  • Define execution order: Specify the order in which test specifications should be executed.

  • Run a spec on a specific platform: Choose a particular test spec and associate it with a specific platform combination defined in the YAML file. This allows you to target specific environments rather than running tests across all defined platform combinations. These enhancements provide you more flexibility and control over the execution of Playwright tests, catering to a wider range of your requirements.

Use the below features to optimize your test execution using Playwright SDK:

Set the setup and teardown keys under playwrightConfigOptions in the browserstack.yml file.

Specs that must run before any other specs in the platform should be defined under setup in the playwrightConfigOptions.

The teardown consists of the specs that you must run after the specs defined in setup and all dependent specs complete running.

Table 1: Properties, valid input types, and error message:

Dependencies Properties Type Valid inputs Optional
setup name String String No
  testMatch String/RegExp/Array String/RegExp/Array No
  teardown String String Yes
teardown name String String No
  testMatch String/RegExp/Array String/RegExp/Array No

Example of how you can set the setup and teardown properties in playwrightConfigOptions:

browserstack.yml
Copy icon Copy

setup and teardown are platform combination specific. They need to be defined in each platform combinations if specs dependency is required.

The above configuration translates to following in Playwright:

playwright.config
Copy icon Copy

Use the storageState in playwrightConfigOptionsin Playwright SDK:

browserstack.yml
Copy icon Copy

Set the testmatch and testIgnore properties under playwrightConfigOptions in the browserstack.yml file.

When you pass a regular expression in testmatch, the test runner executes only the files that match one of these patterns. Matching occurs against the absolute file path, treating strings as glob patterns.

Playwright, by default, searches for files that match the following glob pattern: **/*.@(spec|test).?(c|m)[jt]s?(x). This entails identifying JavaScript or TypeScript files with the suffixes .test or .spec such as sample-screen-credentials.spec.ts.

When you pass a regular expression in testIgnore, test files are not executed if they match one of these patterns. Matching involves assessing the absolute file path, and strings are treated as glob patterns.

For instance, the pattern ‘/test-assets/’ will exclude any files within the test-assets directory.

You can add the testMatch and testIgnore properties in playwrightConfigOptions. When added to a platform combination, only tests that match these properties run in the platform.

Table 2: Properties, valid input types, and error message:

Properties Valid input types Error message
testMatch and testIgnore string / RegExp / Array <string|RegExp> “Invalid value for testMatch key in the browserstack.yml file”
“Invalid value for testIgnore key in the yml file”

Example of how you can set the testMatch in playwrightConfigOptions in the browserstack.yml file:

browserstack.yml
Copy icon Copy

The above configuration translates to following in Playwright:

playwright.config
Copy icon Copy

Example of how you can set the testIgnore in playwrightConfigOptions in the browserstack.yml file:

browserstack.yml
Copy icon Copy

The above configuration translates to following in Playwright:

playwright.config
Copy icon Copy

Set testDir in the browserstack.yml file.

testDir is a directory that gets recursively scanned for test files where the configuration file is located.

Table 3: Properties, valid input types, and error message:

Properties Valid Input Types Error Message
testDir string “Invalid value for ‘testDir’ key in the yml file”
browserstack.yml
Copy icon Copy

The above configuration translates to following in Playwright:

playwright.config
Copy icon Copy

Need help?

If you have any queries, get in touch with us.

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback

Is this page helping you?

Yes
No

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback!

Talk to an Expert
Download Copy Check Circle