14

We have in protractor like: browser.driver.manage().window().setSize( width - 30, height );

How to achieve this in playwright?

Sangeetha
  • 151
  • 2
  • 4
  • 1
    Welcome to StackOverflow. please take a while and read [ask] with [mre]. Good luck – nima Nov 12 '21 at 12:02
  • 1
    You can pass a custom viewport in the playwright.config.ts see here: https://playwright.dev/docs/api/class-testoptions or when creating a new context if you are using the library: https://playwright.dev/docs/emulation#viewport – Max Schmitt Nov 12 '21 at 12:20
  • Thanks Max, I need to resize window and reset it back to its original between a test and in the same browser context. How can I get current size dynamically and +/- some pixels from it? – Sangeetha Nov 13 '21 at 13:07

1 Answers1

18

To resize your playwrite browser window: you can use the method page.setViewportSize()

For Example:

import { test, expect, devices } from '@playwright/test';

test('test', async ({ page }) => {
  page.setViewportSize({ width: 600, height: 600 });
  // do stuff then resize to a particular device size 
  page.setViewportSize(devices['iPhone X'].viewport);
}
Leo103
  • 691
  • 7
  • 16