dataduke
5/23/2017 - 4:23 PM

XLT TestSuite in Docker

XLT TestSuite in Docker

#!/bin/bash

# If any script fails then exit 1.
set -e

# Always own possibly mounted docker volumes (files on host).
chown -R ebs:ebs ${EBS_RESULTS_VOL}

# Use size defined in Dockerfile
export GEOMETRY="$SCREEN_WIDTH""x""$SCREEN_HEIGHT""x""$SCREEN_DEPTH"

# Change to testsuite dir
cd "${WORKDIR}"

# If the first argument is -Dtestcase or -Dparallel
# then set exec to prepend with ant.
if [[ "${1}" =~ ^.*(-Dtestcase)|(-Dparallel).*$ ]]; then
    set ant test "${@}"
fi

# If the first argument is test
# then set exec to prepend with ant.
if [[ "${1}" =~ ^.*(test).*$ ]]; then
    set ant "${@}"
fi

# If the first argument is ant
# then set exec with all given args.
if [[ "${1}" == "ant" ]]; then
	# sudo chown root:root /tmp/.X11-unix
	Xvfb :1 -screen 0 1920x1200x24 & 
	export DISPLAY=:1.0                     # :display.screen
	cd ${EBS_TESTSUITE}  
	ant test
	# set -- gosu ebs xvfb-run --server-args="$DISPLAY -screen 0 $GEOMETRY -ac +extension RANDR" \
	# ant $@

	# try with root if gosu does not work:
	# set xvfb-run --server-args="$DISPLAY -screen 0 $GEOMETRY -ac +extension RANDR" \
	# ant $@
fi

# Execute defined arguments.
# This includes not ant related args (e.g. `bash`).
exec "${@}"


# OTHER OPTIONS
#
# Option 1: configure Xvfb and then run tests
#
# sudo chown root:root /tmp/.X11-unix
# Xvfb :1 -screen 0 1920x1200x24 & 
# export DISPLAY=:1.0                     # :display.screen  
# ant test
  
# Option 2: use wrapper (done above)
#
# xvfb-run --server-args="-screen 0 1920x1200x24" ant test

The ebs-testsuite

The project is based on XLT and Script Developer, which utilize the Selenium core.

Best Practices for extending the testsuite can be found at the SiteGenesis-Community-TestSuite.

Docker Usage

# Build image
docker build -t xalt-ebs-testsuite .

# Create dir for mounting test results
# mkdir results

# Run all test cases
docker run --rm --volume=$(pwd)/results:/home/ebs/testsuite/tmp/results xalt-ebs-testsuite

# Run a single test case
docker run --rm --volume=$(pwd)/results:/home/ebs/testsuite/tmp/results xalt-ebs-testsuite ant test -Dtestcase=THome_LoginLogout
# or short
docker run --rm --volume=$(pwd)/results:/home/ebs/testsuite/tmp/results xalt-ebs-testsuite -Dtestcase=THome_LoginLogout

# Run all test cases in parallel with e.g. 2 headless browser instances
docker run --rm --volume=$(pwd)/results:/home/ebs/testsuite/tmp/results xalt-ebs-testsuite ant test -Dparallle=2

# Debug via login to interactive terminal in container
docker run --rm --volume=$(pwd)/results:/home/ebs/testsuite/tmp/results -it xalt-ebs-testsuite bash

FROM ubuntu:16.04

################
# Setup System #
################

# Add sources to mirror list
RUN echo "deb http://archive.ubuntu.com/ubuntu xenial main universe\n" > /etc/apt/sources.list && \
    echo "deb http://archive.ubuntu.com/ubuntu xenial-updates main universe\n" >> /etc/apt/sources.list && \
    echo "deb http://security.ubuntu.com/ubuntu xenial-security main universe\n" >> /etc/apt/sources.list

# Make sure our system is up-to-date
ENV LAST_REFRESH=2016-03-01

# Set non-interactive shell for installation
ENV DEBIAN_FRONTEND noninteractive
ENV DEBCONF_NONINTERACTIVE_SEEN true

RUN apt-get update -qqy && apt-get -qqy --no-install-recommends install \
    ant \
    ant-optional \
    ca-certificates \
    bzip2 \
    sudo \
    unzip \
    wget \
    xvfb \
    xz-utils
# && rm -rf /var/lib/apt/lists/* \
# && sed -i 's/securerandom\.source=file:\/dev\/random/securerandom\.source=file:\/dev\/urandom/' ./usr/lib/jvm/java-8-openjdk-amd64/jre/lib/security/java.security

##############
# Setup Java #
##############

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

# 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 8u91
ENV JAVA_DEBIAN_VERSION 8u91-b14-1~bpo8+1

# see https://bugs.debian.org/775775
# and https://github.com/docker-library/java/issues/19#issuecomment-70546872
ENV CA_CERTIFICATES_JAVA_VERSION 20140324

RUN set -x \
  && apt-get update \
  && apt-get install -y \
    openjdk-8-jdk \
    ca-certificates-java \
    junit \
  && [ "$JAVA_HOME" = "$(docker-java-home)" ]

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

##############
# Setup gosu #
##############

# Grab gosu for easy step-down from root
ENV GOSU_VERSION 1.7
RUN set -x \
	&& wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture)" \
	&& wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture).asc" \
	&& export GNUPGHOME="$(mktemp -d)" \
	&& gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \
	&& gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu \
	&& rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc \
	&& chmod +x /usr/local/bin/gosu \
	&& gosu nobody true

#############################
# Setup screen and browsers #
#############################

# Configuration options for the screen
ENV SCREEN_WIDTH 1600
ENV SCREEN_HEIGHT 1080
ENV SCREEN_DEPTH 24
ENV DISPLAY :99.0

##################
# Setup browsers #
##################

# Install firefox
ENV FIREFOX_VERSION 45.0.2
RUN apt-get update -qqy \
  && apt-get -qqy --no-install-recommends install firefox \
  && rm -rf /var/lib/apt/lists/* \
  && wget --no-verbose -O /tmp/firefox.tar.bz2 https://download-installer.cdn.mozilla.net/pub/firefox/releases/$FIREFOX_VERSION/linux-x86_64/en-US/firefox-$FIREFOX_VERSION.tar.bz2 \
  && apt-get -y purge firefox \
  && rm -rf /opt/firefox \
  && tar -C /opt -xjf /tmp/firefox.tar.bz2 \
  && rm /tmp/firefox.tar.bz2 \
  && mv /opt/firefox /opt/firefox-$FIREFOX_VERSION \
  && ln -fs /opt/firefox-$FIREFOX_VERSION/firefox /usr/bin/firefox

# Install chrome
RUN 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-chrome.list \
  && apt-get update -qqy \
  && apt-get -qqy install google-chrome-stable \
  && rm /etc/apt/sources.list.d/google-chrome.list \
  && rm -rf /var/lib/apt/lists/*

# Install chrome webdriver
ENV CHROME_DRIVER_VERSION 2.21
RUN wget --no-verbose -O /tmp/chromedriver_linux64.zip https://chromedriver.storage.googleapis.com/$CHROME_DRIVER_VERSION/chromedriver_linux64.zip \
  && rm -rf /opt/selenium/chromedriver \
  && unzip /tmp/chromedriver_linux64.zip -d /opt/selenium \
  && rm /tmp/chromedriver_linux64.zip \
  && mv /opt/selenium/chromedriver /opt/selenium/chromedriver-$CHROME_DRIVER_VERSION \
  && chmod 755 /opt/selenium/chromedriver-$CHROME_DRIVER_VERSION \
  && ln -fs /opt/selenium/chromedriver-$CHROME_DRIVER_VERSION /usr/bin/chromedriver

################################
# Setup ebs testsuite with xlt #
################################

ENV EBS_USER="ebs" \
    EBS_HOME="/home/ebs" \
    EBS_TESTSUITE="/home/ebs/testsuite" \
    EBS_RESULTS_VOL="/home/ebs/testsuite/results"

# Add ebs user and home dir with passwordless sudo
RUN sudo useradd ebs --shell /bin/bash --create-home \
  && sudo usermod -a -G sudo ebs \
  && echo 'ALL ALL = (ALL) NOPASSWD: ALL' >> /etc/sudoers \
  && echo 'ebs:secret' | chpasswd

# Install xlt
ENV XLT_VERSION="4.6.4"
# RUN  mkdir -p /opt/selenium
RUN set -x \
    && wget --non-verbose -O ${EBS_HOME}/xlt-${XLT_VERSION}.zip "https://lab.xceptance.de/releases/xlt/${XLT_VERSION}/xlt-${XLT_VERSION}.zip"

RUN unzip ${EBS_HOME}/xlt-${XLT_VERSION}.zip -d ${EBS_HOME}

# Create testsuite directory and directory for results
RUN mkdir -p ${EBS_TESTSUITE} ${EBS_RESULTS_VOL}

# Copy project to testsuite dir
COPY . ${EBS_TESTSUITE}

# Change ownership to ebs
RUN chown -R ebs:ebs ${EBS_TESTSUITE}

# Set volume mount points
VOLUME ["${EBS_RESULTS_VOL}"]

# Use our own entrypoint script that changes file ownerships
COPY docker-entrypoint.sh /
RUN chown ebs:ebs /docker-entrypoint.sh && \
	chmod +x /docker-entrypoint.sh
ENTRYPOINT ["/docker-entrypoint.sh"]

# Set default command and default option suffix
CMD ["ant", "test"]