diff --git a/README.md b/README.md index 8a0fefba..89e14848 100644 --- a/README.md +++ b/README.md @@ -122,6 +122,17 @@ module.exports = { - `skipInitialization` <[boolean]>. Add you ability to skip first setup `playwright` process. Possible use cases can be found [here](https://github.com/playwright-community/jest-playwright/issues/424) - `useDefaultBrowserType` <[boolean]>. [Sometimes](https://github.com/microsoft/playwright/issues/2787) `browser` + `device` combinations don't have any sense. With this option tests will be run with [`defaultBrowserType`](https://github.com/microsoft/playwright/pull/3731) of device. Pay attention that you should define **devices** to correct usage of this option. +### Usage of process environment to define browser + +You can control the browser with passing environment variable. + +```js +// jest-playwright.config.js +module.exports = { + browsers: [process.env.BROWSER], +} +``` + ### Specific browser options For `launchOptions`, `connectOptions` and `contextOptions` you can define special browser options. @@ -185,11 +196,6 @@ module.exports = { } ``` -### Notes - -You can also specify browser with the `BROWSER` environment variable. You should do it only if you are using the whole playwright package. -You can specify device with `DEVICE` environment variable. - ## Globals - `browserName` <[string]> - name of the current browser (chromium, firefox or webkit) @@ -519,11 +525,14 @@ It's important to not change the `testEnvironment` to `node`. Otherwise it won't ### Error reporting with Jest -If you face into error messages like +If you face into error messages like + ``` UnhandledPromiseRejectionWarning: Error: Protocol error (Runtime.callFunctionOn): Target closed. -``` +``` + or + ``` Timeout - Async callback was not invoked within the 20000ms timeout specified by jest.setTimeout.Timeout - Async callback was not invoked within the 20000ms timeout specified by jest.setTimeout.Error: ``` diff --git a/src/PlaywrightEnvironment.ts b/src/PlaywrightEnvironment.ts index dbdc0d84..69d2e474 100644 --- a/src/PlaywrightEnvironment.ts +++ b/src/PlaywrightEnvironment.ts @@ -33,7 +33,6 @@ import { getBrowserOptions, getBrowserType, getDeviceBrowserType, - getDeviceType, getPlaywrightInstance, } from './utils' import { saveCoverageOnPage, saveCoverageToFile } from './coverage' @@ -205,7 +204,7 @@ export const getPlaywrightEnv = (basicEnv = 'node'): unknown => { browserName, this._jestPlaywrightConfig.contextOptions, ) - const device = getDeviceType(this._config.device) + const device = this._config.device const deviceName: Nullable = getDeviceName(device) const { name, diff --git a/src/utils.test.ts b/src/utils.test.ts index c94fb7f1..81dbd856 100644 --- a/src/utils.test.ts +++ b/src/utils.test.ts @@ -8,7 +8,6 @@ import { Playwright } from '../types/global' const { readConfig, getBrowserType, - getDeviceType, checkBrowserEnv, checkDeviceEnv, checkDevice, @@ -172,11 +171,9 @@ describe('getBrowserType', () => { const browserType = getBrowserType() expect(browserType).toBe(CHROMIUM) }) - it('should return BROWSER if defined', async () => { - process.env.BROWSER = 'webkit' + it('should return passed browser if it is passed', async () => { const browserType = getBrowserType('firefox') - expect(browserType).toBe(process.env.BROWSER) - delete process.env.BROWSER + expect(browserType).toBe('firefox') }) }) @@ -205,19 +202,6 @@ describe('getBrowserOptions', () => { }) }) -describe('getDeviceType', () => { - it('should return "null" when there is no device', async () => { - const device = getDeviceType(null) - expect(device).toBe(null) - }) - it('should return BROWSER if defined', async () => { - process.env.DEVICE = 'iPhone 11' - const device = getDeviceType(null) - expect(device).toBe(process.env.DEVICE) - delete process.env.DEVICE - }) -}) - describe('checkBrowserEnv', () => { it('should throw Error with unknown type', async () => { const browserType = getBrowserType('unknown' as BrowserType) diff --git a/src/utils.ts b/src/utils.ts index 89d30d0a..d044f62f 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -104,16 +104,7 @@ export const getDisplayName = ( return `browser: ${browser}` } -export const getDeviceType = (device: DeviceType): DeviceType => { - const processDevice = process.env.DEVICE - return processDevice || device -} - export const getBrowserType = (browser?: BrowserType): BrowserType => { - const processBrowser = process.env.BROWSER - if (processBrowser) { - return processBrowser as BrowserType - } return browser || CHROMIUM }