From 76d7644202c87de7c1d12a9a0f8e96fb7811e5ed Mon Sep 17 00:00:00 2001 From: Marina Date: Tue, 6 Feb 2024 14:37:55 +0300 Subject: [PATCH 1/4] copied from 485 --- tests/README.md | 21 +++++++++++++++++++++ tests/basic_selenium_test.py | 30 ++++++++++++++++++++++++++++++ tests/main.py | 26 ++++++++++++++++++++++++++ 3 files changed, 77 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..3bcc009a --- /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 open page debug: +class DebugTestSelenium(BasicSeleniumTest) with 1 test + +Test check: if page "/debug" opens + +## 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..f5eb67a2 --- /dev/null +++ b/tests/main.py @@ -0,0 +1,26 @@ +import unittest +import sys +import argparse +from basic_selenium_test import BasicSeleniumTest +from test_debug import DebugTestSelenium + +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(DebugTestSelenium, 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 0c83e22c1c002d983587a1d300944139bb0cbe29 Mon Sep 17 00:00:00 2001 From: Marina Date: Tue, 6 Feb 2024 14:38:43 +0300 Subject: [PATCH 2/4] added test_debug.py --- tests/test_debug.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tests/test_debug.py diff --git a/tests/test_debug.py b/tests/test_debug.py new file mode 100644 index 00000000..01e78c3a --- /dev/null +++ b/tests/test_debug.py @@ -0,0 +1,25 @@ +import os +from basic_selenium_test import BasicSeleniumTest +from selenium.webdriver.common.by import By + +class DebugTestSelenium(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 333365837f3311ba0ce57915f9878beb98ae3460 Mon Sep 17 00:00:00 2001 From: Marina Date: Wed, 7 Feb 2024 17:41:11 +0300 Subject: [PATCH 3/4] version_test done --- tests/README.md | 4 ++-- tests/basic_selenium_test.py | 17 +++++++++++++++++ tests/main.py | 4 ++-- tests/test_debug.py | 25 ------------------------- 4 files changed, 21 insertions(+), 29 deletions(-) delete mode 100644 tests/test_debug.py diff --git a/tests/README.md b/tests/README.md index 3bcc009a..e5450961 100644 --- a/tests/README.md +++ b/tests/README.md @@ -8,9 +8,9 @@ pip install webdriver-manager (to avoid problem with binary. And you should have webdriver-manager==4.0.1 ## Test for open page debug: -class DebugTestSelenium(BasicSeleniumTest) with 1 test +class VersionTestSelenium(BasicSeleniumTest) with 1 test -Test check: if page "/debug" opens +Test check: if page "/version" opens and contains info from "VERSION.json" ## Run run_tests 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/main.py b/tests/main.py index f5eb67a2..de5cf3ae 100644 --- a/tests/main.py +++ b/tests/main.py @@ -2,7 +2,7 @@ import sys import argparse from basic_selenium_test import BasicSeleniumTest -from test_debug import DebugTestSelenium +from test_version import VersionTestSelenium def parse_arguments(): parser = argparse.ArgumentParser(description='Run Selenium tests with specified host, login, and password.') @@ -15,7 +15,7 @@ def main(): args = parse_arguments() suite = unittest.TestSuite() - suite.addTest(BasicSeleniumTest.parametrize(DebugTestSelenium, param=(args.host, args.login, args.password))) + suite.addTest(BasicSeleniumTest.parametrize(VersionTestSelenium, param=(args.host, args.login, args.password))) returnCode = not unittest.TextTestRunner(verbosity=2).run(suite).wasSuccessful() diff --git a/tests/test_debug.py b/tests/test_debug.py deleted file mode 100644 index 01e78c3a..00000000 --- a/tests/test_debug.py +++ /dev/null @@ -1,25 +0,0 @@ -import os -from basic_selenium_test import BasicSeleniumTest -from selenium.webdriver.common.by import By - -class DebugTestSelenium(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 a45c1a105fecfeb5c7f18cffbfcef0aa6b205113 Mon Sep 17 00:00:00 2001 From: Marina Date: Wed, 7 Feb 2024 17:53:32 +0300 Subject: [PATCH 4/4] tests/requirements.txt added --- tests/README.md | 14 ++++++++------ tests/requirements.txt | 2 ++ tests/test_version.py | 14 ++++++++++++++ 3 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 tests/requirements.txt create mode 100644 tests/test_version.py diff --git a/tests/README.md b/tests/README.md index e5450961..96ca441a 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 page debug: +```bash +$ pip install -r tests/requirements.txt +``` + + +## Test for open page /version: class VersionTestSelenium(BasicSeleniumTest) with 1 test Test check: if page "/version" opens and contains info from "VERSION.json" 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_version.py b/tests/test_version.py new file mode 100644 index 00000000..1064c663 --- /dev/null +++ b/tests/test_version.py @@ -0,0 +1,14 @@ +import os +from basic_selenium_test import BasicSeleniumTest +from selenium.webdriver.common.by import By + +class VersionTestSelenium(BasicSeleniumTest): + + def test_version(self): + self.authorization() + URL = self.getUrl('/version') + self.getDriver().get(URL) + self.getDriver().implicitly_wait(30) + obj = self.getDriver().find_element(By.ID, "version-table") + self.assertNotEquals(obj, None) +