I currently have a project, where Flutter Integration Tests are required to be run on a GitLab pipeline. I initiate the download/install of Chrome and ChromeDriver via .gitlab-ci.yml
file, which appears to work successfully. I then try and start ChromeDriver with chromedriver --port=4444
before running my first test. The error received is:
> $ chromedriver --port=4444 /bin/bash: line 266: chromedriver: command
> not found
How do I initiate ChromeDriver in this scenario?
# Code to start chromedriver
.webapp:test: &webapp_test
image: $CI_REGISTRY_IMAGE/flutter:latest
script:
- apt-get update && apt-get install -y jq
- cd $APP_DIR
- cd /chromedriver/
- chromedriver --port=4444
FYI, code to install Chrome and ChromeDriver:
webapp:test:
extends: .webapp:test
stage: test
allow_failure: true
before_script:
# Chrome and ChromeDriver dependencies
- cd $APP_DIR
- apt-get install -y wget unzip
- wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
- echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list
# Update the package list
- apt-get update -y
# Download and Install chrome
- wget --no-verbose -O /tmp/chrome.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb && apt install -y /tmp/chrome.deb && rm /tmp/chrome.deb
# Download and install Chromedriver
- mkdir /chromedriver
- wget -q --continue -P /chromedriver "https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/120.0.6099.109/linux64/chromedriver-linux64.zip"
- unzip /chromedriver/chromedriver* -d chromedriver
Thanks, I am new to this as you can probably tell
Suppose that you want to run the following script:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("--no-sandbox")
options.add_argument("--headless")
options.add_argument("--window-size=1920,1080")
driver = webdriver.Chrome(options=options)
driver.get('http://www.example.com')
print(driver.page_source)
The GitLab CI setup could be something like this:
chrome:
image: python:3.11.4
stage: test
before_script:
- apt-get update && apt-get install -y wget unzip
# Chrome
- wget -q https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
- apt install -y ./google-chrome-stable_current_amd64.deb
- rm google-chrome-stable_current_amd64.deb
- ln -s /opt/google/chrome/chrome /usr/local/bin/
# Chromedriver
- wget -q https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/120.0.6099.109/linux64/chromedriver-linux64.zip
- unzip -j chromedriver-linux64.zip chromedriver-linux64/chromedriver
- rm chromedriver-linux64.zip
- mv chromedriver /usr/local/bin/
- chrome --version
- chromedriver --version
- pip3 install selenium
script:
- python3 run.py
Script runs and dumps contents of http://www.example.com.
You can find more details in here, which I have updated to address precisely this question.