Skip to content

Commit

Permalink
Tests added in Docker (ready)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarinaProsche committed Feb 27, 2024
1 parent 83e8fa4 commit 11febfa
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 10 deletions.
5 changes: 4 additions & 1 deletion Dockerfile_selenium
Original file line number Diff line number Diff line change
Expand Up @@ -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}
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 7 additions & 4 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
6 changes: 2 additions & 4 deletions tests/basic_selenium_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 3 additions & 0 deletions tests/test_authorization.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import time
from basic_selenium_test import BasicSeleniumTest
from selenium.webdriver.common.by import By

Expand Down Expand Up @@ -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)
3 changes: 2 additions & 1 deletion tests/test_statistic.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 11febfa

Please sign in to comment.