skip to Main Content

I’m exploring options to modify my existing test so that certain steps execute only when I include a specific annotation/tag in Playwright. The test currently performs several assertions, and I want to extend it to add a few more without repeating the same actions. Specifically, I’m checking the previews of a message editor. I’d like to enhance it to also send the message, while still verifying the previews independently.

test('Test for some feature 1', async ({page}) => {
   test.step('Step 1', async() => {
     //Few assertions here
    });
  
  test.step('Step 2', async() => {
    //Few assertions here
    });
 
//This step should only run if I pass a certain annotation/tag
 test.step('Step 3', {tag: ['@featureX']}, async() => {
 //This should run only if I pass an annotation say @featureX
 });
});

2

Answers


  1. I don’t believe test.step supports any kind of tagging feature, however I don’t see why you couldn’t achieve what you are looking for by checking for an environment variable, which you can set when you want the extra step to run and not set when you don’t.

    Login or Signup to reply.
  2. How to skip/execute a test step conditionally?

    How about using a boolean flag variable…

    somethingIsTrue && await test.step('my step', async () => {
      ...
    });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search