Search code examples
javascriptplaywright

Playwright - Run test having run flag as Yes


I am working on Playwright framework in JavaScript.

I have database where maintaining data and test run flag as Yes or No.

enter image description here

From above table, generating json file for Test ID having Execute flag as 'Yes' along with test data.

Have created different test file for each Test ID.

Now want to run only those tests having Execute flag as 'Yes'. Please help.


Solution

  • Without seeing much of what you have going, what you can try is to conditionally set test.skip() on the tests where Execute is No.

    Assuming a JSON structure like this:

    {
      "TC_001": "Yes",
      "TC_002": "Yes",
      "TC_003": "No"
    }
    
    import { test } from "@playwright/test"
    import testJson from "path/to/your/file.json"
    
    test("some test", async ({ page }) => {
       const testId = "TC_002"
       if (JSON.parse(testJson)[testId] === "No") test.skip()
    })
    

    There is likely a more global way to approach this that could require you to change the test and folder structure. Pore over the config documentation to see if there's a case that works for you.