如何使用 Playwright 最大化弹出窗口 window(例如单击按钮打开弹出窗口 window)

How to maximize a Popup window using Playwright (ex clicking a button to open Popup window)

我正在测试的软件有很多弹出 windows / 模态 windows。主页 loginPage 以全屏模式打开。单击按钮后,将打开一个新的弹出窗口(模态)window,例如。 overviewPage

我想要实现的是更改此弹出窗口的视口 window,或者最好将其最大化,在本例中是 overviewPage

这是我的代码:

const browser = await chromium.launch({
        args: ['--start-maximized'],
        headless : false, slowMo : 50});
const context = await browser.newContext({viewport : null});
const loginPage = await context.newPage();
await loginPage.goto(myURL.href);  //Login Page was opened in Maximized mode (Fullscreen)

// Next step is to click a button on Login Page, and a new page is opened.
await loginPage.click('#nextBtn');

console.log('Get page after a specific action (e.g. clicking a button');
const [overviewPage] = await Promise.all([
    context.waitForEvent('page')
]);
await overviewPage.waitForLoadState();
await overviewPage.screenshot({ path: `reportoverview.png` });
console.log('Current window: ' + await overviewPage.title());

弹窗windowoverviewPage打开了,但是视口很小,不知道怎么最大化。

我已经在 context 中设置了标志 --start-maximized,它适用于 loginPage。如何以及在何处设置 Popup 的视口 window.

我使用的是 Playwright 版本:v1.2.1.

我可以使用 setViewportSize

将弹出 window 的 viewport 设置为我的需求
await overviewPage.setViewportSize({ width: 1920, height: 1080 });

它解决了我的问题。

//You can use setViewPortSize(int width, int height) in Java.
public static void main(String[] args) {

        Playwright playwright = Playwright.create();
        Browser browser = playwright.chromium().launch(new BrowserType.LaunchOptions().setHeadless(false));
        BrowserContext context = browser.newContext(new Browser.NewContextOptions().setViewportSize(1920, 1080));
        Page page = context.newPage();
        page.navigate("https://www.amazon.com/");
    }
 
//You can get the current screen dimensions as well:
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            int width = (int)screenSize.getWidth();
            int height = (int)screenSize.getHeight();
            System.out.println(width + " " + height);
            
            Playwright playwright = Playwright.create();
            Browser browser = playwright.chromium().launch(new BrowserType.LaunchOptions().setHeadless(false));
            BrowserContext context = browser.newContext(new Browser.NewContextOptions().setViewportSize(width,height));
            Page page = context.newPage();
              page.navigate("https://www.amazon.com/");