I have my config as
Projects :[
{ name: 'setup', testMatch: 'auth.setup.ts' },
{
name: 'e2e-uat',
use: {
baseURL: 'https://uat.example.com',
storageState: '.auth/user.json',
},
dependencies: ['setup'],
},
{
name: 'e2e-canary',
use: {
baseURL: 'https://example.com',
storageState: '.auth/user.json',
},
dependencies: ['setup'],
},]
but when I run the auth.setup,
await page.goto('/auth/login');
it does not get any baseUrl and hence it becomes an invalid URL.
How can I pass the baseURLÂ from one config to it’s dependency configAs here when I run e2e-uat I want to pass baseURL: 'https://uat.example.com'
to project setup
and when I run e2e-canary I want to pass baseURL: 'https://example.com'
to project setup
2
Answers
You may access the base URL (from any project) inside your global setup file like below:
Complete Example:
Dynamic Reference:
To pass baseurl dynamically from the command line in Playwright test, you can always pass using the –baseURL option. For example, to run tests against a staging environment, you would run the following command:
References:
First solution
You should create a dedicated setup project for each project,
and pass the url using the
use
property inside each of the setups – because a setup project has it’s own tests to execute.Second solution
Using the same setup project for both of the projects,
is to create a
switch-case
statement inside the setup test, that checks the project-name that executes current run, and based on the name- pass the wanted URL.