Facing issues attempting to run Selenium tests inside a docker container

336 views
Skip to first unread message

Gehan Mendis

unread,
Jan 15, 2024, 8:06:34 AM1/15/24
to Selenium Users

I am working on a Java 17 and Maven 3.9.6-based robotic automation application that automates Chrome through Selenium. to perform report download tasks. This operation works fine when performed in a local development environment and as an executable jar, file.

But when I am attempting to dockerize this application I am facing issues related to selenium and browser dependencies when building and attempting to run the docker image. 


Could someone please suggest if my approach is correct or if it requires any changes or improvements to my Docker file and how the browser dependencies are added?

Could you also suggest some valid resources on how this Java Selenium application can dockerized to be deployed on a new server that does not contain Selenium or Chrome browser functionality currently installed?

After rummaging through a ton of internet resources, forums, and videos to assist with this task my docker files currently look like this.

Use the official OpenJDK 17 image as a base image

FROM maven:3.9.6-eclipse-temurin-17-alpine AS builder


Set the working directory inside the container

WORKDIR /app

RUN chmod -R 777 /app


Install tools.

RUN apt update -y & apt install -y wget unzip

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get install -y tzdata


Install Chrome.

RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -

RUN sh -c 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'

RUN apt-get update

RUN apt-get install -y google-chrome-stable


Install ChromeDriver.

RUN wget -N https://chromedriver.storage.googleapis.com/105.0.5195.19/chromedriver_linux64.zip -P ~/

RUN unzip ~/chromedriver_linux64.zip -d ~/

RUN rm ~/chromedriver_linux64.zip

RUN mv -f ~/chromedriver /usr/local/bin/chromedriver

RUN chmod +x /usr/local/bin/chromedriver


Copy the entire project (assuming Dockerfile is in the project root)

COPY . .


Build the application using Maven

RUN mvn package -DskipTests


Use the official OpenJDK 17 image as the final image

FROM eclipse-temurin:17.0.6_10-jdk@sha256:13817c2faa739c0351f97efabed0582a26e9e6745a6fb9c47d17f4365e56327d


Set the working directory inside the container

WORKDIR /app


Copy the JAR file and other necessary files to the container

COPY report-automation.jar /app/report-automation.jar

COPY src/main/resources/META-INF/MANIFEST.MF /app/META-INF/MANIFEST.MF

COPY src /app/src

COPY src/main/resources/META-INF/MANIFEST.MF /app/META-INF/MANIFEST.MF

COPY src/main/resources/config.properties /app/config.properties

COPY pom.xml /app/pom.xml

COPY testng.xml /app/testng.xml

COPY application.properties /app/application.properties

COPY Configuration.xlsm /app/Configuration.xlsm

COPY apache-maven-3.9.6/ /app/apache-maven-3.9.6/

COPY Downloads /app/Downloads

COPY Logs /app/Logs

COPY report /app/report

COPY Reports /app/Reports


Expose the port (if your application listens on a specific port)

EXPOSE 8080


Set the entry point for the container (replace with your main class)

ENTRYPOINT ["java", "-jar", "report-automation.jar"] These are the more useful references I came across. But I still seem to be missing something and facing issues.


⇜Krishnan Mahadevan⇝

unread,
Jan 15, 2024, 8:13:20 AM1/15/24
to seleniu...@googlegroups.com
Gehan,

Couple of things.

Rather than trying to build all of the browser requirements by hand again within your docker file, what if you extended the already available docker images (depending upon the browser flavour ?) .

For e.g., if you were just looking at chrome (which is what your docker file seems to suggest) then you could just start with this image as your base image: https://hub.docker.com/r/selenium/standalone-chrome

Is there any hard wired requirement that you would need to have your browser and your app all packed into 1 docker container? What if you were to create a docker-compose file, which would just club a bunch of docker images (your application image + the docker chrome image) into 1 small docker cluster and work with that?

That way, you can focus on ONLY those things that are required by your standalone app and for the selenium needs your requests just go to the selenium container.

It's a lot more cleaner that way.



Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribblings @ https://rationaleemotions.com/


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/007f8ea9-15d7-4afa-928d-09d42ccb8238n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages