【问题标题】:Playwright config file not using all of the values set剧作家配置文件未使用所有设置的值
【发布时间】:2021-09-28 03:28:48
【问题描述】:

我的 Playwright 配置文件似乎没有正确使用。当我运行test 命令时,我确保指向我的配置文件(命名为:playwright.config.ts,使用--config)并且终端会验证该文件是否正在使用。

但是,只有retries 设置似乎有效。测试设置为“on”还是“only-on-failure”后,不会应用超时设置更改并且不会生成屏幕截图。没有设置outputDir 也不会生成文件夹。

TypeScript 没有在我的配置文件上出现任何错误,所以我不知道哪里出了问题。配置文件与我的测试位于同一文件夹中,它不在根目录下。

我将文件移到根目录外,遇到了同样的问题。


import { PlaywrightTestConfig } from '@playwright/test';

const config: PlaywrightTestConfig = {
  testDir: 'tests', //is recognized
  timeout: 45000,
  retries: 1, //is recognized
  outputDir: './screenshots',
  use: {
    headless: false,
    viewport: { width: 1440, height: 800 },
    screenshot: 'only-on-failure',
  },
};

export default config;

以下是供参考的文档:https://playwright.dev/docs/test-configuration/

【问题讨论】:

    标签: typescript playwright


    【解决方案1】:

    我也面临这个问题,我的错误是使用test方法:

    import { firefox } from 'playwright';
    import { test } from '@playwright/test';
    
        test('test not using configuration', async () => {
            var browser = await firefox.launch()
            var context = await browser.newContext()
            var page = await browser.newPage()
             
            await page.goto("http://ya.ru")
            page.waitForLoadState()
            var input = await page.waitForSelector('#text');
            (await input).click
            await page.keyboard.type('test text', {delay: 100})
            console.log(await page.video()?.path())
        })
    

    该代码未使用配置,因为使用默认参数初始化新浏览器。

    使用配置的代码示例:

    test('test using configuration', async ({ page }) => {
        await page.goto("http://ya.ru")
        page.waitForLoadState()
        var input = await page.waitForSelector('#text');
        (await input).click
        await page.keyboard.type('test text', {delay: 100})
        console.log(await page.video()?.path())
    });
    

    因为我们在测试方法中添加了page 参数并且他是从配置文件中初始化的,所以这可以工作。那个例子有docs

    【讨论】:

      猜你喜欢
      • 2022-01-12
      • 2021-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-05
      相关资源
      最近更新 更多