英文:
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:
- click({ timeout: 600000 });
- test.slow();
- test.setTimeout(600000);
- page.setDefaultTimeout(600000);
- 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('Perform someAction', async () => {
await page.performSomeAction()
},600000)
Reference: https://playwright.dev/docs/test-timeouts
[1]: https://playwright.dev/docs/test-timeouts#test-timeout
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论