0

I am using two URLs for dev and stg environments. These two environments also have different URL for API calls. This is my .env file:

URL1=https://playwright-dev.com/
URL2=https://playwright-stg.com/
BASE_URL1=https://playwright-dev/api/
BASE_URL2=https://playwright-stg/api/

And this is an example of how I am using it in the tests:

test('example', async ({ page, request }) => {
  await page.goto(process.env.URL1);
  let response = await request.put(`${process.env.BASE_URL1}/import`, {
            headers: {authorization: `Bearer ${token}`},
            data: JSON.parse(Data)
        });
});

However, I would like to be able to select the wanted URL via command line and delete .env file, something like that:

URL=https://playwright-dev.com/ BASE_URL=https://playwright-dev/api/ npx playwright test

How can I do that? Thank you!

1449
  • 21
  • 5
  • Looks like you already have it? Those you’re setting in the command line are available the same way as the .env, you just need to update the name in the code to remove the `1`, for instance. – David R Mar 08 '23 at 15:57
  • Also, you may need to wrap the urls in quotes (`URL=”someurl”`) on the command line, come to think of it. – David R Mar 09 '23 at 02:31

0 Answers0