playwright
playwright copied to clipboard
[Question] Getting baseURL?
I noticed a similar issue here: https://github.com/microsoft/playwright/issues/9439
Basically I need a way to get baseURL outside of a fixture? I need to be able to get the current baseURL in a class for being able to merge baseURL w/ another url (Some methods we use require the baseURL to produce headers).
Not sure if this is possible?
You can pass the baseURL from your test over to your class in order to have access to it, would that work for you?
That's what I ended up doing. Something like:
In the test:
test.beforeEach(async ({ request, baseURL }) => {
widget= new Widget(request, baseURL);
});
in the class:
constructor(protected apiContext: APIRequestContext, protected baseUrl: string) {
super(apiContext, baseUrl);
//super calls the base class
}
Does that seem correct?
This is correct and the recommend way.