Reputation: 87
I have a set of e2e tests. We have a test enviroment: test.mypage.com And we also have a UAT enviroment: uat.mypage.com I want to be able to run the same e2e tests on either our test or uat enviroment, depending on the command line i use.
my config file:
import { LaunchOptions } from 'playwright';
const browserOptions: LaunchOptions = {
headless: false,
slowMo: 0,
args: []
};
export const config = {
browserOptions,
env: {
server: 'test'
}
};
my step file:
Given(/^i go to login page$/, async function () {
await PW.page.goto(`https://${config.env.server}.mypage.com/`);
});
the command line I use to run my tests:
npx cucumber-js
So I assume the solution would be something like
npx cucumber-js --server "uat"
but either my syntax is wrong or I'm missing something. When I run the script above, I get an error: unknown option: '--server'
.
I tried
npx cucumber-js `$env:server="uat"
which didn't throw any errors but the environment remained test.mypage.com
.
So how can I change the environment from the command line?
Upvotes: 0
Views: 1984
Reputation: 18650
You can use the baseurl test option for this.
In your config file, add the baseurl:
import { PlaywrightTestConfig } from '@playwright/test';
const config: PlaywrightTestConfig = {
use: {
baseURL: `https://${config.env.server}.mypage.com/`,
},
};
export default config;
So now your test should look like this:
Given(/^i go to login page$/, async function () {
await PW.page.goto('/');
});
Now from CLI, you can run with a different baseurl like this:
URL=https://playwright.dev npx playwright test
Upvotes: 1