Foto von ThisIsEngineering:

Using Selenium within Github Actions

When working with Github Actions it can be useful to use Selenium. A common use case is for example the verification of a deployment (e.g. checking if a SPA is rendered correctly). With Selenium code, a user using a browser can be simulated.

Setting up the Chrome Driver

The Chrome Driver must be set up specifically to work correctly within a Github Action Runtime. This is the configuration I am currently using:

ChromeOptions options = new ChromeOptions();
WebDriver driver = new ChromeDriver(options);

Configuring the Github Action Pipeline

To execute the action we use the ubuntu-latest image. However, this image does not have Google Chrome or Selenium installed. This means we have to install these components before we can execute our code. Here is the sample code for Github Actions which shows how to do this:

name: Selenium Example on:

runs-on: ubuntu-latest
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
java-version: '17'
distribution: 'temurin'
cache: maven
- name: Setup Selenium
run: |
sudo wget -q -O - | sudo apt-key add - && \
sudo sh -c 'echo "deb [arch=amd64] stable main" >> /etc/apt/sources.list.d/google-chrome.list' && \
sudo apt-get -y update && \
sudo apt-get install -y google-chrome-stable && \
sudo apt-get install -yqq unzip && \
sudo wget -O /tmp/`curl -sS`/ && \
sudo unzip /tmp/ chromedriver -d /usr/local/bin/ && \
DISPLAY=:99 && \
sudo apt install -y python3-pip && \
sudo pip install --upgrade pip && \
sudo pip install selenium
- name: Build with Maven
run: cd my-selenium-app && mvn -DskipTests -B package --file pom.xml
- name: Execute Selenium app
run: cd my-selenium-app && java -jar target/my-selenium-app.jar update-index-flatfox

With this pipeline the installation of both Chrome and Selenium roughly takes about 17 seconds.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Aymen Furter

Aymen Furter

DevOps – Linux — Kubernetes –Azure — Java — JS — Apache Camel