From 7818b03eb8e18a8eb1723f689a403bd0beb5c525 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Petr=20=C5=A0tetiar?= Date: Thu, 6 Aug 2020 14:37:23 +0200 Subject: [PATCH] ci: add site building and testing MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit To improve the QA. Signed-off-by: Petr Štetiar --- .gitignore | 3 +++ .gitlab-ci.yml | 33 +++++++++++++++++++++++++++++++++ tests/test_spa.py | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 .gitignore create mode 100644 tests/test_spa.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..782eb43 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +build/ +node_modules/ +__pycache__/ diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f1761b5..9356e56 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -22,3 +22,36 @@ check HTML, CSS and SVG with html5validator: image: cyb3rjak3/html5validator:latest script: - html5validator --root www --also-check-css --also-check-svg --show-warnings --log INFO + +build site on Python 3.8: + stage: pre-build + image: python:3.8-slim-buster + before_script: + - apt-get update; apt-get install -y make + script: + - cp -R ./www ./build + - misc/collect.py scrape https://downloads.openwrt.org build + artifacts: + expire_in: 1 week + when: always + paths: + - build + +test site with selenium: + stage: test + image: selenium/standalone-firefox:latest + script: + - /opt/bin/entry_point.sh & + - sudo apt-get update; sudo apt-get install -y python3-pip python3-pytest + - pip3 install selenium-firefox + - (cd build; python3 -m http.server &) + - pytest-3 tests + +build site for target environment: + stage: test + image: debian:9 + before_script: + - apt-get update; apt-get install -y make python3 + script: + - cp -R ./www ./build + - misc/collect.py scrape https://downloads.openwrt.org build diff --git a/tests/test_spa.py b/tests/test_spa.py new file mode 100644 index 0000000..5a2cecb --- /dev/null +++ b/tests/test_spa.py @@ -0,0 +1,41 @@ +from selenium import webdriver +from selenium.webdriver.support.ui import Select +from selenium.webdriver.common.desired_capabilities import DesiredCapabilities + + +def init_driver(): + driver = webdriver.Remote( + command_executor="http://localhost:4444/wd/hub", + desired_capabilities=DesiredCapabilities.FIREFOX, + ) + return driver + + +def test_spa(): + driver = init_driver() + driver.get("http://localhost:8000") + assert "OpenWrt Firmware Selector" in driver.title + + model = driver.find_element_by_id("models") + model.clear() + model.send_keys("a7 v5") + + models = driver.find_element_by_id("models-autocomplete-list") + assert "TP-Link Archer A7 v5" in models.text + + message = driver.find_element_by_xpath("/html/body/div/div/p") + assert "use the input below to download firmware" in message.text + + lang = Select(driver.find_element_by_id("language-selection")) + + lang.select_by_visible_text("Deutsch") + message = driver.find_element_by_xpath("/html/body/div/div/p") + assert "benutze die Eingabe um die passende" in message.text + + lang.select_by_value("ca") + message = driver.find_element_by_xpath("/html/body/div/div/p") + assert "servir el formulari de sota per seleccionar" in message.text + + lang.select_by_visible_text("Polski") + message = driver.find_element_by_xpath("/html/body/div/div/p") + assert "pola poniżej żeby znaleźć obraz" in message.text -- 2.30.2