diff --git a/Dockerfile-selenium b/Dockerfile-selenium new file mode 100644 index 0000000..eec40ae --- /dev/null +++ b/Dockerfile-selenium @@ -0,0 +1,11 @@ +FROM selenium/standalone-firefox +USER root + +RUN apt-get -y update +RUN apt-get -y install python3-pip +USER seluser +RUN python3 -m pip install helium --user +WORKDIR /home/seluser +ADD tests/* /home/seluser/ + +ENTRYPOINT [ "python3", "tests.py" ] \ No newline at end of file diff --git a/docker-compose-tests.yml b/docker-compose-tests.yml new file mode 100644 index 0000000..e66c203 --- /dev/null +++ b/docker-compose-tests.yml @@ -0,0 +1,11 @@ +services: + rimgu: + build: . + network_mode: host + selenium: + depends_on: + - "rimgu" + build: + dockerfile: ./Dockerfile-selenium + context: . + network_mode: host diff --git a/run-tests.sh b/run-tests.sh new file mode 100755 index 0000000..1b349c8 --- /dev/null +++ b/run-tests.sh @@ -0,0 +1,5 @@ +#!/bin/bash +sudo docker-compose -f docker-compose-tests.yml up --abort-on-container-exit --build +EXIT_CODE=$? +sudo docker-compose -f docker-compose-tests.yml down +exit "$EXIT_CODE" \ No newline at end of file diff --git a/tests/find_video_for_cMeqLga.js b/tests/find_video_for_cMeqLga.js new file mode 100644 index 0000000..036b51d --- /dev/null +++ b/tests/find_video_for_cMeqLga.js @@ -0,0 +1,12 @@ +// Script is executed by selenium because the css selector is bugged in helium/selenium +// Check for the meme video's element presence then write to page so helium +// knows it is there +let vid = document.querySelectorAll('source[src="/InQKYvf.mp4"]') + +if (vid.length){ + let p = document.createElement("p") + p.innerText = "video exists" + + document.body.appendChild(p) + +} diff --git a/tests/tests.py b/tests/tests.py new file mode 100644 index 0000000..16c83ef --- /dev/null +++ b/tests/tests.py @@ -0,0 +1,14 @@ +import time +import helium + +gallery_id = "cMeqLga" +f = helium.start_firefox(f"http://127.0.0.1:8080/gallery/{gallery_id}", headless=True) + +assert helium.Text("2021-10-13T15:25:25Z").exists() + +# Check for meme video by running a js to create a p element if it exists +with open(f"find_video_for_{gallery_id}.js", "r") as script: + f.execute_script(script.read()) + + +assert helium.Text("video exists").exists()