From c7dae0bdb302f0467310398358b54a15ee4d6795 Mon Sep 17 00:00:00 2001 From: Ada Werefox Date: Tue, 17 Jan 2023 18:22:01 +0000 Subject: [PATCH] Initial setup of test suite containers, basic Selenium test script added. --- deploy.sh | 11 +++++++---- run_tests.sh | 5 +++++ tests/Dockerfile | 5 +++++ tests/docker-compose.yml | 30 ++++++++++++++++++++++++++++++ tests/test_suite/test.py | 12 ++++++++++++ 5 files changed, 59 insertions(+), 4 deletions(-) create mode 100755 run_tests.sh create mode 100644 tests/Dockerfile create mode 100644 tests/docker-compose.yml create mode 100644 tests/test_suite/test.py diff --git a/deploy.sh b/deploy.sh index c873a31..0384d1b 100755 --- a/deploy.sh +++ b/deploy.sh @@ -8,7 +8,7 @@ CONTAINER_NAME=werefox-dev MODE=$1 x=$(APP_FOLDER=$APP_FOLDER MODE=$MODE docker compose ps | grep $CONTAINER_NAME | wc -l) -if [ "$MODE" == "" ]; then +if [ "$MODE" == "" ] || [ "$MODE" != "build" && "$MODE" != "dev" && "$MODE" != "start" ]; then echo "Please use 'dev', 'build', or 'start' as an argument." exit 1 fi @@ -24,10 +24,13 @@ if [ ! -d "$(pwd)/src/$APP_FOLDER" ]; then cd /usr/src/app && rm -rf node_modules package.json package-lock.json" fi + APP_FOLDER=$APP_FOLDER MODE=$MODE docker compose run $CONTAINER_NAME sh -c "cd $APP_FOLDER && npm install --silent" APP_FOLDER=$APP_FOLDER MODE=$MODE docker compose run $CONTAINER_NAME sh -c "cd $APP_FOLDER && npx next telemetry disable" -APP_FOLDER=$APP_FOLDER MODE=$MODE docker compose up -d -if [ "$MODE" == "dev" ] || [ "$MODE" == "start" ]; then +if [ "$MODE" == "build" ]; then + APP_FOLDER=$APP_FOLDER MODE=$MODE docker compose run $CONTAINER_NAME sh -c "cd $APP_FOLDER && npm run build" +elif [ "$MODE" == "dev" ] || [ "$MODE" == "start" ]; then + APP_FOLDER=$APP_FOLDER MODE=$MODE docker compose up -d APP_FOLDER=$APP_FOLDER MODE=$MODE docker compose logs -f -fi \ No newline at end of file +fi diff --git a/run_tests.sh b/run_tests.sh new file mode 100755 index 0000000..f6d008e --- /dev/null +++ b/run_tests.sh @@ -0,0 +1,5 @@ +#/bin/bash + +cd tests/ +docker compose build --no-cache --pull && docker compose up --remove-orphans --abort-on-container-exit --exit-code-from selenium-node +docker compose rm -sf diff --git a/tests/Dockerfile b/tests/Dockerfile new file mode 100644 index 0000000..afd64ed --- /dev/null +++ b/tests/Dockerfile @@ -0,0 +1,5 @@ +FROM python:alpine + +USER root +RUN python3 -m pip install selenium +WORKDIR / diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml new file mode 100644 index 0000000..63b9c06 --- /dev/null +++ b/tests/docker-compose.yml @@ -0,0 +1,30 @@ +--- +version: "3" + +services: + selenium-hub: + image: selenium/standalone-chrome:108.0 + shm_size: '2gb' + ports: + - "4444:4444" + - "7900:7900" + environment: + - SE_OPTS:"--allow-cors true" + healthcheck: + test: curl --fail http://localhost:4444/ + interval: 5s + retries: 5 + start_period: 10s + timeout: 30s + + selenium-node: + image: selenium-node:latest + build: . + depends_on: + selenium-hub: + condition: service_healthy + volumes: + - ./test_suite:/tests:ro + - ./output:/output:rw + user: "1000:1000" + command: 'python3 /tests/test.py' diff --git a/tests/test_suite/test.py b/tests/test_suite/test.py new file mode 100644 index 0000000..828b7da --- /dev/null +++ b/tests/test_suite/test.py @@ -0,0 +1,12 @@ +from selenium import webdriver +from time import sleep +chrome_options = webdriver.ChromeOptions() +print('Attempting to establish connection to remote webdriver...') +driver = webdriver.Remote(command_executor='http://selenium-hub:4444', options=chrome_options) +print('Connection established.') +print('Attempting to get page...') +driver.get("https://werefox.cafe") +print('Page loaded.') +sleep(10) +driver.close() +driver.quit()