在 jest-playwright

问题描述

我在如何正确使用 jest-playwright 中的两个调试选项方面遇到了一些困难。

相关的 jest-config.js 文件

module.exports = {
  preset: "jest-playwright-preset",testEnvironment: "./custom-environment.js",testEnvironmentOptions: {
    'jest-playwright': {
      launchOptions: {
        headless: true
      },debugOptions: {
        launchOptions: {
          headless: false,devtools: true
        }
      },contextOptions: {
        ignoreHTTPSErrors: true,hasTouch: true,storageState: {
          cookies: [
            {
              sameSite: 'None',name: 'm_user',value: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1aWQiOiI0OTM2MGYxZi02YThlLTRjMTetoDMxMC1jYzkwODY5YWYxNWYiLCJpcCI6IjE5Mi4xNjguMC4xMiJ9.3jUXwcU1zLcOGWlNoFrLsYUw5y-pR7707jNOK-EImxg',domain: 'mondev.chandlerfamily.org.uk',path: '/',expires: -1,httpOnly: false,secure: false
            }
          ]
        }
      }
    }
  },// The root directory that Jest should scan for tests and modules within
  rootDir: "test/end2end",setupFilesAfterEnv: ["expect-playwright"]

};

首先 - 如果我在上面的配置文件中更改 headless: false,我可以打开浏览器

describe('managing reconciled and cleared balance',() => {
  beforeAll(async () => {
    await page.goto(`https://${process.env.MONEY_DOMAIN}/account?account=Cash`);
    await page.textContent('#defcur');
  })
  test('check reconciled balance,cleared balance and minimum balance are set correctly',async() => {
    const reconciledBalance = await page.$eval('#recbal',el => el.value);
    expect(reconciledBalance).toBe(1000.00);
    await expect(page).toHaveText('#clearb','1000.00');
    const minb = await page.textContent('#minb');
    console.log('minimum balance',minb);
    await jestPlaywright.debug();
  });
});

此时,我运行测试的终端窗口显示代码已暂停,按回车键恢复”并且测试在此时停止。但是我所做的任何事情都不能使测试继续进行。按回车什么也不做,此时我唯一的选择是使用 Control C 来终止测试。这样做的问题是 Afterall 测试没有运行,我的数据库保留了我为其中的测试所做的所有准备工作。

另一种选择是将我的测试更改为

test.jestPlaywrightDebug('check reconciled balance,async() => {
...
}); 

如果我在没有 await jestPlaywright.debug() 语句的情况下执行此操作 - 浏览器会短暂显示该测试的非无头,但会继续。如果我确实包含 await jestPlaywright.debug() 语句,则会出现浏览器窗口,但页面为空白,并且测试会在 15 秒后因超时而失败。

我希望 test.jestPlaywrightDebug 切换到调试选项(它似乎确实这样做),但是在我探索正在发生的事情时,测试不要超时。但是在 await jestPlaywright.debug() 调用中,有一种方法可以完成调试并告诉它继续进行。

我怎样才能做到这一点?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)