How to run particular file with Playwright?
Asked Answered
C

3

11

I have multiple test files in a specific folder with extension spec.ts. How I can run a particular file with Playwright?

Currently for configuration is set as the test folder and will run all files (tests) from it:

testDir: './smokeTests', 

I assume that there is some option in the config file, but I'm not sure which one.

Cranford answered 23/12, 2021 at 10:25 Comment(0)
B
11

Use testMatch in config:

testMatch:['sampleTest.spec.ts']

https://playwright.dev/docs/api/class-testconfig#test-config-test-match

Brandi answered 23/12, 2021 at 14:39 Comment(1)
Also, if you want to run it outside of your config and as part of your terminal command line you can use npx playwright test sampleTest.spec.tsGoss
L
0

This comment should be an answer for permanence:

npx playwright test path/to/your-specific-test.test.js

will run one file with the path path/to/your-specific-test.test.js.

Wildcards like * are allowed to run multiple files and directories can be used to run all tests in the directory.

Keep the default testMatch pattern in mind when naming test files.

Laws answered 4/4, 2024 at 17:9 Comment(0)
O
-1

Via Command Line:

If the file name is unique:

npx playwright test testFile.spec.ts

If the file name is not unique:

npx playwright test uniquePath/testFile.spec.ts

Via playwright.config file (using testMatch)

projects: [
    {
      name: "login",
      testMatch: /loginTests.spec.ts/,
    },
]

Note that this testMatch is within a dedicated playwright project, this way you avoid changing the global configuration.

Ormond answered 8/8, 2024 at 21:47 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.