From b8ee64e7291445467eb5e8149a5c6284db7bf394 Mon Sep 17 00:00:00 2001 From: Marina Date: Mon, 11 Dec 2023 11:46:51 +0300 Subject: [PATCH 1/8] add folder tests --- tests/test_authoriation | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/test_authoriation diff --git a/tests/test_authoriation b/tests/test_authoriation new file mode 100644 index 00000000..e69de29b From 2218ad6605fa5737204f3ad7d9b02a9305111f7d Mon Sep 17 00:00:00 2001 From: Marina Date: Mon, 11 Dec 2023 20:09:15 +0300 Subject: [PATCH 2/8] add test folder and first test --- requirements.txt | 1 + tests/basic_selenium_test.py | 44 ++++++++++++++++++++++++++++++++++++ tests/main.py | 24 ++++++++++++++++++++ tests/test_authoriation | 0 tests/test_authorization.py | 36 +++++++++++++++++++++++++++++ 5 files changed, 105 insertions(+) create mode 100644 tests/basic_selenium_test.py create mode 100644 tests/main.py delete mode 100644 tests/test_authoriation create mode 100644 tests/test_authorization.py diff --git a/requirements.txt b/requirements.txt index 0d87cf6c..08fd098f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -28,3 +28,4 @@ pytest~=7.1.2 filetype==1.2.0 language-tool-python==2.7.1 markdown==3.4.4 +selenium==4.16.0 diff --git a/tests/basic_selenium_test.py b/tests/basic_selenium_test.py new file mode 100644 index 00000000..0ef8bac7 --- /dev/null +++ b/tests/basic_selenium_test.py @@ -0,0 +1,44 @@ +import unittest +from selenium import webdriver +from selenium.webdriver.firefox.service import Service as FirefoxService +from webdriver_manager.firefox import GeckoDriverManager +from selenium.webdriver.firefox.options import Options + +class BasicSeleniumTest(unittest.TestCase): + + # options = Options() + # options.binary_location = r'~/home/snap/bin/firefox' + # driver = webdriver.Firefox(options=options) + + driver = webdriver.Firefox(service=FirefoxService(GeckoDriverManager().install())) + + def __init__(self, methodName='runTest', param=None): + super(BasicSeleniumTest, self).__init__(methodName) + self.param = param + + @staticmethod + def parametrize(testcase_klass, param=None): + testloader = unittest.TestLoader() + testnames = testloader.getTestCaseNames(testcase_klass) + suite = unittest.TestSuite() + for name in testnames: + suite.addTest(testcase_klass(name, param=param)) + return suite + + def getUrl(self, relativePath): + return self.param + relativePath + + def getDriver(_): + return BasicSeleniumTest.driver + + @classmethod + def closeDriver(cls): + cls.driver.close() + + + +# def setUp(self): +# self.driver = webdriver.Firefox() # Chrome() + +# def tearDown(self): +# self.driver.close() diff --git a/tests/main.py b/tests/main.py new file mode 100644 index 00000000..c0c3be3e --- /dev/null +++ b/tests/main.py @@ -0,0 +1,24 @@ +import unittest +import sys +from basic_selenium_test import BasicSeleniumTest +from test_authorization import AuthTestSelenium + + +def main(host): + suite = unittest.TestSuite() + + suite.addTest( + BasicSeleniumTest.parametrize( + AuthTestSelenium, + param=host)) + + returnCode = not unittest.TextTestRunner( + verbosity=2).run(suite).wasSuccessful() + + BasicSeleniumTest.closeDriver() + sys.exit(returnCode) + + +if __name__ == '__main__': + host_arg = 'https://slides-checker.moevm.info' + main(host_arg) diff --git a/tests/test_authoriation b/tests/test_authoriation deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/test_authorization.py b/tests/test_authorization.py new file mode 100644 index 00000000..2990c8d2 --- /dev/null +++ b/tests/test_authorization.py @@ -0,0 +1,36 @@ +import unittest +import time +from basic_selenium_test import BasicSeleniumTest +from selenium.webdriver.common.by import By + +# AUTH_URL = 'https://slides-checker.moevm.info/login' + +class AuthTestSelenium(BasicSeleniumTest): + + 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) + return True + + + def failed_auth(self): + 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('wrong_login') + + password = self.getDriver().find_element(By.ID, "password_text_field") + password.clear() + password.send_keys('wrong_password') + + login_button = self.getDriver().find_element(By.ID, "login_button") + login_button.click() + obj = self.getDriver().find_element(By.CLASS_NAME, "invalid-feedback ins") + self.assertNotEquals(obj, None) + From e095e915d70aae8c2490c50033bed513009eb558 Mon Sep 17 00:00:00 2001 From: Marina Date: Tue, 12 Dec 2023 15:22:17 +0300 Subject: [PATCH 3/8] first version of auyh tests --- requirements.txt | 3 ++- tests/README.md | 19 ++++++++++++++++++ tests/basic_selenium_test.py | 18 ++--------------- tests/main.py | 3 +-- tests/test_authorization.py | 39 ++++++++++++++++++------------------ 5 files changed, 43 insertions(+), 39 deletions(-) create mode 100644 tests/README.md diff --git a/requirements.txt b/requirements.txt index 08fd098f..00313ba3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 @@ -29,3 +29,4 @@ filetype==1.2.0 language-tool-python==2.7.1 markdown==3.4.4 selenium==4.16.0 +webdriver-manager==4.0.1 diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 00000000..504f3409 --- /dev/null +++ b/tests/README.md @@ -0,0 +1,19 @@ +## For beginning: + +Install: +pip install selenium +(selenium==4.16.0 (in this version you don't need to download geckodriver)) + +pip install webdriver-manager (to avoid problem with binary. And you should have Firefox installed not in 'snap') +webdriver-manager==4.0.1 + +## Test for autorization: +class AuthTestSelenium(BasicSeleniumTest) with 3 tests + +Tests check: if page "/login" opens, if it doesn't take wrong login/password and takes correct. + +## Run run_tests + +```bash +$ python main.py +``` diff --git a/tests/basic_selenium_test.py b/tests/basic_selenium_test.py index 0ef8bac7..2cdd99b5 100644 --- a/tests/basic_selenium_test.py +++ b/tests/basic_selenium_test.py @@ -1,17 +1,11 @@ import unittest from selenium import webdriver from selenium.webdriver.firefox.service import Service as FirefoxService -from webdriver_manager.firefox import GeckoDriverManager -from selenium.webdriver.firefox.options import Options +from webdriver_manager.firefox import GeckoDriverManager #pip install webdriver-manager class BasicSeleniumTest(unittest.TestCase): - - # options = Options() - # options.binary_location = r'~/home/snap/bin/firefox' - # driver = webdriver.Firefox(options=options) - - driver = webdriver.Firefox(service=FirefoxService(GeckoDriverManager().install())) + driver = webdriver.Firefox(service=FirefoxService(GeckoDriverManager().install())) #you should have Firefox, installed not from snap def __init__(self, methodName='runTest', param=None): super(BasicSeleniumTest, self).__init__(methodName) self.param = param @@ -34,11 +28,3 @@ def getDriver(_): @classmethod def closeDriver(cls): cls.driver.close() - - - -# def setUp(self): -# self.driver = webdriver.Firefox() # Chrome() - -# def tearDown(self): -# self.driver.close() diff --git a/tests/main.py b/tests/main.py index c0c3be3e..35535fba 100644 --- a/tests/main.py +++ b/tests/main.py @@ -18,7 +18,6 @@ def main(host): BasicSeleniumTest.closeDriver() sys.exit(returnCode) - if __name__ == '__main__': - host_arg = 'https://slides-checker.moevm.info' + host_arg = 'http://127.0.0.1:8080' main(host_arg) diff --git a/tests/test_authorization.py b/tests/test_authorization.py index 2990c8d2..8a92b7c2 100644 --- a/tests/test_authorization.py +++ b/tests/test_authorization.py @@ -1,36 +1,35 @@ -import unittest -import time +import os from basic_selenium_test import BasicSeleniumTest from selenium.webdriver.common.by import By -# AUTH_URL = 'https://slides-checker.moevm.info/login' - class AuthTestSelenium(BasicSeleniumTest): - 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) - return True - - - def failed_auth(self): + 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('wrong_login') - + login.send_keys(login_param) password = self.getDriver().find_element(By.ID, "password_text_field") password.clear() - password.send_keys('wrong_password') - + password.send_keys(password_param) login_button = self.getDriver().find_element(By.ID, "login_button") login_button.click() - obj = self.getDriver().find_element(By.CLASS_NAME, "invalid-feedback ins") + + 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): + 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): + self.check_auth(os.environ['ADMIN_PASSWORD'], os.environ['ADMIN_PASSWORD']) + upload_url = self.getUrl('/upload') + self.assertIn(upload_url, self.getDriver().current_url) From 10950d7a0ec3c5f92aa8b20b1f15e6d7ef2c7910 Mon Sep 17 00:00:00 2001 From: Marina Date: Fri, 29 Dec 2023 18:33:39 +0300 Subject: [PATCH 4/8] added param in commandline and class --- tests/README.md | 4 +++- tests/basic_selenium_test.py | 8 ++++---- tests/main.py | 24 ++++++++++++++---------- tests/test_authorization.py | 4 +++- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/tests/README.md b/tests/README.md index 504f3409..fdaf0fc0 100644 --- a/tests/README.md +++ b/tests/README.md @@ -14,6 +14,8 @@ Tests check: if page "/login" opens, if it doesn't take wrong login/password and ## Run run_tests +use login and password from .env + ```bash -$ python main.py +$ python tests/main.py --host host --login login --password password ``` diff --git a/tests/basic_selenium_test.py b/tests/basic_selenium_test.py index 2cdd99b5..ea9dd50e 100644 --- a/tests/basic_selenium_test.py +++ b/tests/basic_selenium_test.py @@ -11,16 +11,16 @@ def __init__(self, methodName='runTest', param=None): self.param = param @staticmethod - def parametrize(testcase_klass, param=None): + def parametrize(testcase_class, param=None): testloader = unittest.TestLoader() - testnames = testloader.getTestCaseNames(testcase_klass) + testnames = testloader.getTestCaseNames(testcase_class) suite = unittest.TestSuite() for name in testnames: - suite.addTest(testcase_klass(name, param=param)) + suite.addTest(testcase_class(name, param=param)) return suite def getUrl(self, relativePath): - return self.param + relativePath + return self.param[0] + relativePath def getDriver(_): return BasicSeleniumTest.driver diff --git a/tests/main.py b/tests/main.py index 35535fba..0bd9d178 100644 --- a/tests/main.py +++ b/tests/main.py @@ -1,23 +1,27 @@ import unittest import sys +import argparse from basic_selenium_test import BasicSeleniumTest from test_authorization import AuthTestSelenium -def main(host): - suite = unittest.TestSuite() +def parse_arguments(): + parser = argparse.ArgumentParser(description='Run Selenium tests with specified host, login, and password.') + parser.add_argument('--host', type=str, default='http://127.0.0.1:8080', help='Host address for testing') + parser.add_argument('--login', type=str, required=True, help='insert Username') + parser.add_argument('--password', type=str, required=True, help='insert Password') + return parser.parse_args() + +def main(): + args = parse_arguments() - suite.addTest( - BasicSeleniumTest.parametrize( - AuthTestSelenium, - param=host)) + suite = unittest.TestSuite() + suite.addTest(BasicSeleniumTest.parametrize(AuthTestSelenium, param=(args.host, args.login, args.password))) - returnCode = not unittest.TextTestRunner( - verbosity=2).run(suite).wasSuccessful() + returnCode = not unittest.TextTestRunner(verbosity=2).run(suite).wasSuccessful() BasicSeleniumTest.closeDriver() sys.exit(returnCode) if __name__ == '__main__': - host_arg = 'http://127.0.0.1:8080' - main(host_arg) + main() diff --git a/tests/test_authorization.py b/tests/test_authorization.py index 8a92b7c2..02683bcf 100644 --- a/tests/test_authorization.py +++ b/tests/test_authorization.py @@ -25,11 +25,13 @@ def test_loading(self): 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): - self.check_auth(os.environ['ADMIN_PASSWORD'], os.environ['ADMIN_PASSWORD']) + host, login, password = self.param + self.check_auth(login, password) upload_url = self.getUrl('/upload') self.assertIn(upload_url, self.getDriver().current_url) From 3dc0bb79a41b95610d7d6d86927725b5a7c87f1d Mon Sep 17 00:00:00 2001 From: Marina Date: Mon, 22 Jan 2024 13:08:15 +0300 Subject: [PATCH 5/8] from basic test --- tests/README.md | 21 +++++++++++++++++++++ tests/basic_selenium_test.py | 30 ++++++++++++++++++++++++++++++ tests/main.py | 27 +++++++++++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 tests/README.md create mode 100644 tests/basic_selenium_test.py create mode 100644 tests/main.py diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 00000000..fdaf0fc0 --- /dev/null +++ b/tests/README.md @@ -0,0 +1,21 @@ +## For beginning: + +Install: +pip install selenium +(selenium==4.16.0 (in this version you don't need to download geckodriver)) + +pip install webdriver-manager (to avoid problem with binary. And you should have Firefox installed not in 'snap') +webdriver-manager==4.0.1 + +## Test for autorization: +class AuthTestSelenium(BasicSeleniumTest) with 3 tests + +Tests check: if page "/login" opens, if it doesn't take wrong login/password and takes correct. + +## Run run_tests + +use login and password from .env + +```bash +$ python tests/main.py --host host --login login --password password +``` diff --git a/tests/basic_selenium_test.py b/tests/basic_selenium_test.py new file mode 100644 index 00000000..ea9dd50e --- /dev/null +++ b/tests/basic_selenium_test.py @@ -0,0 +1,30 @@ +import unittest +from selenium import webdriver +from selenium.webdriver.firefox.service import Service as FirefoxService +from webdriver_manager.firefox import GeckoDriverManager #pip install webdriver-manager + +class BasicSeleniumTest(unittest.TestCase): + + driver = webdriver.Firefox(service=FirefoxService(GeckoDriverManager().install())) #you should have Firefox, installed not from snap + def __init__(self, methodName='runTest', param=None): + super(BasicSeleniumTest, self).__init__(methodName) + self.param = param + + @staticmethod + def parametrize(testcase_class, param=None): + testloader = unittest.TestLoader() + testnames = testloader.getTestCaseNames(testcase_class) + suite = unittest.TestSuite() + for name in testnames: + suite.addTest(testcase_class(name, param=param)) + return suite + + def getUrl(self, relativePath): + return self.param[0] + relativePath + + def getDriver(_): + return BasicSeleniumTest.driver + + @classmethod + def closeDriver(cls): + cls.driver.close() diff --git a/tests/main.py b/tests/main.py new file mode 100644 index 00000000..0bd9d178 --- /dev/null +++ b/tests/main.py @@ -0,0 +1,27 @@ +import unittest +import sys +import argparse +from basic_selenium_test import BasicSeleniumTest +from test_authorization import AuthTestSelenium + + +def parse_arguments(): + parser = argparse.ArgumentParser(description='Run Selenium tests with specified host, login, and password.') + parser.add_argument('--host', type=str, default='http://127.0.0.1:8080', help='Host address for testing') + parser.add_argument('--login', type=str, required=True, help='insert Username') + parser.add_argument('--password', type=str, required=True, help='insert Password') + return parser.parse_args() + +def main(): + args = parse_arguments() + + suite = unittest.TestSuite() + suite.addTest(BasicSeleniumTest.parametrize(AuthTestSelenium, param=(args.host, args.login, args.password))) + + returnCode = not unittest.TextTestRunner(verbosity=2).run(suite).wasSuccessful() + + BasicSeleniumTest.closeDriver() + sys.exit(returnCode) + +if __name__ == '__main__': + main() From 05c504f0ac878b36cc4cc5621d63e803babba149 Mon Sep 17 00:00:00 2001 From: Marina Date: Mon, 22 Jan 2024 14:31:52 +0300 Subject: [PATCH 6/8] first version of test_statistic --- tests/README.md | 6 +++--- tests/main.py | 5 ++--- tests/test_statistic.py | 25 +++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 tests/test_statistic.py diff --git a/tests/README.md b/tests/README.md index fdaf0fc0..e76c5f85 100644 --- a/tests/README.md +++ b/tests/README.md @@ -7,10 +7,10 @@ pip install selenium pip install webdriver-manager (to avoid problem with binary. And you should have Firefox installed not in 'snap') webdriver-manager==4.0.1 -## Test for autorization: -class AuthTestSelenium(BasicSeleniumTest) with 3 tests +## Test for open statistic: +class StatisticTestSelenium(BasicSeleniumTest) with 1 test -Tests check: if page "/login" opens, if it doesn't take wrong login/password and takes correct. +Test check: if page "/check_list" opens ## Run run_tests diff --git a/tests/main.py b/tests/main.py index 0bd9d178..e16af4a7 100644 --- a/tests/main.py +++ b/tests/main.py @@ -2,8 +2,7 @@ import sys import argparse from basic_selenium_test import BasicSeleniumTest -from test_authorization import AuthTestSelenium - +from test_statistic import StatisticTestSelenium def parse_arguments(): parser = argparse.ArgumentParser(description='Run Selenium tests with specified host, login, and password.') @@ -16,7 +15,7 @@ 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() diff --git a/tests/test_statistic.py b/tests/test_statistic.py new file mode 100644 index 00000000..e2029d36 --- /dev/null +++ b/tests/test_statistic.py @@ -0,0 +1,25 @@ +import os +from basic_selenium_test import BasicSeleniumTest +from selenium.webdriver.common.by import By + +class StatisticTestSelenium(BasicSeleniumTest): + + def test_open_statistic(self): + host, login_param, password_param = self.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() + URL = self.getUrl('/check_list') + self.getDriver().get(URL) + self.getDriver().implicitly_wait(30) + obj = self.getDriver().find_element(By.CLASS_NAME, "fixed-table-container") + self.assertNotEquals(obj, None) + From c216d92bb8b8ab78d4f87dd43e85f343e2289c37 Mon Sep 17 00:00:00 2001 From: Marina Date: Wed, 7 Feb 2024 18:07:19 +0300 Subject: [PATCH 7/8] requrements.txt and def authorization() added --- tests/README.md | 14 ++++++++------ tests/basic_selenium_test.py | 17 +++++++++++++++++ tests/requirements.txt | 2 ++ tests/test_statistic.py | 13 +------------ 4 files changed, 28 insertions(+), 18 deletions(-) create mode 100644 tests/requirements.txt diff --git a/tests/README.md b/tests/README.md index e76c5f85..e2f61ebb 100644 --- a/tests/README.md +++ b/tests/README.md @@ -1,13 +1,15 @@ ## For beginning: -Install: -pip install selenium -(selenium==4.16.0 (in this version you don't need to download geckodriver)) +You should have Firefox, installed not in 'snap'. -pip install webdriver-manager (to avoid problem with binary. And you should have Firefox installed not in 'snap') -webdriver-manager==4.0.1 +Install requirements.txt: -## Test for open statistic: +```bash +$ pip install -r tests/requirements.txt +``` + + +## Test for open page /version: class StatisticTestSelenium(BasicSeleniumTest) with 1 test Test check: if page "/check_list" opens diff --git a/tests/basic_selenium_test.py b/tests/basic_selenium_test.py index ea9dd50e..0485faa1 100644 --- a/tests/basic_selenium_test.py +++ b/tests/basic_selenium_test.py @@ -1,11 +1,28 @@ import unittest from selenium import webdriver from selenium.webdriver.firefox.service import Service as FirefoxService +from selenium.webdriver.common.by import By from webdriver_manager.firefox import GeckoDriverManager #pip install webdriver-manager class BasicSeleniumTest(unittest.TestCase): driver = webdriver.Firefox(service=FirefoxService(GeckoDriverManager().install())) #you should have Firefox, installed not from snap + + def authorization(self): + host, login_param, password_param = self.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 __init__(self, methodName='runTest', param=None): super(BasicSeleniumTest, self).__init__(methodName) self.param = param diff --git a/tests/requirements.txt b/tests/requirements.txt new file mode 100644 index 00000000..c384f7a9 --- /dev/null +++ b/tests/requirements.txt @@ -0,0 +1,2 @@ +selenium==4.16.0 #in this version you don't need to download geckodriver +webdriver-manager==4.0.1 #to avoid problem with binary diff --git a/tests/test_statistic.py b/tests/test_statistic.py index e2029d36..61d403d8 100644 --- a/tests/test_statistic.py +++ b/tests/test_statistic.py @@ -5,18 +5,7 @@ class StatisticTestSelenium(BasicSeleniumTest): def test_open_statistic(self): - host, login_param, password_param = self.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() + self.authorization() URL = self.getUrl('/check_list') self.getDriver().get(URL) self.getDriver().implicitly_wait(30) From 0145493a3a16978d9321f8c2b4eeb81f7494f065 Mon Sep 17 00:00:00 2001 From: Marina Date: Wed, 21 Feb 2024 17:08:48 +0300 Subject: [PATCH 8/8] test_statistic improved --- tests/test_statistic.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/test_statistic.py b/tests/test_statistic.py index 61d403d8..0da75881 100644 --- a/tests/test_statistic.py +++ b/tests/test_statistic.py @@ -1,6 +1,7 @@ import os from basic_selenium_test import BasicSeleniumTest from selenium.webdriver.common.by import By +from selenium.common.exceptions import NoSuchElementException class StatisticTestSelenium(BasicSeleniumTest): @@ -9,6 +10,9 @@ def test_open_statistic(self): URL = self.getUrl('/check_list') self.getDriver().get(URL) self.getDriver().implicitly_wait(30) - obj = self.getDriver().find_element(By.CLASS_NAME, "fixed-table-container") - self.assertNotEquals(obj, None) - + try: + string_in_table = self.getDriver().find_element(By.XPATH, "//table[@id='check-list-table']//tr/td/a") + self.assertNotEquals(string_in_table, None) + except NoSuchElementException: + empty_table = self.getDriver().find_element(By.CLASS_NAME, "no-records-found") + self.assertNotEquals(empty_table, None)