英文:
Why am I getting timeout exceptions when I use the WaitForRequestFinishedAsync function?
问题
我的.NET Playwright测试经常跳过步骤,我一直在使用 Thread.Sleep()
来确保它不会跳过代码。而现在,我想使用 WaitForRequestFinishedAsync()
代替:
await page.Locator(".my-class").ClickAsync(); // 想确保不会跳过这一行
await page.WaitForRequestFinishedAsync();
我收到的错误信息是:
>System.TimeoutException : 在等待事件 "RequestFinished" 时超过了30000毫秒的超时时间
我可能漏掉了一些明显的东西,但任何建议都将不胜感激。
英文:
My .NET Playwright tests often skip steps and I have been using Thread.Sleep()
to make sure it doesn't skip over code. Instead of this, I want to use WaitForRequestFinishedAsync()
instead:
await page.Locator(".my-class").ClickAsync(); // want to make sure it doesn't skip this line
await page.WaitForRequestFinishedAsync();
My error I am receiving:
>System.TimeoutException : Timeout 30000ms exceeded while waiting for event "RequestFinished"
I am probably missing something obvious here, but any suggestions would be great.
答案1
得分: 1
从文档中,似乎可以在方法定义的第二个参数中设置超时时间(如果未定义,默认为30000毫秒)。尝试将其设置为0
以禁用超时,只是为了检查请求是否花费了荒谬的长时间。
或者,也许尝试使用RunAndWaitForRequestFinishedAsync()
,因为在这种情况下,WaitForRequestFinishedAsync()
可能正在等待一个实际上从未启动的Task
。
英文:
From the docs, it appears that you can set the timeout time (defaulting to 30000ms if not defined) as the second argument in the method definition. Try setting this to 0
to disable the timeout, just to check that the request isn't taking an absurdly long time.
Alternatively, maybe try using RunAndWaitForRequestFinishedAsync()
, because in this scenario WaitForRequestFinishedAsync()
may be waiting on a Task
that was never actually started.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论