Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions docs/src/test-api/class-testoptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,27 @@ export default defineConfig({
});
```

## property: TestOptions.screen
* since: v1.64
- type: ?<[Object]>
- `width` <[int]> page width in pixels.
- `height` <[int]> page height in pixels.

Emulates consistent window screen size available inside web page via `window.screen`. Is only used when the [`property: TestOptions.viewport`] is set.

**Usage**

```js title="playwright.config.ts"
import { defineConfig } from '@playwright/test';

export default defineConfig({
use: {
viewport: { width: 390, height: 664 },
screen: { width: 390, height: 844 },
},
});
```

## property: TestOptions.screenshot
* since: v1.10
- type: <[Object]|[ScreenshotMode]<"off"|"on"|"only-on-failure"|"on-first-failure">>
Expand Down
4 changes: 4 additions & 0 deletions packages/playwright/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures, UtilityTestFixt
permissions: [({ contextOptions }, use) => use(contextOptions.permissions), { option: true, box: true }],
proxy: [({ contextOptions }, use) => use(contextOptions.proxy), { option: true, box: true }],
reducedMotion: [({ contextOptions }, use) => use(contextOptions.reducedMotion === undefined ? 'no-preference' : contextOptions.reducedMotion), { option: true, box: true }],
screen: [({ contextOptions }, use) => use(contextOptions.screen), { option: true, box: true }],
storageState: [({ contextOptions }, use) => use(contextOptions.storageState), { option: true, box: true }],
clientCertificates: [({ contextOptions }, use) => use(contextOptions.clientCertificates), { option: true, box: true }],
timezoneId: [({ contextOptions }, use) => use(contextOptions.timezoneId), { option: true, box: true }],
Expand Down Expand Up @@ -311,6 +312,7 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures, UtilityTestFixt
permissions,
proxy,
reducedMotion,
screen,
storageState,
viewport,
timezoneId,
Expand Down Expand Up @@ -356,6 +358,8 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures, UtilityTestFixt
options.proxy = proxy;
if (reducedMotion !== undefined)
options.reducedMotion = reducedMotion;
if (screen !== undefined)
options.screen = screen;
if (storageState !== undefined)
options.storageState = storageState;
if (clientCertificates?.length)
Expand Down
20 changes: 20 additions & 0 deletions packages/playwright/types/test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7683,6 +7683,26 @@ export interface PlaywrightTestOptions {
*
*/
reducedMotion: ReducedMotion;
/**
* Emulates consistent window screen size available inside web page via `window.screen`. Is only used when the
* [testOptions.viewport](https://playwright.dev/docs/api/class-testoptions#test-options-viewport) is set.
*
* **Usage**
*
* ```js
* // playwright.config.ts
* import { defineConfig } from '@playwright/test';
*
* export default defineConfig({
* use: {
* viewport: { width: 390, height: 664 },
* screen: { width: 390, height: 844 },
* },
* });
* ```
*
*/
screen: ViewportSize | undefined;
/**
* Learn more about [storage state and auth](https://playwright.dev/docs/auth).
*
Expand Down
26 changes: 26 additions & 0 deletions tests/playwright-test/playwright.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,32 @@ export class VideoPlayer {
}
}

test('should respect screen option', async ({ runInlineTest }) => {
const result = await runInlineTest({
'playwright.config.ts': `
module.exports = { use: { viewport: { width: 500, height: 500 }, screen: { width: 1000, height: 1000 } } };
`,
'a.test.ts': `
import { test, expect } from '@playwright/test';
test('pass', async ({ page, screen }) => {
expect(screen).toEqual({ width: 1000, height: 1000 });
expect(await page.evaluate(() => [window.screen.width, window.screen.height])).toEqual([1000, 1000]);
});
`,
'b.test.ts': `
import { test, expect, devices } from '@playwright/test';
test.use({ ...devices['iPhone 13'] });
test('pass', async ({ page, screen }) => {
expect(screen).toEqual({ width: 390, height: 844 });
expect(await page.evaluate(() => [window.screen.width, window.screen.height])).toEqual([390, 844]);
});
`,
}, { workers: 1 });

expect(result.exitCode).toBe(0);
expect(result.passed).toBe(2);
});

test('should respect viewport option', async ({ runInlineTest }) => {
const result = await runInlineTest({
'playwright.config.ts': `
Expand Down
1 change: 1 addition & 0 deletions utils/generate_types/overrides-test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ export interface PlaywrightTestOptions {
permissions: string[] | undefined;
proxy: Proxy | undefined;
reducedMotion: ReducedMotion;
screen: ViewportSize | undefined;
storageState: StorageState | undefined;
timezoneId: string | undefined;
userAgent: string | undefined;
Expand Down
Loading