Chrome 浏览器在从 chromedriver 启动时随机挂起
Chrome browser randomly hangs on start from chromedriver
我有几个使用 selenium/python 自动进行的测试。
测试是 运行 通过 teamcity,在你安装 Ubuntu 14.04 的 xfvb 驱动器中。
所有 28 个测试,当它们 运行 时,我看到一个进程 运行s Chrome(使用命令 ps auvvx | grep chrome | grep -v grep):
teamcity 31660 2.5 0.0 139000 8368 ? Sl 13:10 0:00 /opt/vendors/chromedriver/webdriver --port=50695 --log-path=chromedriverEnBundlesTests.log
teamcity 31680 27.3 0.2 625396 70948 ? Rl 13:10 0:00 /opt/google/chrome/chrome --disable-background-networking --disable-client-side-phishing-detection --disable-default-apps --disable-extensions --disable-gpu --disable-hang-monitor --disable-infobars --disable-popup-blocking --disable-prompt-on-repost --disable-sync --disable-web-resources --enable-logging --ignore-certificate-errors --lang=en --load-component-extension=/var/tainted/build-agent/temp/buildTmp/.org.chromium.Chromium.EnML8k/internal --log-level=0 --metrics-recording-only --no-first-run --password-store=basic --remote-debugging-port=12388 --safebrowsing-disable-auto-update --test-type=webdriver --use-mock-keychain --user-data-dir=/var/tainted/build-agent/temp/buildTmp/.org.chromium.Chromium.65DCDh --v=1 --verbose --–-single-process data:,
teamcity 31693 1.0 0.0 335680 26132 ? S 13:10 0:00 /opt/google/chrome/chrome --type=zygote --enable-logging --log-level=0 --v=1 --user-data-dir=/var/tainted/build-agent/temp/buildTmp/.org.chromium.Chromium.65DCDh
teamcity 31696 0.0 0.0 26192 2068 ? S 13:10 0:00 /opt/google/chrome/nacl_helper
teamcity 31699 0.0 0.0 335680 8448 ? S 13:10 0:00 /opt/google/chrome/chrome --type=zygote --enable-logging --log-level=0 --v=1 --user-data-dir=/var/tainted/build-agent/temp/buildTmp/.org.chromium.Chromium.65DCDh
teamcity 31749 2.5 0.0 706404 31408 ? Sl 13:10 0:00 /opt/google/chrome/chrome --type=renderer --enable-logging --log-level=0 --test-type=webdriver --v=1 --primordial-pipe-token=1DE74651242181EC5B45C60E6057984B --lang=en-US --user-data-dir=/var/tainted/build-agent/temp/buildTmp/.org.chromium.Chromium.65DCDh --extension-process --disable-client-side-phishing-detection --enable-offline-auto-reload --enable-offline-auto-reload-visible-only --enable-pinch --num-raster-threads=4 --enable-main-frame-before-activation --content-image-texture-target=0,0,3553;0,1,3553;0,2,3553;0,3,3553;0,4,3553;0,5,3553;0,6,3553;0,7,3553;0,8,3553;0,9,3553;0,10,3553;0,11,3553;0,12,3553;0,13,3553;0,14,3553;0,15,3553;1,0,3553;1,1,3553;1,2,3553;1,3,3553;1,4,3553;1,5,3553;1,6,3553;1,7,3553;1,8,3553;1,9,3553;1,10,3553;1,11,3553;1,12,3553;1,13,3553;1,14,3553;1,15,3553;2,0,3553;2,1,3553;2,2,3553;2,3,3553;2,4,3553;2,5,3553;2,6,3553;2,7,3553;2,8,3553;2,9,3553;2,10,3553;2,11,3553;2,12,3553;2,13,3553;2,14,3553;2,15,3553;3,0,3553;3,1,3553;3,2,3553;3,3,3553;3,4,3553;3,5,3553;3,6,3553;3,7,3553;3,8,3553;3,9,3553;3,10,3553;3,11,3553;3,12,3553;3,13,3553;3,14,3553;3,15,3553 --disable-accelerated-video-decode --disable-webrtc-hw-encoding --disable-gpu-compositing --service-request-channel-token=1DE74651242181EC5B45C60E6057984B --renderer-client-id=2 --v8-natives-passed-by-fd --v8-snapshot-passed-by-fd
teamcity 31772 14.5 0.1 734440 46176 ? Sl 13:10 0:00 /opt/google/chrome/chrome --type=renderer --enable-logging --log-level=0 --test-type=webdriver --v=1 --primordial-pipe-token=29BAB961D66EB1226D9E5A0151BC00FD --lang=en-US --user-data-dir=/var/tainted/build-agent/temp/buildTmp/.org.chromium.Chromium.65DCDh --disable-client-side-phishing-detection --enable-offline-auto-reload --enable-offline-auto-reload-visible-only --enable-pinch --num-raster-threads=4 --enable-main-frame-before-activation --content-image-texture-target=0,0,3553;0,1,3553;0,2,3553;0,3,3553;0,4,3553;0,5,3553;0,6,3553;0,7,3553;0,8,3553;0,9,3553;0,10,3553;0,11,3553;0,12,3553;0,13,3553;0,14,3553;0,15,3553;1,0,3553;1,1,3553;1,2,3553;1,3,3553;1,4,3553;1,5,3553;1,6,3553;1,7,3553;1,8,3553;1,9,3553;1,10,3553;1,11,3553;1,12,3553;1,13,3553;1,14,3553;1,15,3553;2,0,3553;2,1,3553;2,2,3553;2,3,3553;2,4,3553;2,5,3553;2,6,3553;2,7,3553;2,8,3553;2,9,3553;2,10,3553;2,11,3553;2,12,3553;2,13,3553;2,14,3553;2,15,3553;3,0,3553;3,1,3553;3,2,3553;3,3,3553;3,4,3553;3,5,3553;3,6,3553;3,7,3553;3,8,3553;3,9,3553;3,10,3553;3,11,3553;3,12,3553;3,13,3553;3,14,3553;3,15,3553 --disable-accelerated-video-decode --disable-webrtc-hw-encoding --disable-gpu-compositing --service-request-channel-token=29BAB961D66EB1226D9E5A0151BC00FD --renderer-client-id=4 --v8-natives-passed-by-fd --v8-snapshot-passed-by-fd
但有时(在随机测试中发生)chrome 无法启动。未启动 - 表示 chrome 进程已启动,但 chrome window 未出现在屏幕上(我正在通过 VNCviewer 观看 xvfb)。然而,虽然 chrome 个进程已启动,但它们看起来很奇怪:
teamcity 30480 0.0 0.0 135880 7956 ? Sl 09:24 0:00 /opt/vendors/chromedriver/webdriver --port=34227 --log-path=chromedriverBundlesTests.log
teamcity 30485 0.0 0.1 558912 53480 ? Sl 09:24 0:00 /opt/google/chrome/chrome --disable-background-networking --disable-client-side-phishing-detection --disable-default-apps --disable-extensions --disable-gpu --disable-hang-monitor --disable-infobars --disable-popup-blocking --disable-prompt-on-repost --disable-sync --disable-web-resources --enable-logging --ignore-certificate-errors --lang=en --load-component-extension=/var/tainted/build-agent/temp/buildTmp/.org.chromium.Chromium.xt55yX/internal --log-level=0 --metrics-recording-only --no-first-run --password-store=basic --remote-debugging-port=12290 --safebrowsing-disable-auto-update --test-type=webdriver --use-mock-keychain --user-agent=CustomUserAgent --user-data-dir=/var/tainted/build-agent/temp/buildTmp/.org.chromium.Chromium.pFyqzd --v=1 --verbose data:,
teamcity 30496 0.0 0.0 335680 26128 ? S 09:24 0:00 /opt/google/chrome/chrome --type=zygote --enable-logging --log-level=0 --v=1 --user-agent=CustomUserAgent --user-data-dir=/var/tainted/build-agent/temp/buildTmp/.org.chromium.Chromium.pFyqzd
teamcity 30500 0.0 0.0 26192 2064 ? S 09:24 0:00 /opt/google/chrome/nacl_helper
teamcity 30503 0.0 0.0 335680 8432 ? S 09:24 0:00 /opt/google/chrome/chrome --type=zygote --enable-logging --log-level=0 --v=1 --user-agent=CustomUserAgent --user-data-dir=/var/tainted/build-agent/temp/buildTmp/.org.chromium.Chromium.pFyqzd
teamcity 30535 0.0 0.0 343876 10328 ? Sl 09:24 0:00 /opt/google/chrome/chrome --type=renderer --enable-logging --log-level=0 --test-type=webdriver --v=1 --primordial-pipe-token=059B5A32F7C1B61E6E6C194E4D3A0DC8 --lang=en-US --user-agent=CustomUserAgent --user-data-dir=/var/tainted/build-agent/temp/buildTmp/.org.chromium.Chromium.pFyqzd --disable-client-side-phishing-detection --enable-offline-auto-reload --enable-offline-auto-reload-visible-only --enable-pinch --num-raster-threads=4 --enable-main-frame-before-activation --content-image-texture-target=0,0,3553;0,1,3553;0,2,3553;0,3,3553;0,4,3553;0,5,3553;0,6,3553;0,7,3553;0,8,3553;0,9,3553;0,10,3553;0,11,3553;0,12,3553;0,13,3553;0,14,3553;0,15,3553;1,0,3553;1,1,3553;1,2,3553;1,3,3553;1,4,3553;1,5,3553;1,6,3553;1,7,3553;1,8,3553;1,9,3553;1,10,3553;1,11,3553;1,12,3553;1,13,3553;1,14,3553;1,15,3553;2,0,3553;2,1,3553;2,2,3553;2,3,3553;2,4,3553;2,5,3553;2,6,3553;2,7,3553;2,8,3553;2,9,3553;2,10,3553;2,11,3553;2,12,3553;2,13,3553;2,14,3553;2,15,3553;3,0,3553;3,1,3553;3,2,3553;3,3,3553;3,4,3553;3,5,3553;3,6,3553;3,7,3553;3,8,3553;3,9,3553;3,10,3553;3,11,3553;3,12,3553;3,13,3553;3,14,3553;3,15,3553 --disable-accelerated-video-decode --disable-webrtc-hw-encoding --disable-gpu-compositing --service-request-channel-token=059B5A32F7C1B61E6E6C194E4D3A0DC8 --renderer-client-id=3 --v8-natives-passed-by-fd --v8-snapshot-passed-by-fd
teamcity 30537 0.2 0.0 558668 14976 ? S 09:24 0:04 /opt/google/chrome/chrome --disable-background-networking --disable-client-side-phishing-detection --disable-default-apps --disable-extensions --disable-gpu --disable-hang-monitor --disable-infobars --disable-popup-blocking --disable-prompt-on-repost --disable-sync --disable-web-resources --enable-logging --ignore-certificate-errors --lang=en --load-component-extension=/var/tainted/build-agent/temp/buildTmp/.org.chromium.Chromium.xt55yX/internal --log-level=0 --metrics-recording-only --no-first-run --password-store=basic --remote-debugging-port=12290 --safebrowsing-disable-auto-update --test-type=webdriver --use-mock-keychain --user-agent=CustomUserAgent --user-data-dir=/var/tainted/build-agent/temp/buildTmp/.org.chromium.Chromium.pFyqzd --v=1 --verbose data:,
在这种状态下,chrome 可能会持续数小时或数天。
下面是一个测试示例,我如何 运行 Chrome from chromedriver:
def setUp(self):
os.environ["CHROME_LOG_FILE"] = 'DeTeasersTests.log'
chrome_options = Options()
chrome_options.add_argument('--verbose')
chrome_options.add_argument('--lang=en')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--enable-logging')
chrome_options.add_argument('--v=1')
chrome_options.add_argument('--ignore-certificate-errors')
chrome_options.add_argument('--disable-extensions')
if platform.system() == 'Linux':
service_log_path = "chromedriverDeTeasersTests.log"
self.driver = webdriver.Chrome('/opt/vendors/chromedriver/webdriver', chrome_options=chrome_options,
service_log_path=service_log_path)
elif platform.system() == 'Windows':
self.driver = webdriver.Chrome('chromedriver.exe', chrome_options=chrome_options,
service_log_path='chromedriver.log')
self.base_url = BASE_DE_URL
self.driver.get(self.base_url)
和测试尾部:
def tearDown(self):
self.driver.close()
time.sleep(5)
self.driver.quit()
请帮忙看看错误是什么?目前测试 运行 在 2/3 的情况下挂起。 Windows 一切正常。
p.s。如果我用英文写错了,我很抱歉。
我的母语是俄语,我在俄语互联网上寻找解决方案,但一无所获。
p.p.s。我已经尝试了很多方法来解决这个问题:
使用 chrome 的参数(--no-sandbox、--single-process、--process-per-site、--disable-gpu 等);
编写和分析 chrome 和 chrome 驱动程序的日志 - 但日志没有异常或错误。
已解决
https://bugs.chromium.org/p/chromedriver/issues/detail?id=1699
tl;博士
我在脚本中添加了这个环境变量的定义,像这样:
def setUp(self):
os.environ["DBUS_SESSION_BUS_ADDRESS"] = '/dev/null'
chrome_options = Options()
这真的很有帮助。
Build 大约启动了 20 次,都成功通过了,尽管在此之前,chrome 肯定挂在 3-5 次启动。
我有几个使用 selenium/python 自动进行的测试。 测试是 运行 通过 teamcity,在你安装 Ubuntu 14.04 的 xfvb 驱动器中。 所有 28 个测试,当它们 运行 时,我看到一个进程 运行s Chrome(使用命令 ps auvvx | grep chrome | grep -v grep):
teamcity 31660 2.5 0.0 139000 8368 ? Sl 13:10 0:00 /opt/vendors/chromedriver/webdriver --port=50695 --log-path=chromedriverEnBundlesTests.log
teamcity 31680 27.3 0.2 625396 70948 ? Rl 13:10 0:00 /opt/google/chrome/chrome --disable-background-networking --disable-client-side-phishing-detection --disable-default-apps --disable-extensions --disable-gpu --disable-hang-monitor --disable-infobars --disable-popup-blocking --disable-prompt-on-repost --disable-sync --disable-web-resources --enable-logging --ignore-certificate-errors --lang=en --load-component-extension=/var/tainted/build-agent/temp/buildTmp/.org.chromium.Chromium.EnML8k/internal --log-level=0 --metrics-recording-only --no-first-run --password-store=basic --remote-debugging-port=12388 --safebrowsing-disable-auto-update --test-type=webdriver --use-mock-keychain --user-data-dir=/var/tainted/build-agent/temp/buildTmp/.org.chromium.Chromium.65DCDh --v=1 --verbose --–-single-process data:,
teamcity 31693 1.0 0.0 335680 26132 ? S 13:10 0:00 /opt/google/chrome/chrome --type=zygote --enable-logging --log-level=0 --v=1 --user-data-dir=/var/tainted/build-agent/temp/buildTmp/.org.chromium.Chromium.65DCDh
teamcity 31696 0.0 0.0 26192 2068 ? S 13:10 0:00 /opt/google/chrome/nacl_helper
teamcity 31699 0.0 0.0 335680 8448 ? S 13:10 0:00 /opt/google/chrome/chrome --type=zygote --enable-logging --log-level=0 --v=1 --user-data-dir=/var/tainted/build-agent/temp/buildTmp/.org.chromium.Chromium.65DCDh
teamcity 31749 2.5 0.0 706404 31408 ? Sl 13:10 0:00 /opt/google/chrome/chrome --type=renderer --enable-logging --log-level=0 --test-type=webdriver --v=1 --primordial-pipe-token=1DE74651242181EC5B45C60E6057984B --lang=en-US --user-data-dir=/var/tainted/build-agent/temp/buildTmp/.org.chromium.Chromium.65DCDh --extension-process --disable-client-side-phishing-detection --enable-offline-auto-reload --enable-offline-auto-reload-visible-only --enable-pinch --num-raster-threads=4 --enable-main-frame-before-activation --content-image-texture-target=0,0,3553;0,1,3553;0,2,3553;0,3,3553;0,4,3553;0,5,3553;0,6,3553;0,7,3553;0,8,3553;0,9,3553;0,10,3553;0,11,3553;0,12,3553;0,13,3553;0,14,3553;0,15,3553;1,0,3553;1,1,3553;1,2,3553;1,3,3553;1,4,3553;1,5,3553;1,6,3553;1,7,3553;1,8,3553;1,9,3553;1,10,3553;1,11,3553;1,12,3553;1,13,3553;1,14,3553;1,15,3553;2,0,3553;2,1,3553;2,2,3553;2,3,3553;2,4,3553;2,5,3553;2,6,3553;2,7,3553;2,8,3553;2,9,3553;2,10,3553;2,11,3553;2,12,3553;2,13,3553;2,14,3553;2,15,3553;3,0,3553;3,1,3553;3,2,3553;3,3,3553;3,4,3553;3,5,3553;3,6,3553;3,7,3553;3,8,3553;3,9,3553;3,10,3553;3,11,3553;3,12,3553;3,13,3553;3,14,3553;3,15,3553 --disable-accelerated-video-decode --disable-webrtc-hw-encoding --disable-gpu-compositing --service-request-channel-token=1DE74651242181EC5B45C60E6057984B --renderer-client-id=2 --v8-natives-passed-by-fd --v8-snapshot-passed-by-fd
teamcity 31772 14.5 0.1 734440 46176 ? Sl 13:10 0:00 /opt/google/chrome/chrome --type=renderer --enable-logging --log-level=0 --test-type=webdriver --v=1 --primordial-pipe-token=29BAB961D66EB1226D9E5A0151BC00FD --lang=en-US --user-data-dir=/var/tainted/build-agent/temp/buildTmp/.org.chromium.Chromium.65DCDh --disable-client-side-phishing-detection --enable-offline-auto-reload --enable-offline-auto-reload-visible-only --enable-pinch --num-raster-threads=4 --enable-main-frame-before-activation --content-image-texture-target=0,0,3553;0,1,3553;0,2,3553;0,3,3553;0,4,3553;0,5,3553;0,6,3553;0,7,3553;0,8,3553;0,9,3553;0,10,3553;0,11,3553;0,12,3553;0,13,3553;0,14,3553;0,15,3553;1,0,3553;1,1,3553;1,2,3553;1,3,3553;1,4,3553;1,5,3553;1,6,3553;1,7,3553;1,8,3553;1,9,3553;1,10,3553;1,11,3553;1,12,3553;1,13,3553;1,14,3553;1,15,3553;2,0,3553;2,1,3553;2,2,3553;2,3,3553;2,4,3553;2,5,3553;2,6,3553;2,7,3553;2,8,3553;2,9,3553;2,10,3553;2,11,3553;2,12,3553;2,13,3553;2,14,3553;2,15,3553;3,0,3553;3,1,3553;3,2,3553;3,3,3553;3,4,3553;3,5,3553;3,6,3553;3,7,3553;3,8,3553;3,9,3553;3,10,3553;3,11,3553;3,12,3553;3,13,3553;3,14,3553;3,15,3553 --disable-accelerated-video-decode --disable-webrtc-hw-encoding --disable-gpu-compositing --service-request-channel-token=29BAB961D66EB1226D9E5A0151BC00FD --renderer-client-id=4 --v8-natives-passed-by-fd --v8-snapshot-passed-by-fd
但有时(在随机测试中发生)chrome 无法启动。未启动 - 表示 chrome 进程已启动,但 chrome window 未出现在屏幕上(我正在通过 VNCviewer 观看 xvfb)。然而,虽然 chrome 个进程已启动,但它们看起来很奇怪:
teamcity 30480 0.0 0.0 135880 7956 ? Sl 09:24 0:00 /opt/vendors/chromedriver/webdriver --port=34227 --log-path=chromedriverBundlesTests.log
teamcity 30485 0.0 0.1 558912 53480 ? Sl 09:24 0:00 /opt/google/chrome/chrome --disable-background-networking --disable-client-side-phishing-detection --disable-default-apps --disable-extensions --disable-gpu --disable-hang-monitor --disable-infobars --disable-popup-blocking --disable-prompt-on-repost --disable-sync --disable-web-resources --enable-logging --ignore-certificate-errors --lang=en --load-component-extension=/var/tainted/build-agent/temp/buildTmp/.org.chromium.Chromium.xt55yX/internal --log-level=0 --metrics-recording-only --no-first-run --password-store=basic --remote-debugging-port=12290 --safebrowsing-disable-auto-update --test-type=webdriver --use-mock-keychain --user-agent=CustomUserAgent --user-data-dir=/var/tainted/build-agent/temp/buildTmp/.org.chromium.Chromium.pFyqzd --v=1 --verbose data:,
teamcity 30496 0.0 0.0 335680 26128 ? S 09:24 0:00 /opt/google/chrome/chrome --type=zygote --enable-logging --log-level=0 --v=1 --user-agent=CustomUserAgent --user-data-dir=/var/tainted/build-agent/temp/buildTmp/.org.chromium.Chromium.pFyqzd
teamcity 30500 0.0 0.0 26192 2064 ? S 09:24 0:00 /opt/google/chrome/nacl_helper
teamcity 30503 0.0 0.0 335680 8432 ? S 09:24 0:00 /opt/google/chrome/chrome --type=zygote --enable-logging --log-level=0 --v=1 --user-agent=CustomUserAgent --user-data-dir=/var/tainted/build-agent/temp/buildTmp/.org.chromium.Chromium.pFyqzd
teamcity 30535 0.0 0.0 343876 10328 ? Sl 09:24 0:00 /opt/google/chrome/chrome --type=renderer --enable-logging --log-level=0 --test-type=webdriver --v=1 --primordial-pipe-token=059B5A32F7C1B61E6E6C194E4D3A0DC8 --lang=en-US --user-agent=CustomUserAgent --user-data-dir=/var/tainted/build-agent/temp/buildTmp/.org.chromium.Chromium.pFyqzd --disable-client-side-phishing-detection --enable-offline-auto-reload --enable-offline-auto-reload-visible-only --enable-pinch --num-raster-threads=4 --enable-main-frame-before-activation --content-image-texture-target=0,0,3553;0,1,3553;0,2,3553;0,3,3553;0,4,3553;0,5,3553;0,6,3553;0,7,3553;0,8,3553;0,9,3553;0,10,3553;0,11,3553;0,12,3553;0,13,3553;0,14,3553;0,15,3553;1,0,3553;1,1,3553;1,2,3553;1,3,3553;1,4,3553;1,5,3553;1,6,3553;1,7,3553;1,8,3553;1,9,3553;1,10,3553;1,11,3553;1,12,3553;1,13,3553;1,14,3553;1,15,3553;2,0,3553;2,1,3553;2,2,3553;2,3,3553;2,4,3553;2,5,3553;2,6,3553;2,7,3553;2,8,3553;2,9,3553;2,10,3553;2,11,3553;2,12,3553;2,13,3553;2,14,3553;2,15,3553;3,0,3553;3,1,3553;3,2,3553;3,3,3553;3,4,3553;3,5,3553;3,6,3553;3,7,3553;3,8,3553;3,9,3553;3,10,3553;3,11,3553;3,12,3553;3,13,3553;3,14,3553;3,15,3553 --disable-accelerated-video-decode --disable-webrtc-hw-encoding --disable-gpu-compositing --service-request-channel-token=059B5A32F7C1B61E6E6C194E4D3A0DC8 --renderer-client-id=3 --v8-natives-passed-by-fd --v8-snapshot-passed-by-fd
teamcity 30537 0.2 0.0 558668 14976 ? S 09:24 0:04 /opt/google/chrome/chrome --disable-background-networking --disable-client-side-phishing-detection --disable-default-apps --disable-extensions --disable-gpu --disable-hang-monitor --disable-infobars --disable-popup-blocking --disable-prompt-on-repost --disable-sync --disable-web-resources --enable-logging --ignore-certificate-errors --lang=en --load-component-extension=/var/tainted/build-agent/temp/buildTmp/.org.chromium.Chromium.xt55yX/internal --log-level=0 --metrics-recording-only --no-first-run --password-store=basic --remote-debugging-port=12290 --safebrowsing-disable-auto-update --test-type=webdriver --use-mock-keychain --user-agent=CustomUserAgent --user-data-dir=/var/tainted/build-agent/temp/buildTmp/.org.chromium.Chromium.pFyqzd --v=1 --verbose data:,
在这种状态下,chrome 可能会持续数小时或数天。 下面是一个测试示例,我如何 运行 Chrome from chromedriver:
def setUp(self):
os.environ["CHROME_LOG_FILE"] = 'DeTeasersTests.log'
chrome_options = Options()
chrome_options.add_argument('--verbose')
chrome_options.add_argument('--lang=en')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--enable-logging')
chrome_options.add_argument('--v=1')
chrome_options.add_argument('--ignore-certificate-errors')
chrome_options.add_argument('--disable-extensions')
if platform.system() == 'Linux':
service_log_path = "chromedriverDeTeasersTests.log"
self.driver = webdriver.Chrome('/opt/vendors/chromedriver/webdriver', chrome_options=chrome_options,
service_log_path=service_log_path)
elif platform.system() == 'Windows':
self.driver = webdriver.Chrome('chromedriver.exe', chrome_options=chrome_options,
service_log_path='chromedriver.log')
self.base_url = BASE_DE_URL
self.driver.get(self.base_url)
和测试尾部:
def tearDown(self):
self.driver.close()
time.sleep(5)
self.driver.quit()
请帮忙看看错误是什么?目前测试 运行 在 2/3 的情况下挂起。 Windows 一切正常。
p.s。如果我用英文写错了,我很抱歉。 我的母语是俄语,我在俄语互联网上寻找解决方案,但一无所获。 p.p.s。我已经尝试了很多方法来解决这个问题: 使用 chrome 的参数(--no-sandbox、--single-process、--process-per-site、--disable-gpu 等); 编写和分析 chrome 和 chrome 驱动程序的日志 - 但日志没有异常或错误。
已解决 https://bugs.chromium.org/p/chromedriver/issues/detail?id=1699
tl;博士
我在脚本中添加了这个环境变量的定义,像这样:
def setUp(self):
os.environ["DBUS_SESSION_BUS_ADDRESS"] = '/dev/null'
chrome_options = Options()
这真的很有帮助。 Build 大约启动了 20 次,都成功通过了,尽管在此之前,chrome 肯定挂在 3-5 次启动。