Skip to content

Commit

Permalink
add Dockerfile && fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
Uunnamed committed Jul 21, 2020
1 parent bc74c5e commit d253532
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 6 deletions.
50 changes: 50 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
FROM clojure:lein-2.9.3

RUN apt-get -yqq update && \
apt-get -yqq upgrade && \
apt-get -yqq install gnupg2 && \
apt-get -yqq install curl unzip && \
apt-get -yqq install fonts-ipafont-gothic xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic && \
apt-get install -y jq libgconf-2-4 && \
rm -rf /var/lib/apt/lists/*

# Install Chrome WebDriver
RUN CHROMEDRIVER_VERSION=`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE` && \
mkdir -p /opt/chromedriver-$CHROMEDRIVER_VERSION && \
curl -sS -o /tmp/chromedriver_linux64.zip http://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VERSION/chromedriver_linux64.zip && \
unzip -qq /tmp/chromedriver_linux64.zip -d /opt/chromedriver-$CHROMEDRIVER_VERSION && \
rm /tmp/chromedriver_linux64.zip && \
chmod +x /opt/chromedriver-$CHROMEDRIVER_VERSION/chromedriver && \
ln -fs /opt/chromedriver-$CHROMEDRIVER_VERSION/chromedriver /usr/local/bin/chromedriver

# Install Google Chrome
RUN curl -sS -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 -yqq update && \
apt-get -yqq install google-chrome-stable && \
rm -rf /var/lib/apt/lists/*

# Install Firefox
# RUN set -o nounset && set -o errexit && set -o xtrace
RUN FIREFOX_URI="https://download.mozilla.org/?product=firefox-latest&os=linux64&lang=en-US" && \
wget --quiet --content-disposition "$FIREFOX_URI" && \
tar xf firefox-*.tar.bz2 -C /usr/local && \
ln -s /usr/local/firefox/firefox /usr/local/bin/firefox

# Install Geckodriver
RUN GECKODRIVER_META="https://api.github.com/repos/mozilla/geckodriver/releases/latest" && \
GECKODRIVER_LATEST_RELEASE_URL=$(curl $GECKODRIVER_META | jq -r ".assets[] | select(.name | test(\"linux64\")) | .browser_download_url") && \
curl --silent --show-error --location --fail --retry 3 --output /tmp/geckodriver_linux64.tar.gz "$GECKODRIVER_LATEST_RELEASE_URL" && \
cd /tmp && \
tar xf geckodriver_linux64.tar.gz && \
chmod +x geckodriver && \
mv geckodriver /usr/local/bin/

WORKDIR /etaoin
COPY ./ ./
RUN lein deps

WORKDIR /
RUN rm -rf /etaoin

ENV ETAOIN_TEST_DRIVERS="[:firefox :chrome]"
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,17 @@ autodoc:
cd autodoc && git add -A
cd autodoc && git commit -m "Documentation updated"
cd autodoc && git push

IMAGE := etaoin

.PHONY: docker-build
docker-build:
docker build -t ${IMAGE}:latest .


.PHONY: docker-test
docker-test:
docker run -it --rm \
-v $(CURDIR)/:/etaoin \
-w /etaoin ${IMAGE}:latest \
lein test
14 changes: 8 additions & 6 deletions test/etaoin/api_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
(defn get-default-drivers []
[:firefox :chrome :phantom :safari])

(def default-opts
{:chrome {:args ["--headless" "--no-sandbox"]}
:firefox {:args ["--headless"]}
:safari {:path-driver "/Applications/Safari Technology Preview.app/Contents/MacOS/safaridriver"}})

(def drivers
(or (get-drivers-from-env)
(get-drivers-from-prop)
Expand All @@ -49,15 +54,12 @@
(defn fixture-browsers [f]
(let [url (-> "html/test.html" io/resource str)]
(doseq [type drivers]
(let [opt (if (= type :safari)
{:path-driver "/Applications/Safari Technology Preview.app/Contents/MacOS/safaridriver"}
{})]
(with-driver type opt driver
(with-driver type (get default-opts type {}) driver
(go driver url)
(wait-visible driver {:id :document-end})
(binding [*driver* driver]
(testing (name type)
(f))))))))
(f)))))))

(use-fixtures
:each
Expand Down Expand Up @@ -343,7 +345,7 @@
(is (not= height height'))))))

(deftest test-maximize
(when-not-drivers [:firefox :phantom] *driver*
(when-not-drivers [:chrome :firefox :phantom] *driver*
(let [{:keys [x y]} (get-window-position *driver*)
{:keys [width height]} (get-window-size *driver*)]
(maximize *driver*)
Expand Down

0 comments on commit d253532

Please sign in to comment.