剧作家 - 不会启动全屏

Mat*_*z K 6 javascript node.js playwright playwright-test

我正在使用新的剧作家测试运行程序启动文本执行。不幸的是我无法让它以全屏模式启动。

我正在使用以下代码:

const { test, expect } = require('@playwright/test');
const { HomePage } = require('../lib/Homepages');
const playwright = require('@playwright/test');

test.describe('Home Test Suite', () => {
  let homePage;

  test.beforeAll(async () => {
    const browser = await playwright.chromium.launch({ args: ['--start-maximized'] });
    const context = await browser.newContext({ viewport: null });
    const page = await context.newPage();
    homePage = new HomePage(page);
    await homePage.loadapp();
  });

  test.afterAll(async ({ browser }) => {
    await browser.close();
  });

  test.describe('test1', () => {
    test('test', async () => {
      expect(await homepage.x()).toBeTruthy();
      // Act
      await homePage.dosomething('Word');

      // Assert
      expect(await homePage.isItCorrect()).toBeTruthy;
    });
   });
   });
Run Code Online (Sandbox Code Playgroud)

运行 npm run test 后。我收到以下错误:

browser.newContext:空“viewport”不支持“deviceScaleFactor”选项

知道如何让它发挥作用吗?

小智 6

我在 .NET 中使用 Playwright,这是我对此问题的解决方案。

在 BrowserTypeLaunchOptions 中指定最大化

new BrowserTypeLaunchOptions()
{
  Args = new string[] { "--start-maximized" }
}
Run Code Online (Sandbox Code Playgroud)

使用 NoViewport 初始化 BrowserContext

Context = await Browser.NewContextAsync(new BrowserNewContextOptions()
{
  ViewportSize = ViewportSize.NoViewport
});
Run Code Online (Sandbox Code Playgroud)


Mat*_*z K -1

该错误是由 playwright.config.js 引起的。

我有以下代码:

    projects: [
        {
            name: 'chromium',
            use: {
                ...devices['Desktop Chrome'],
            },
        },
]
Run Code Online (Sandbox Code Playgroud)

注释掉“使用”已经解决了这个问题。