docs(webServer): prefer url over port (#13008)

This commit is contained in:
Dmitry Gozman 2022-03-23 16:07:30 -07:00 committed by GitHub
parent e1700bd167
commit 03b08c1ff9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -156,10 +156,13 @@ import { PlaywrightTestConfig } from '@playwright/test';
const config: PlaywrightTestConfig = { const config: PlaywrightTestConfig = {
webServer: { webServer: {
command: 'npm run start', command: 'npm run start',
port: 3000, url: 'http://localhost:3000/app/',
timeout: 120 * 1000, timeout: 120 * 1000,
reuseExistingServer: !process.env.CI, reuseExistingServer: !process.env.CI,
}, },
use: {
baseURL: 'http://localhost:3000/app/',
},
}; };
export default config; export default config;
``` ```
@ -171,41 +174,36 @@ export default config;
const config = { const config = {
webServer: { webServer: {
command: 'npm run start', command: 'npm run start',
port: 3000, url: 'http://localhost:3000/app/',
timeout: 120 * 1000, timeout: 120 * 1000,
reuseExistingServer: !process.env.CI, reuseExistingServer: !process.env.CI,
}, },
use: {
baseURL: 'http://localhost:3000/app/',
},
}; };
module.exports = config; module.exports = config;
``` ```
Now you can use a relative path when navigating the page, or use `baseURL` fixture: Now you can use a relative path when navigating the page:
```js js-flavor=ts ```js js-flavor=ts
// test.spec.ts // test.spec.ts
import { test } from '@playwright/test'; import { test } from '@playwright/test';
test('test', async ({ page, baseURL }) => { test('test', async ({ page }) => {
// baseURL is taken directly from your web server, // baseURL is set in the config to http://localhost:3000/app/
// e.g. http://localhost:3000 // This will navigate to http://localhost:3000/app/login
await page.goto(baseURL + '/bar'); await page.goto('./login');
// Alternatively, just use relative path, because baseURL is already
// set for the default context and page.
// For example, this will result in http://localhost:3000/foo
await page.goto('/foo');
}); });
``` ```
```js js-flavor=js ```js js-flavor=js
// test.spec.js // test.spec.js
const { test } = require('@playwright/test'); const { test } = require('@playwright/test');
test('test', async ({ page, baseURL }) => { test('test', async ({ page }) => {
// baseURL is taken directly from your web server, // baseURL is set in the config to http://localhost:3000/app/
// e.g. http://localhost:3000 // This will navigate to http://localhost:3000/app/login
await page.goto(baseURL + '/bar'); await page.goto('./login');
// Alternatively, just use relative path, because baseURL is already
// set for the default context and page.
// For example, this will result in http://localhost:3000/foo
await page.goto('/foo');
}); });
``` ```