不能启动超过 17 个 Selenium-webdrivers

Can't start more than 17 Selenium-webdrivers

我在 python 多线程环境中将 Selenium 与 ChromeDriver 结合使用。 在多处理开始之前,每个浏览器实例都已设置。可以毫无问题地启动 17 个浏览器,但如果超过 17 个实例就会失败。

这是浏览器的日志输出 webdriver.Chrome(service_log_path=self.session_logfile):

工作实例(实例 #17):

[…]
[1640642658.135][INFO]: [d95aa29866064789c167e42c4911ed36] RESPONSE SetTimeouts
[1640642658.136][INFO]: [d95aa29866064789c167e42c4911ed36] COMMAND Navigate {
   "url": "https://www.website.com"
}
[1640642658.136][INFO]: Waiting for pending navigations...
[1640642658.137][INFO]: Done waiting for pending navigations. Status: ok
[1640642658.417][INFO]: Waiting for pending navigations...
[1640642659.122][INFO]: Done waiting for pending navigations. Status: ok
[1640642659.122][INFO]: [d95aa29866064789c167e42c4911ed36] RESPONSE Navigate
[1640642659.127][INFO]: [d95aa29866064789c167e42c4911ed36] COMMAND DeleteAllCookies {

}
[1640642659.127][INFO]: Waiting for pending navigations...
[1640642659.128][INFO]: Done waiting for pending navigations. Status: ok
[…]

失败实例(实例 #18):

[…]
[1640642194.176][INFO]: [9148f58db0e76ea70186f0739b04e677] RESPONSE SetTimeouts
[1640642194.176][INFO]: [9148f58db0e76ea70186f0739b04e677] COMMAND Navigate {
   "url": "https://www.website.com"
}
[1640642194.176][INFO]: Waiting for pending navigations...
[1640642194.178][INFO]: Done waiting for pending navigations. Status: ok
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
[1640642194.122][INFO]: [330dd18a9973da505814eddae0cfd97d] COMMAND QuitAll {

}
[1640642194.172][INFO]: [330dd18a9973da505814eddae0cfd97d] RESPONSE QuitAll

我试过调试它,但不明白为什么会这样。我如何检索有关此实例 fails/quits 的原因的更多信息?

如果您要为 Python 测试使用多线程,您可以考虑使用“pytest-xdist”来为您处理多个进程:https://github.com/pytest-dev/pytest-xdist. And if you're using Selenium with Python and pytest, there's a framework that may simplify the Selenium test multithreading for you, "SeleniumBase": https://github.com/seleniumbase/SeleniumBase。它用作 pytest 插件,因此您可以使用 pytest-xdist 提供的 pytest 多线程参数,并且 运行 所有 Selenium Python 测试都根据需要进行多线程。例如:pytest -n 20 表示 20 个并行线程,假设您的机器有足够的内存。如果你的机器没有足够的内存,那么一定要使用更少的线程。启动大量浏览器 windows 可能会占用大量内存。