如何在docker container中运行web自动化测试

在docker container中运行自动化测试,需要在container里安装chromedriver和chrome浏览器,还有headless display的xvfb。由于测试是用java写的,gradle运行的,所以还需要安装java和gradle,Dockerfile如下:

FROM java:8

ADD . /test

WORKDIR /test

# Download and install Gradle

RUN \

    cd /usr/local && \

    curl -L https://services.gradle.org/distributions/gradle-4.1-bin.zip -o gradle-4.1-bin.zip && \

    unzip gradle-4.1-bin.zip && \

    rm gradle-4.1-bin.zip

RUN apt-get update

# Install chrome

RUN apt-get -y install fonts-liberation xdg-utils libxss1 libappindicator1 libindicator7 libgtk-3-0 lsb-release

RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb

RUN apt-get -f install -y

RUN dpkg -i google-chrome*.deb

# Install chromedriver

RUN wget-N https://chromedriver.storage.googleapis.com/LATEST_RELEASE-P ~/Downloads

RUN wget-N"http://chromedriver.storage.googleapis.com/`cat ~/Downloads/LATEST_RELEASE`/chromedriver_linux64.zip" -P ~/Downloads

RUN chmod +x ~/Downloads/chromedriver

RUN mv -f ~/Downloads/chromedriver /usr/local/share/chromedriver

RUN ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver

RUN ln -s /usr/local/share/chromedriver /usr/bin/chromedriver

#Install Headless Display

RUN apt-get -y install xvfb

# Export some environment variables

ENV GRADLE_HOME=/usr/local/gradle-4.1

ENV PATH=$PATH:$GRADLE_HOME/bin

EXPOSE {some port}

CMD "running script for test"

你可能感兴趣的:(如何在docker container中运行web自动化测试)