JS newbie here so please excuse any misconceptions I may have about JS or Playwright…
I have config.js file setup with projects and for each project I define custom variables (like login creds, etc.). How can I access these values in the global-setup.js
file when I use the ““–project=ProjectName“` when I run the test?
I can use testInfo in tests to access these values, but can I access it in global-setup.js
, since (as I understand it) is adds to the config object?
I am trying to use one global-setup file for login in with credentials from either one or another project, which are defined in the config.js file.
So I would run this:
npz playwright test testFile.spec.js --project=FirstProject
The playwright.config.js
file would have this setup:
{
name: "FirstProject",
username: "blahblah",
password: "blahblah",
},
{
name: "SecondProject",
username: "blahblah1",
password: "blahblah1",
}
]
And in global-setup.js
I would like to check which project is being used in order to provide the correct credentials — something like this:
module.exports = async config => {
const username = config.projects[${projectName}].username;
const password = config.projects[${projectName}].password;
Is this possible?
Thank you.