playwright - playwright-python - `handleSIGTERM=False` 导致 UnhandledPromiseRejectionWarning 并关闭浏览器
问题描述
我收到 UnhandledPromiseRejectionWarning 错误,并且在尝试模拟不应关闭浏览器的测试失败时关闭浏览器。
文档说我应该将handleSIGTERM设置为 False 并且它不应该在运行结束时关闭浏览器,对吧?所以我做到了(见代码示例)。
handleSIGTERM : Optional[bool] 在 SIGTERM 上关闭浏览器进程。默认为真。
Environment:
node v15.0.1
Python 3.8.0
MacOS Catalina 10.15.7
playwright 0.152.0
代码示例:
import asyncio
from playwright import async_playwright
async def main():
playwright = await async_playwright().start()
browser = await playwright.chromium.launch(headless=False, handleSIGTERM=False, handleSIGHUP=False)
page = await browser.newPage()
page.setDefaultTimeout(timeout=5000)
await page.goto('https://google.com/')
# the following row simulates test failure
await page.waitForSelector('input[name="q"]', state='hidden')
await browser.close()
await playwright.stop()
if __name__ == "__main__":
asyncio.run(main())
意外的行为是浏览器关闭并且节点显示以下输出:
(node:28715) UnhandledPromiseRejectionWarning: Error: write EPIPE
at afterWriteDispatched (internal/stream_base_commons.js:154:25)
at writeGeneric (internal/stream_base_commons.js:145:3)
at Socket._writeGeneric (net.js:786:11)
at Socket._write (net.js:798:8)
at doWrite (_stream_writable.js:403:12)
at writeOrBuffer (_stream_writable.js:387:5)
at Socket.Writable.write (_stream_writable.js:318:11)
at Transport.send (/snapshot/playwright-cli/node_modules/playwright/lib/protocol/transport.js:38:25)
at DispatcherConnection.onmessage (/snapshot/playwright-cli/lib/driver.js:49:61)
at DispatcherConnection.sendMessageToClient (/snapshot/playwright-cli/node_modules/playwright/lib/dispatchers/dispatcher.js:130:14)
(node:28715) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:28715) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:28715) UnhandledPromiseRejectionWarning: Error [ERR_STREAM_DESTROYED]: Cannot call write after a stream was destroyed
at doWrite (_stream_writable.js:399:19)
at writeOrBuffer (_stream_writable.js:387:5)
at Socket.Writable.write (_stream_writable.js:318:11)
at Transport.send (/snapshot/playwright-cli/node_modules/playwright/lib/protocol/transport.js:38:25)
at DispatcherConnection.onmessage (/snapshot/playwright-cli/lib/driver.js:49:61)
at DispatcherConnection.sendMessageToClient (/snapshot/playwright-cli/node_modules/playwright/lib/dispatchers/dispatcher.js:130:14)
at BrowserContextDispatcher._dispatchEvent (/snapshot/playwright-cli/node_modules/playwright/lib/dispatchers/dispatcher.js:70:26)
at CRBrowserContext.<anonymous> (/snapshot/playwright-cli/node_modules/playwright/lib/dispatchers/browserContextDispatcher.js:33:18)
at CRBrowserContext.emit (events.js:315:20)
at CRBrowserContext._didCloseInternal (/snapshot/playwright-cli/node_modules/playwright/lib/server/browserContext.js:102:14)
(node:28715) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
你知道我做错了什么吗?
解决方案
推荐阅读
- javascript - 使用选择过滤全日历事件
- api - 调用另一个 API 的 API 的 HTTP 方法是什么?
- eclipse - 在我新安装的 Eclipse 中,缺少 3 个文件夹。Java 资源、JAX-WAS Web 服务和部署描述符
- python - 是否有任何脚本或代码可以使用程序打开 Android 应用程序?
- python - 如何在python数据表中填充空值?
- assembly - MASM 不会插入带有某些 CPU 和 FPU 指令组合的 x87 WAIT 前缀
- google-chrome - 谷歌浏览器显示问题
- mongodb - 如何从另一个 mongodb 集合中获取字段并将这些字段值作为数组添加到当前集合中?
- javascript - React-router URL,路由节点/快递和文件结构
- gdb - 如何设置 gdb-multiarch 以支持 PowerPC 架构?