From 11febfae591eca220990382b2707e1175ed73d16 Mon Sep 17 00:00:00 2001 From: Marina Date: Tue, 27 Feb 2024 15:13:13 +0300 Subject: [PATCH] Tests added in Docker (ready) --- Dockerfile_selenium | 5 ++++- docker-compose.yml | 11 +++++++++++ tests/README.md | 11 +++++++---- tests/basic_selenium_test.py | 6 ++---- tests/test_authorization.py | 3 +++ tests/test_statistic.py | 3 ++- 6 files changed, 29 insertions(+), 10 deletions(-) diff --git a/Dockerfile_selenium b/Dockerfile_selenium index 51a519f2..c3309625 100644 --- a/Dockerfile_selenium +++ b/Dockerfile_selenium @@ -10,4 +10,7 @@ RUN apt-get update && \ COPY tests ./tests RUN pip install -r tests/requirements.txt -CMD ["python3", "tests/main.py", "--login", "admin", "--password", "admin"] +ENV LOGIN="" +ENV PASSWORD="" + +ENTRYPOINT python3 tests/main.py --login ${LOGIN} --password ${PASSWORD} diff --git a/docker-compose.yml b/docker-compose.yml index 51a19367..c2346f58 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -68,6 +68,17 @@ services: volumes: - ../slides_checker_mongo_data:/data/db + selenium-tests: + build: + context: . + dockerfile: Dockerfile_selenium + environment: + - LOGIN=${ADMIN_PASSWORD} + - PASSWORD=${ADMIN_PASSWORD} + depends_on: + - web + network_mode: host + volumes: presentation_files: redis_data: diff --git a/tests/README.md b/tests/README.md index cff11bd9..b3a8f8fc 100644 --- a/tests/README.md +++ b/tests/README.md @@ -1,11 +1,14 @@ -## For beginning: -You should have Firefox, installed not in 'snap'. +## Docker: -Install requirements.txt: +Tests included in docker-compose.yml + +You can run tests with dockerfile_selenium independently, using special flag: ```bash -$ pip install -r tests/requirements.txt +$ docker build -t your_image_name -f Dockerfile_selenium . +$ docker run -e LOGIN=your_login -e PASSWORD=your password --network="host" your_image_name + ``` ## Test for autorization: diff --git a/tests/basic_selenium_test.py b/tests/basic_selenium_test.py index cf5ad0b1..f1b9e983 100644 --- a/tests/basic_selenium_test.py +++ b/tests/basic_selenium_test.py @@ -8,17 +8,15 @@ class BasicSeleniumTest(unittest.TestCase): chrome_options = Options() service = Service(executable_path='/usr/bin/chromedriver') - chrome_options.add_argument("--no-sandbox") chrome_options.add_argument("--headless=new") - chrome_options.add_argument("--disable-gpu") + chrome_options.add_argument('--disable-gpu') + chrome_options.add_argument("--no-sandbox") driver = webdriver.Chrome(options=chrome_options, service=service) def authorization(self): host, login_param, password_param = self.param URL = self.getUrl('/login') - print(111111111111111) - print(URL) self.getDriver().get(URL) self.getDriver().implicitly_wait(30) login = self.getDriver().find_element(By.ID, "login_text_field") diff --git a/tests/test_authorization.py b/tests/test_authorization.py index 02683bcf..12de2ed8 100644 --- a/tests/test_authorization.py +++ b/tests/test_authorization.py @@ -1,4 +1,5 @@ import os +import time from basic_selenium_test import BasicSeleniumTest from selenium.webdriver.common.by import By @@ -32,6 +33,8 @@ def test_failed_auth(self): def test_complete_auth(self): host, login, password = self.param + time.sleep(10) self.check_auth(login, password) + time.sleep(10) upload_url = self.getUrl('/upload') self.assertIn(upload_url, self.getDriver().current_url) diff --git a/tests/test_statistic.py b/tests/test_statistic.py index 6ca1ca44..d4643a93 100644 --- a/tests/test_statistic.py +++ b/tests/test_statistic.py @@ -1,4 +1,4 @@ -import unittest +import time from basic_selenium_test import BasicSeleniumTest from selenium.webdriver.common.by import By from selenium.common.exceptions import NoSuchElementException @@ -7,6 +7,7 @@ class StatisticTestSelenium(BasicSeleniumTest): def test_open_statistic(self): self.authorization() + time.sleep(10) URL = self.getUrl('/check_list') self.getDriver().get(URL) self.getDriver().implicitly_wait(30)