Search code examples
javascriptautomated-testsplaywrightplaywright-test

How to avoid "Duplicate test titles are not allowed" error in playwright-test?


Context: In long E2E test flows there are certain steps that are duplicated like moving in-between "Product" vs "shipping" vs "Payment method" tabs in an online order workflow.

Problem: In Playwright-Test, duplicate test titles are not allowed as "error" (not as a warning) which is painful for someone who is migrating test scripts from other testing frameworks like "Jasmine" (as in my scenario) where duplicate test titles were allowed.

Desired Solution : Is there a solution, where this error can be avoided on the configuration level (preferably as a warning) without changing 100s of scripts manually? Thanks!

enter image description here


Solution

  • Update:

    As this has been declined by playwright team to implement as a direct solution, you may use test.step as workaround.

    For new tests with duplicate titles:

    test.step can be re-used in multiple tests, instead of making it a separate test.

    import { test, expect } from '@playwright/test';
    
    test('test', async ({ page }) => {
      await test.step('Log in', async () => {
        // ...
      });
    });
    

    For existing tests with duplicate titles:

    You can write a script to change every test('...', into test('n-...', to make the titles unique by adding a randomely generated long number in the title to make it unique.