【问题标题】:GitLab's CI/CD pipelines: Selenium Chrome driver failed to start: exited abnormally or google-chrome is no longer running, Chrome has crashedGitLab 的 CI/CD 管道:Selenium Chrome 驱动程序无法启动:异常退出或 google-chrome 不再运行,Chrome 已崩溃
【发布时间】:2021-11-25 07:14:46
【问题描述】:

我正在为 selenium Python UI 自动化测试运行 git lab ci cd 管道。我的测试在我的本地测试通过。我已经使用下面的代码初始化了谷歌浏览器

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 测试,所以不确定在我的案例中使用的 runner 没有在 GUI 模式下运行的设施。

我在这里发现了类似的问题-WebDriverException: Message: unknown error: Chrome failed to start: crashed error using ChromeDriver Chrome through Selenium Python on Amazon Linux

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

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

我正在使用带有图像 joyzoursky/python-chromedriver:3.8 的 -Docker 执行器旋转图像

【问题讨论】:

    标签: python-3.x selenium-webdriver gitlab gitlab-ci-runner cicd


    【解决方案1】:

    您可能缺少以下选项:

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

    如需更多灵感,请访问: WebDriverException: unknown error: DevToolsActivePort file doesn't exist while trying to initiate Chrome Browser

    【讨论】:

      猜你喜欢
      • 2023-02-14
      • 2021-12-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多