In Protractor, I am currently passing a flag in the command line that indicates what my URL is for the app I am testing. And now we are switching to Playwright, I want to do something similar. Since the same tests will be used to test the app in different environments (dev, test, CI) I need a way to pass different URLs and ideally it will be nice if I can control that via command line.
UPDATE:
The baseURL option has been added in Playwright v1.13.0.
import { PlaywrightTestConfig } from '@playwright/test';
const config: PlaywrightTestConfig = {
use: {
baseURL: 'http://localhost:3000',
},
};
export default config;
Currently, in Playwright Test v1.12.0 there is no baseUrl property as we have in Protractor. But you can accomplish it with a system variable.
For instance:
import { test } from '@playwright/test';
const BASE_URL = process.env.URL;
test('verify title of the page', async ({ page }) => {
await page.goto(BASE_URL);
});
and then run it on dev env:
URL=https://playwright.dev npx playwright test
or prod:
URL=https://playwright.prod npx playwright test
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With