Initial setup of test suite containers, basic Selenium test script added.

This commit is contained in:
Ada Werefox 2023-01-17 18:22:01 +00:00
parent e51076300a
commit c7dae0bdb3
5 changed files with 59 additions and 4 deletions

View File

@ -8,7 +8,7 @@ CONTAINER_NAME=werefox-dev
MODE=$1 MODE=$1
x=$(APP_FOLDER=$APP_FOLDER MODE=$MODE docker compose ps | grep $CONTAINER_NAME | wc -l) 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." echo "Please use 'dev', 'build', or 'start' as an argument."
exit 1 exit 1
fi 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" cd /usr/src/app && rm -rf node_modules package.json package-lock.json"
fi 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 && 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 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 APP_FOLDER=$APP_FOLDER MODE=$MODE docker compose logs -f
fi fi

5
run_tests.sh Executable file
View File

@ -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

5
tests/Dockerfile Normal file
View File

@ -0,0 +1,5 @@
FROM python:alpine
USER root
RUN python3 -m pip install selenium
WORKDIR /

30
tests/docker-compose.yml Normal file
View File

@ -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'

12
tests/test_suite/test.py Normal file
View File

@ -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()