Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,8 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Set up JDK 15
uses: actions/setup-java@v2
with:
java-version: '15'
distribution: 'adopt'
- name: Install Google Chrome
run: |
chmod +x ./scripts/InstallChrome.sh
./scripts/InstallChrome.sh
- name: Build with Maven
run: mvn -B package --file pom.xml allure:report
- name: Run CI
run: make ci
env:
user_good_username: ${{ secrets.USER_GOOD_USERNAME }}
user_good_password: ${{ secrets.USER_GOOD_PASSWORD }}
Expand Down
79 changes: 79 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
FROM ubuntu:18.04

# Default to UTF-8 file.encoding
ENV LANG C.UTF-8

################################################################################################################
# Install JDK
# https://github.com/docker-library/openjdk/blob/master/8-jdk/Dockerfile
# Selenum is based on Xenial, so it is a bit different
################################################################################################################

# add a simple script that can auto-detect the appropriate JAVA_HOME value
# based on whether the JDK or only the JRE is installed
RUN { \
echo '#!/bin/sh'; \
echo 'set -e'; \
echo; \
echo 'dirname "$(dirname "$(readlink -f "$(which javac || which java)")")"'; \
} > /usr/local/bin/docker-java-home \
&& chmod +x /usr/local/bin/docker-java-home

ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64

ENV JAVA_VERSION 8u312
ENV JAVA_DEBIAN_VERSION 8u312-b07-0ubuntu1~18.04

RUN set -x \
&& apt-get update \
&& apt-get install -y \
curl \
wget \
make \
bzip2 \
unzip \
xz-utils \
fonts-liberation \
xdg-utils \
libxkbcommon0 \
libgbm1 \
libgtk-3-bin \
openjdk-8-jdk="$JAVA_DEBIAN_VERSION" \
&& rm -rf /var/lib/apt/lists/* \
&& [ "$JAVA_HOME" = "$(docker-java-home)" ]

# see CA_CERTIFICATES_JAVA_VERSION notes above
RUN /var/lib/dpkg/info/ca-certificates-java.postinst configure

################################################################################################################
# Install Maven
# https://github.com/carlossg/docker-maven
# https://medium.com/@ahamedabdulrahman/dockerize-selenium-java-project-and-run-selenium-scripts-within-docker-container-c2603d1bac3f
################################################################################################################

ARG MAVEN_VERSION=3.8.5
ARG USER_HOME_DIR="/root"
ARG SHA=89ab8ece99292476447ef6a6800d9842bbb60787b9b8a45c103aa61d2f205a971d8c3ddfb8b03e514455b4173602bd015e82958c0b3ddc1728a57126f773c743
ARG BASE_URL=https://apache.osuosl.org/maven/maven-3/${MAVEN_VERSION}/binaries
RUN mkdir -p /usr/share/maven /usr/share/maven/ref \
&& curl -fsSL -o /tmp/apache-maven.tar.gz ${BASE_URL}/apache-maven-${MAVEN_VERSION}-bin.tar.gz \
&& echo "${SHA} /tmp/apache-maven.tar.gz" | sha512sum -c - \
&& tar -xzf /tmp/apache-maven.tar.gz -C /usr/share/maven --strip-components=1 \
&& rm -f /tmp/apache-maven.tar.gz \
&& ln -s /usr/share/maven/bin/mvn /usr/bin/mvn
ENV MAVEN_HOME /usr/share/maven
ENV MAVEN_CONFIG "$USER_HOME_DIR/.m2"

################################################################################################################
# Install chrome latest - see below reference to install a particular version
# https://medium.com/@ahamedabdulrahman/dockerize-selenium-java-project-and-run-selenium-scripts-within-docker-container-c2603d1bac3f
################################################################################################################
RUN curl -s -o /chrome.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN dpkg -i /chrome.deb
RUN rm /chrome.deb

################################################################################################################
# Put our stuff
################################################################################################################
COPY . /
WORKDIR /
33 changes: 33 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# commands
MVN = mvn
DOCKER = docker
COMPOSE = docker-compose -f $(CURDIR)/docker-compose.yml

-include $(CURDIR)/.env.local
export

help:
@echo "Please use 'make <target>' where <target> is one of the following:"
@echo " ci to run the tests on ci/docker."
@echo " ci-cleanup to kill & remove all ci containers."
@echo " test to run the tests locally with maven."
@echo " test to cleanup generated files and folders."

.PHONY: test
test:
$(MVN) -B package --file pom.xml allure:report

.PHONY: clean
clean:
$(MVN) clean
rm -f test-output.log*

.PHONY: ci
ci: ci-cleanup
$(COMPOSE) up --build --no-deps --force-recreate -d selenium-run
$(COMPOSE) run selenium-run make test
$(MAKE) ci-cleanup

.PHONY: ci-cleanup
ci-cleanup:
$(COMPOSE) down
7 changes: 7 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: '3.2'
services:
selenium-run:
build:
context: ./
dockerfile: Dockerfile
restart: on-failure:10
5 changes: 0 additions & 5 deletions scripts/InstallChrome.sh

This file was deleted.

6 changes: 1 addition & 5 deletions src/test/java/selenium/base/TestBase.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package selenium.base;

import java.net.URL;
import java.time.Duration;

import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.rules.ExternalResource;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
Expand Down Expand Up @@ -44,7 +40,7 @@ public static void setupClass() {
@Before
public void setup() {
this.setupLogger();
Context.getInstance().setLogger(LOGGER);
Context.getInstance().setLogger(LOGGER);

//https://www.linkedin.com/pulse/running-selenium-web-tests-github-actions-moataz-nabil/
ChromeOptions options = new ChromeOptions();
Expand Down
38 changes: 38 additions & 0 deletions src/test/resources/log4j2-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO" monitorInterval="30">

<!-- Logging Properties -->
<Properties>
<Property name="LOG_PATTERN">%d %p %c [%t] %m%n</Property>
<Property name="FILENAME">test-output.log</Property>
</Properties>

<Appenders>

<!-- Console Appender -->
<Console name="Console" target="SYSTEM_OUT" follow="true">
<PatternLayout pattern="${LOG_PATTERN}"/>
</Console>

<!-- File Appenders on need basis -->
<RollingFile name="FrameworkLog" fileName="${FILENAME}"
filePattern="${FILENAME}-%d{MM-dd-yy-HH-mm-ss}.log">
<PatternLayout pattern="${LOG_PATTERN}"/>
<Policies>
<SizeBasedTriggeringPolicy size="19500KB" />
</Policies>
<DefaultRolloverStrategy max="10"/>
</RollingFile>

</Appenders>

<Loggers>

<Root level="warn">
<AppenderRef ref="Console"/>
<AppenderRef ref="FrameworkLog"/>
</Root>

</Loggers>

</Configuration>