Playwright – timeout in config is 2mins but i want to wait for 5mins in one my test case without change in the config waittime

huangapple go评论71阅读模式
英文:

Playwright - timeout in config is 2mins but i want to wait for 5mins in one my test case without change in the config waittime

问题

我在 PlaywrightTestConfig 文件中设置了一个全局的 2 分钟超时时间。在其中一个测试用例中,我想等待 10 分钟以进行文件验证。所有测试的全局设置如下所示:

const config: PlaywrightTestConfig = {
  // 每个 Playwright 操作的超时时间,以毫秒为单位。默认为 0(无超时)
  timeout: 120000
  ...
}

我尝试了以下几种方法:
1. click({ timeout: 600000 });
2. test.slow();
3. test.setTimeout(600000);
4. page.setDefaultTimeout(600000);
5. page.setDefaultNavigationTimeout(600000);

在所有这些情况下,测试都在 2 分钟后超时,而不是覆盖的 10 分钟(600000)。

提高全局设置可能会起作用,但会使整个测试套件运行得更慢,这并不理想。

在步骤中是否有可能将超时时间设定为超过全局超时时间?
英文:

I have a timeout for 2 mins in PlaywrightTestConfig file as a Global setting. In one of the test case I want to wait for 10 mins for a file validation to happen.
Global setting for all tests is defined like below:

const config: PlaywrightTestConfig = {
  // Timeout for each Playwright action in milliseconds. Defaults to 0 (no timeout)
  timeout: 120000
  ...
}

I tried these ways:

  1. click({ timeout: 600000 });
  2. test.slow();
  3. test.setTimeout(600000);
  4. page.setDefaultTimeout(600000);
  5. page.setDefaultNavigationTimeout(600000);

In all these cases, the test timesout after 2 mins instead of the overwrite 10 mins(600000).

Bumping up the global setting might work, but it will make the whole test suite run slower which is not ideal.

Is it possible to have timeout for a step be more than the global timeout?

答案1

得分: 0

听起来你的测试套件中有不同类型的测试。根据持续时间来分离它们的一种可能方法是将它们拆分成项目。然后,对于每个项目,你可以指定不同的 timeout,而不是使用一个全局值,因为这不适用于所有用例。

{
  "use": [
    {
      "browserName": "chromium",
      "timeout": 120000
    },
    {
      "browserName": "chromium",
      "timeout": 600000,
      "testMatch": '/long-tasks/**/*.spec.js',
    }
  ]
}
英文:

Sounds like there are different types of tests in your suite. One possible approach to separate them based on duration is to split them into projects. Then for each project you can specify different timeout instead of having one global value which doesn't fit all use cases.

{
  "use": [
    {
      "browserName": "chromium",
      "timeout": 120000
    },
    {
      "browserName": "chromium",
      "timeout": 600000,
      "testMatch": '/long-tasks/**/*.spec.js',
    }
  ]
}

答案2

得分: 0

**在特定操作上设置自定义超时时间+ [测试超时][1]:**

在页面对象内的特定操作:

```javascript
async performSomeAction() {
  //一些测试步骤
   await page.click(someLocator)
   await page.waitForSelector(locatorWhichAppearAfterClick,{timeout:400000})
  //一些其他步骤
}

在测试中:

test('执行一些操作', async () => {
    await page.performSomeAction()  
  },600000)

参考链接: https://playwright.dev/docs/test-timeouts


<details>
<summary>英文:</summary>

**Have custom timeout on specific action+ [test timeout][1]:**


Specific action inside Page Object :

     async performSomeAction() {
      //some test steps
       await page.click(someLocator)
       await page.waitForSelector(locatorWhichAppearAfterClick,{timeout:400000})
      //some other steps
    }


Inside Test:

 

    test(&#39;Perform someAction&#39;, async () =&gt; {
        await page.performSomeAction()  
      },600000)


Reference: https://playwright.dev/docs/test-timeouts


  [1]: https://playwright.dev/docs/test-timeouts#test-timeout

</details>



huangapple
  • 本文由 发表于 2023年4月4日 06:46:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/75924261.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定