GitLab 的 CI/CD 管道:Selenium Chrome 驱动程序启动失败:异常退出或 google-chrome 不再运行,Chrome 崩溃了

问题描述 投票:0回答:2

我正在运行 git lab ci cd pipeline 来进行 selenium Python UI 自动化测试。我的测试在本地顺利通过。我已经使用下面的代码初始化了 Google Chrome

driver = chromedriver_autoinstaller.install()
options = webdriver.ChromeOptions()
prefs = {'profile.default_content_setting_values.automatic_downloads': 1}
options.add_experimental_option("prefs", prefs)
driver = webdriver.Chrome(options=options)

当我运行 GitLab 作业时,我的管道失败并出现以下错误

下面是我在运行时看到的 GitLab 运行程序:

我还尝试使用远程驱动程序和无头模式- 在无头模式下,大多数测试都会失败。在远程模式下,它不实例化驱动程序。删除驱动代码如下

elif self.browser == 'remote':
driver = webdriver.Remote(options=webdriver.ChromeOptions(), command_executor='http://selenium__standalone-chrome:4444/wd/hub')

我不确定这是否是由于 gitlab runner 造成的。或者我是否需要创建自定义 gitlab 运行程序才能在特定机器上运行。 我正在运行 selenium UI 测试,因此不确定在我的情况下使用的运行器是否具有在 GUI 模式下运行的设施。

我在这里发现了类似的问题 - WebDriverException:消息:未知错误:Chrome 无法启动:在 Amazon Linux 上通过 Selenium Python 使用 ChromeDriver Chrome 发生崩溃错误

尝试了下面的代码,但仍然是同样的问题

    options = Options()
    options.binary_location = '/usr/bin/google-chrome'
    driver = webdriver.Chrome(options=options, 
    executable_path='/usr/local/bin/chromedriver')

我正在使用 -Docker 执行器与图像 Joyzoursky/python-chromedriver:3.8 旋转图像

python-3.x selenium-webdriver gitlab gitlab-ci-runner cicd
2个回答
1
投票

您可能缺少以下选项:

    options = webdriver.ChromeOptions()
    options.add_argument('--no-sandbox')
    options.add_argument('--disable-dev-shm-usage')

欲了解更多灵感,请访问: WebDriverException:未知错误:尝试启动 Chrome 浏览器时 DevToolsActivePort 文件不存在


0
投票

我也遇到了和你一样的问题。然而,我的根本问题是因为在 /usr/bin/google-chrome.conf 中找不到 chrome 浏览器。我的解决方案深受这篇文章如何在 GitLab CI/CD 上安装 chrome-webdriver 的启发。截至目前,Ubuntu 上的 chrome 稳定版本为 119.0.6045.105-1,请确保您的驱动版本与您的驱动兼容。

这是我的 .gitlab-ci.yml 文件:

  before_script:
  - apt-get update -qy
  - apt-get install -y default-jre
  - apt-get update
  - apt-get install -y wget unzip curl

  # Install or update Google Chrome
  - CHROME_VERSION="119.0.6045.105-1"
  # Install Google Chrome
  - wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
  - dpkg -i google-chrome-stable_current_amd64.deb || apt --fix-broken install -y
  - google-chrome-stable --version

只要我的2分钱! :D

© www.soinside.com 2019 - 2024. All rights reserved.