GitLab's CI/CD pipelines: Selenium Chrome driver failed to start: exited abnormally or google-chrome is no longer running, Chrome has crashed

I am running git lab ci cd pipeline for selenium Python UI automated tests. My tests are passing ok on my local. I have initialized Google Chrome using below code

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)

When I am running GitLab job, my pipeline is failing with below error

enter image description here

Below if the GitLab runner I can see used while running : enter image description here

I also tried to used remote driver and headless mode- In headless mode most of tests are failing. In remote mode, it not instantiating driver. Remove driver code as below

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

I am not sure if its happening due to gitlab runner. Or Do I need to create my custom gitlab runner to run on specific machine. I am running selenium UI tests , so not sure runner which is used in my case don’t have facility to run in GUI mode.

My gitlab pipeline

Thanks for taking the time to be thorough in your request, it really helps! :blush:

Any help from gitlab side?

Hi @newuserbk did you get the solution? I am also facing the same issue

The Chrome driver is trying to launch the browser in UI mode and start testing. The solution is to run the test cases with the chrome using the headless option.

I use this gitlab-ci. yml :

image: python:3.8-slim

stages:
  - scraping

variables:
  CHROME_BIN: "/usr/bin/google-chrome"

before_script:

  - apt-get update && apt-get install -y wget gnupg unzip

  - wget -O google-chrome.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
  - dpkg -i google-chrome.deb || apt-get -fy install

  - pip install -r requirements.txt

scraping_job:
  stage: scraping
  script:
    - python scrapping.py
  artifacts:
    paths:
      - data/scrapping_csv.csv

and in my .py file :

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service 
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager
import time
import pandas as pd

chrome_options = Options()
chrome_options.add_argument("--headless")          
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-dev-shm-usage")

service = Service(ChromeDriverManager().install())

driver = webdriver.Chrome(service=service, options=chrome_options)


driver.get("https://www.your_url/")```


it worked well

It’s because Gitlab runner works in different enviroment from local browser.
In that enviroment browser version is older even local browser version is valid so hard code the version of the browser driver.