hypertest-cloud / hypertest

Plug-and-play library that distributes tests in the cloud to cut runtime to just your slowest test, ensuring cost-effectiveness.
https://hypertest.cloud
1 stars 0 forks source link

Research Playwright API How to run single test #5

Closed marcinlesek closed 6 months ago

marcinlesek commented 6 months ago

Playwright allow us to run specific test files (less useful for us):

npx playwright test tests/file.ts

Run specific test from line 42 in file:

npx playwright test file.ts:42

What is more interesting here, we can run tests based on title searching with regular expression:

npx playwright test -g "test title 123"

The most interesting thing, is option to list all the tests, but not run them (useful for creating test lists scope?):

npx playwright test --list

Programatically, we can add .only to test function to run only that test:

test.only('my single test', async ({ page }) => {
  // Run only focused tests in the entire project.
});

Next thing is option to tag tests (directly in test title or indirectly, in details object):

import { test, expect } from '@playwright/test';

test('my test title 1', {
  tag: '@fast',
}, async ({ page }) => {
  // ...
});

test('my test title 2 @slow', async ({ page }) => {
  // ...
});

It allows also to add array of tags to tag property and run them with -g flag (grep):

npx playwright test --grep @fast