Playwright change baseUrl only for specific set of specs

133 views Asked by At

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?

2

There are 2 answers

0
candre On BEST ANSWER

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

0
Yehor Zakharov On

You can specify the full URL address for those 2 specs, if I correctly understood your question:

  await page.goto('https://playwright.dev/');

this will overwrite the value in playwright.config.js while using

await page.goto();

will use URL from you config