我正在尝试使用Playwright最大化浏览器窗口。我尝试了下面的代码,但浏览器没有最大化到完整模式。
hooks.cjsclass:
const playwright = require('playwright');
const { BeforeAll, Before, After, AfterAll , Status } = require('@cucumber/cucumber');
// Launch options.
const options = {
slowMo: 100,
ignoreHTTPSErrors: true,
};
// Create a global browser for the test session.
BeforeAll(async () => {
console.log('Launch Browser');
global.browser = await playwright['chromium'].launch({ headless: false,
args:['--window-size=1920,1040']}); // --start-maximized //defaultViewport: null
//global.context = await playwright['chromium'].launch({ args: ['--start-maximized'] });
})
// Create a new browser context for each test.
Before(async () => {
console.log('Create a new Context and Page')
global.context = await global.browser.newContext()
global.page = await global.context.newPage()
})
// Close the page and context after each test.
After(async () => {
console.log('Close Context and Page');
await global.page.close();
await global.context.close();
})
// Take Screenshot if Scenario Fails
After(async function (scenario) {
if (scenario.result.status === Status.FAILED) {
const buffer = await global.page.screenshot({ path: `reports/${scenario.pickle.name}.png`, fullPage: true })
this.attach(buffer, 'image/png');
}
})
// Close Browser
AfterAll(async () => {
console.log('close Browser')
await global.browser.close()
});
使用npm:npm run test -- --tags "@Begin"
我已经尝试了很多方法,但我不能启动浏览器最大化。我该怎么做?
2条答案
按热度按时间wh6knrhe1#
如果你想最大化地启动浏览器,那么在启动浏览器时使用
--start-maximized
标志,并在启动上下文或页面时禁用固定视口。例如在python中,使用等效的
no_viewport
arg,并在启动上下文时将其作为True
传递gwbalxhn2#
您可以在浏览器启动期间传递如下参数: