You can use the skip() method in Playwright to skip a test. You can use this method with one or more tests in your spec file.
Table of Contents
Skip a Test
Here is the syntax to skip a test.
test.skip(title, testFunction)
The test will never run if you will link the skip() method with it. For example:
test('Test 1', async({page})=>{
console.log("Test 1 Executed");
})
test.skip('Test 2', async({page})=>{
console.log("Test 2 Executed");
})
test('Test 3', async({page})=>{
console.log("Test 3 Executed");
})
Test 2 will be skipped in the above code, and the remaining two tests will be executed.
Also, in the report, Test 2 will be listed under skipped section, and the remaining two test cases in the passed section.
You can .skip() method with multiple tests; Playwright will not restrict you. However, if you want to skip group of tests, better you use skip() with the describe.
Unconditionally Skip a Test
Instead of linking the skip() method with your test, you can also use the test.skip() statement inside your test method body. It will unconditionally skip a test. The test is immediately terminated when you call the test.skip().
test('Test 2', async({page})=>{
test.skip()
console.log("Test 2 Executed");
})
However, it makes more sense to skip the test based on conditions. You can use this statement inside your if block or give a condition as an argument in the skip() method.
- Log in to post comments