Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

globalSetup to reference baseUrl from playwright.config

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!

like image 384
OrdinaryKing Avatar asked Sep 18 '25 22:09

OrdinaryKing


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/

like image 60
Max Schmitt Avatar answered Sep 23 '25 06:09

Max Schmitt