3

Im currently using a global-setup.ts file to load a url via playwright.

await page.goto('https://test1.com/');

I am also doing extra code inside here and storing the state of my object (All works as expected)

My playwright.config.ts file references the globalsetup and this all works as expected.

In my Config file I also set baseUrl however, I am struggling on a way to get the baseUrl passed to my global-setup.ts file instead of hardcoding it.

Thanks!

OrdinaryKing
  • 411
  • 1
  • 7
  • 16

1 Answers1

8

Inside your global setup, you can access the baseURL like that:

import { FullConfig } from '@playwright/test';

async function globalSetup(config: FullConfig) {
  console.log(config.projects[0].use.baseURL);
}

export default globalSetup

See here: https://playwright.dev/docs/api/class-testconfig/

Max Schmitt
  • 2,529
  • 1
  • 12
  • 26
  • Hi Max. I dont think this will work. Im using multiple projects and this is only taking the first projects url. Is there a way of me being able to pass the project I have already selected? – OrdinaryKing Sep 22 '21 at 09:19
  • globalSetup will only run a single time before all the tests run. There is no globalSetup yet for projects. If you want different globalSetups per project you for now need to create multiple playwright config files. – Max Schmitt Sep 22 '21 at 10:47