Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Selenium with chrome in pipelines

evan.hicken December 17, 2020

I am able to build a docker images with my selenium tests and run them on my local docker instance without any errors. When I use the same image in pipelines however I get the error below. Has anyone had anyluck getting chrome to run?


org.openqa.selenium.NoSuchSessionException: invalid session idBuild info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:19:58.91Z'System info: host: '76c81c59-2ec6-44f9-91db-fb13626d5dbb-gqswg', ip: '10.36.112.198', os.name: 'Linux', os.arch: 'amd64', os.version: '5.4.72-flatcar', java.version: '1.8.0_275'Driver info: org.openqa.selenium.chrome.ChromeDriverCapabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 87.0.4280.88, chrome: {chromedriverVersion: 87.0.4280.88 (89e2380a3e36c..., userDataDir: /tmp/.com.google.Chrome.6FdbbO}, goog:chromeOptions: {debuggerAddress: localhost:41187}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: LINUX, platformName: LINUX, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:virtualAuthenticators: true}Session ID: 28201cd2bee5172666f4d1a104b5219d*** Element info: {Using=css selector, value=a.cc-dismiss}

Resources I have read:
BitBucket Pipelines - Selenium (atlassian.com)
Solved: Setting up pipelines with selenium (atlassian.com)
Run selenium UI tests in Docker container | by Yiquan Zhou | Medium

and many other forum posts.

Docker File:

FROM openjdk:8
USER root

RUN apt-get -qqy update
RUN apt-get -qqy install apt-utils

##########################################
# Install Xvfb, curl, and chrome browser
##########################################
RUN apt-get update
RUN apt-get -y install xvfb curl
RUN curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add
RUN echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list
RUN apt-get -y update
RUN apt-get -y install google-chrome-stable

##########################################
# Install the entry script setup xvfb
##########################################
ADD xvfb.init /etc/init.d/xvfb
RUN chmod +x /etc/init.d/xvfb
ENV DISPLAY :99
RUN export DISPLAY
RUN update-rc.d xvfb defaults
RUN mkdir /entryFolder
ADD entry.sh /entryFolder
RUN chmod +x /entryFolder/entry.sh

 

xvfb.init File:

#!/bin/bash
#
#
### BEGIN INIT INFO
# Provides: Xvfb graphics
# Required-Start: $local_fs $network
# Required-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: xvfb
# Description: Provides the xvfb graphics to run off screen.
### END INIT INFO

XVFB=/usr/bin/Xvfb
XVFBARGS=":99 -screen 0 1280x1024x24 -ac +extension GLX +render -noreset"

PIDFILE=/var/run/xvfb.pid
case "$1" in
start)
echo -n "Starting virtual X frame buffer: Xvfb"
start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile --background --exec $XVFB -- $XVFBARGS
echo "."
;;
stop)
echo -n "Stopping virtual X frame buffer: Xvfb"
start-stop-daemon --stop --quiet --pidfile $PIDFILE
echo "."
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: /etc/init.d/xvfb {start|stop|restart}"
exit 1
esac

exit 0

entry.sh file

#!/bin/bash
# Simple script to start up the Xvfb service.

# Startup the Xvfb service so we have a UI
service xvfb start

# Wait for Xvfb
MAX_ATTEMPTS=120 # About 60 seconds
COUNT=0
echo -n "Waiting for Xvfb to be ready on display ${DISPLAY}..."
while ! xdpyinfo -display ${DISPLAY} >/dev/null 2>&1; do
echo -n "."
sleep 0.50s
COUNT=$(( COUNT + 1 ))
if [ "${COUNT}" -ge "${MAX_ATTEMPTS}" ]; then
echo " Gave up waiting for X server on ${DISPLAY}"
exit 1
fi
done
echo -n " Done - Xvfb is ready!"

Bitbucket-pipelines.yml script:

script:
- sh /entryFolder/entry.sh
- git clone <MY_SELENIUM_TEST_REPO>
- cd <MY_SELENIUM_TEST_REPO>
- chmod +x gradlew
- ./gradlew test <TEST_OPTIONS>

 

When I run this locally to test it, I launch the docker image with docker run -it --rm <DOCKER_IMAGE> 

Then run the commands that the bitbucket-pipelines script would run.

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events