Playwright provides a set of annotations that we can use to control the behavior of our tests. Annotations can be used on a single test or a group of tests and can be conditional, in which case they apply when the condition is truthy.
Here’s a more detailed look at these annotations.
test.skip()
This annotation is used when you want to skip a test. The test will not be run by Playwright. Skipping tests is not recommended and should only be used in unavoidable cases.
A test can be skipped under specific conditions, and you can optionally include a description if necessary.
test.skip()
can also take a predicate as its first argument. The test will be skipped if it returns true.
test.only()
This annotation is used to focus on a specific test. When there are focused tests, only these tests will run. This is useful when you want to run a single test or a group of tests exclusively.
test.fail()
This annotation is used to mark a test as failing. Playwright will run this test and ensure it does indeed fail. If the test does not fail, Playwright will complain. This is useful for documentation purposes to acknowledge that some functionality is broken until it is fixed.
We can label a test as failing based on certain conditions, and if needed, provide an optional description as well.
test.fail()
can also take a predicate as its first argument. The failing label will be applied if it returns true.
test.fixme()
Marks a test as fixme, with the intention to fix it. Test is immediately aborted when you call test.fixme().
We can label a test as fixme based on certain conditions, and if needed, provide an optional description too.
test.fixme()
can also take a predicate as its first argument. The fixme label will be applied if it returns true.
test.step()
It allows for the breakdown of individual actions within a test and grouping of relevant steps together, thus enhancing the readability of test reports.
test.slow()
This annotation is used to mark a test as slow. Playwright will triple the test timeout. This is useful when a test takes longer to run.
We can label a test as slow based on certain conditions, and if needed, provide an optional description too.
test.slow()
can also take a predicate as its first argument. The slow label will be applied if it returns true.
This is a theoretical chapter. There is nothing to commit in here. If you have made some changes to the project, clean them up by executing the
following command.