Skip to content

Commit

Permalink
Merge branch '481_first_selenium_test' into 485_selenium_test_statistic
Browse files Browse the repository at this point in the history
  • Loading branch information
MarinaProsche committed Feb 21, 2024
2 parents c216d92 + 10950d7 commit ed59b0f
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
werkzeug==2.0.0
Flask==2.0.3
jinja2==3.0.0
requests==2.24.0
requests==2.25.0
python-pptx==0.6.18
odfpy==1.4.1
pymongo==3.11.1
Expand All @@ -28,3 +28,5 @@ pytest~=7.1.2
filetype==1.2.0
language-tool-python==2.7.1
markdown==3.4.4
selenium==4.16.0
webdriver-manager==4.0.1
7 changes: 6 additions & 1 deletion tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@ Install requirements.txt:
$ pip install -r tests/requirements.txt
```

## Test for autorization:
class AuthTestSelenium(BasicSeleniumTest) with 3 tests

## Test for open page /version:
Tests check: if page "/login" opens, if it doesn't take wrong login/password and takes correct.

## Test for open page /check_list:
class StatisticTestSelenium(BasicSeleniumTest) with 1 test

Test check: if page "/check_list" opens


## Run run_tests

use login and password from .env
Expand Down
4 changes: 3 additions & 1 deletion tests/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import argparse
from basic_selenium_test import BasicSeleniumTest
from test_statistic import StatisticTestSelenium
from test_authorization import AuthTestSelenium

def parse_arguments():
parser = argparse.ArgumentParser(description='Run Selenium tests with specified host, login, and password.')
Expand All @@ -15,8 +16,9 @@ def main():
args = parse_arguments()

suite = unittest.TestSuite()
suite.addTest(BasicSeleniumTest.parametrize(AuthTestSelenium, param=(args.host, args.login, args.password)))
suite.addTest(BasicSeleniumTest.parametrize(StatisticTestSelenium, param=(args.host, args.login, args.password)))

returnCode = not unittest.TextTestRunner(verbosity=2).run(suite).wasSuccessful()

BasicSeleniumTest.closeDriver()
Expand Down
37 changes: 37 additions & 0 deletions tests/test_authorization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os
from basic_selenium_test import BasicSeleniumTest
from selenium.webdriver.common.by import By

class AuthTestSelenium(BasicSeleniumTest):

def check_auth(self, login_param, password_param):
URL = self.getUrl('/login')
self.getDriver().get(URL)
self.getDriver().implicitly_wait(30)
login = self.getDriver().find_element(By.ID, "login_text_field")
login.clear()
login.send_keys(login_param)
password = self.getDriver().find_element(By.ID, "password_text_field")
password.clear()
password.send_keys(password_param)
login_button = self.getDriver().find_element(By.ID, "login_button")
login_button.click()

def test_loading(self):
URL = self.getUrl('/login')
self.getDriver().get(URL)
self.getDriver().implicitly_wait(30)
obj = self.getDriver().find_element(By.CLASS_NAME, "form-group")
self.assertNotEquals(obj, None)

def test_failed_auth(self):
host, login, password = self.param
self.check_auth('wrong_login', 'wrong_password')
obj = self.getDriver().find_element(By.ID, "login_button")
self.assertNotEquals(obj, None)

def test_complete_auth(self):
host, login, password = self.param
self.check_auth(login, password)
upload_url = self.getUrl('/upload')
self.assertIn(upload_url, self.getDriver().current_url)

0 comments on commit ed59b0f

Please sign in to comment.