globalSetup to reference baseUrl from playwright.config

Viewed 2157

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!

1 Answers

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/

Related