为什么在使用WaitForRequestFinishedAsync函数时我会收到超时异常?

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

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.

huangapple
  • 本文由 发表于 2023年6月16日 03:52:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/76485103.html
匿名

发表评论

匿名网友

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

确定