【发布时间】:2020-01-17 06:46:03
【问题描述】:
所以我使用了一个 while 循环,所以我的测试将在一个恒定循环中运行,直到我的后端崩溃。 我已经实现了 try and catch(error),所以任何前端崩溃,自动化都会刷新并继续运行
while(true){
try{
await page.waitFor(selector)
await page.click(selector)
}
catch(error){
console.log("FE crashed with\n\n" + error + "\n\nRefreshing page and continuing profile switching")
await page.reload(page);
continue;
}}
因此,实际上任何超时错误都会自动刷新页面并继续循环。 但我收到不同的崩溃错误
(node:6535) UnhandledPromiseRejectionWarning: Error: Page crashed!
at Page._onTargetCrashed (/home/raymond/node_modules/puppeteer/lib/Page.js:170:24)
at CDPSession.Page.client.on.event (/home/raymond/node_modules/puppeteer/lib/Page.js:125:56)
at CDPSession.emit (events.js:182:13)
at CDPSession._onMessage (/home/raymond/node_modules/puppeteer/lib/Connection.js:200:12)
at Connection._onMessage (/home/raymond/node_modules/puppeteer/lib/Connection.js:112:17)
at _tickCallback (internal/process/next_tick.js:43:7)
at listOnTimeout (timers.js:294:7)
at processTimers (timers.js:268:5)
(node:6535) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
我该如何处理这个错误?如果我手动刷新页面一切正常。 谢谢
【问题讨论】:
-
我看起来像你的 puppeteer “page” 在 “catch” 部分崩溃了,而且你里面没有另一个 “try...catch”。尝试处理此错误。有时 puppeteer 本身会崩溃、chromium 崩溃等……所以你也必须处理这些错误。例如,您可以关闭页面(或浏览器)并创建另一个页面(或浏览器)。
-
好的,我可以试试这个,但是我怎么知道系统崩溃了,我的意思是我的try and catch没有工作,所以try and catch整个循环?
-
我想尝试...catch 里面的catch,只是为了发出“await page.reload(page)”命令,因为我认为这是导致问题的原因。但是尝试...在浏览器创建中捕获 while() 会更好。
-
我试过尝试捕获while循环并没有解决问题我会尝试你的建议
-
你想要
await page.reload();,将页面作为选项传递是没有意义的。你可能想看看reload docs and options
标签: javascript node.js mocha.js puppeteer