我有几个使用selenium / python自动化的测试。 测试通过teamcity运行,在xfvb驱动器中安装了Ubuntu 14.04。 所有28个测试,当它们运行时,我看到一个运行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窗口未出现在屏幕上(我通过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:,
并且在这种状态下,铬可能会持续数小时或数天。 下面是一个测试示例,我如何从chromedriver运行Chrome:
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和chromedriver的日志 - 但是日志没有例外或错误。
答案 0 :(得分:2)
已经解决了 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次发布时挂起。