如何让浏览器在测试剧作家时打开?

问题描述 投票:0回答:1

我正在对一个网址进行 e2e 测试。在测试过程中,用户需要单击其中一个元素。 下面的代码是用playwriter写的:

  test("advanced order", async ({ browser }) => {
  const context = await browser.newContext({
    storageState: "./auth.json",
  });

  const pageOrigin = await context.newPage();
  //   await pageOrigin.goto("http://localhost:5500/#view/login.html");
  await pageOrigin.goto("https://sina.exirbroker.com/mobile/#view/login.html");
  await pageOrigin.getByLabel("user").click();
  await pageOrigin.getByLabel("user").fill("ab23");
  await pageOrigin.getByLabel("user").press("Tab");
  await pageOrigin.getByLabel("pass").click();
  await pageOrigin.getByLabel("pass").fill("csds");
  await pageOrigin.getByText("btn").click();
  await pageOrigin.waitForTimeout(3000);
  await pageOrigin.waitForURL("**/OnlineTrades/newOrder.html?**");
  await pageOrigin.waitForTimeout(3000);
  await pageOrigin
    .locator("header")
    .filter({ hasText: "submit order" })
    .locator("span")
    .click();
  await pageOrigin
    .locator("#orderSettingsHolder > div > .km-switch > .km-switch-container")
    .first()
    .click();

  await pageOrigin.getByLabel("Close").click();

  await pageOrigin.waitForTimeout(3000);
  await pageOrigin.waitForTimeout(5000);
  await expect(pageOrigin).toHaveScreenshot();
});

因此必须打开浏览器并且用户单击该元素。使用playwright vscode运行测试,打开浏览器,但是当按

npx playwright test
运行测试时,浏览器不会打开。 如何解决这个问题?

javascript e2e-testing playwright
1个回答
1
投票

您应该在 headed 模式下运行它。

默认为 false。 要更改它 - 编辑

playwright.config.ts
use.headless = false

npx playwright test --headed

更好的调试替代方案:

npx playwright test --debug
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.