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.

3 Answers 3

9

Use testMatch in config:

testMatch:['sampleTest.spec.ts']

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

Sign up to request clarification or add additional context in comments.

1 Comment

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.ts
1

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.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.