playwrightbase-url

Playwright change baseUrl only for specific set of specs


Hi I have 5 specs that my playwright runs. All of them are using the baseUrl which is set in my playwright.config.js BUT I would like 2 out of those 5 tests to run on a different baseUrl. Is that even possible?


Solution

  • That you can, just put the tests you want to run with overridden baseUrl inside a describe like this:

    import { test } from "@playwright/test";
    
    test.describe("Tests with different baseUrl", async () => {
    
      test.use({ baseURL: "https://overriden.url" });
    
      test("Test 2", async ({ page }) => {
        await page.goto("/");
        // Test uses overridden url
      });
    });
    
    

    ...or to use on whole spec file, put the test.use line on top of the file