From d462a127ee32d3fb4a546f8d2eb67784b2d7798f Mon Sep 17 00:00:00 2001 From: Marina Date: Mon, 11 Mar 2024 12:07:40 +0300 Subject: [PATCH] structure is improved --- tests/README.md | 10 ++------ tests/basic_selenium_test.py | 3 +++ tests/main.py | 5 ++-- tests/test_pres_load.py | 31 ------------------------- tests/test_report_load.py | 41 --------------------------------- tests/test_single_card_check.py | 1 - tests/test_statistic.py | 1 - tests/test_version.py | 5 ++-- 8 files changed, 10 insertions(+), 87 deletions(-) delete mode 100644 tests/test_pres_load.py delete mode 100644 tests/test_report_load.py diff --git a/tests/README.md b/tests/README.md index 2f04a045..462854d0 100644 --- a/tests/README.md +++ b/tests/README.md @@ -54,12 +54,6 @@ class StatisticTestSelenium(BasicSeleniumTest) with 1 test Test check: if page "/check_list" opens -### Test for loading presentation: - -class PresLoadTestSelenium(BasicSeleniumTest) with 1 test -Test check: if the presentation loads correctly -use path to "example_of_pres.pptx" from "/tests" (default) or your own example - ### Test for open single check card: class SingleCheckTestSelenium(BasicSeleniumTest) with 1 test @@ -70,9 +64,9 @@ Test check: if page with random single check opens (from "/check_list") class VersionTestSelenium(BasicSeleniumTest) with 1 test Test check: if page "/version" opens and contains info from "VERSION.json" -### Test for loading report: +### Test for loading report and pres: -class ReportLoadTestSelenium(BasicSeleniumTest) with 2 tests +class FileLoadTestSelenium(BasicSeleniumTest) with 3 tests Test check: if reports wit different extensions loads correctly use default documents from "/tests" or your own example diff --git a/tests/basic_selenium_test.py b/tests/basic_selenium_test.py index 5a6e00a2..e686e77f 100644 --- a/tests/basic_selenium_test.py +++ b/tests/basic_selenium_test.py @@ -4,6 +4,8 @@ from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.chrome.service import Service +from selenium.webdriver.support.wait import WebDriverWait +from selenium.webdriver.support import expected_conditions as EC class BasicSeleniumTest(unittest.TestCase): @@ -36,6 +38,7 @@ def authorization(self): password.send_keys(password_param) login_button = self.getDriver().find_element(By.ID, "login_button") login_button.click() + WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.ID, "upload_upload_button"))) def __init__(self, methodName='runTest', param=None): diff --git a/tests/main.py b/tests/main.py index 22a16e81..cc3ea851 100644 --- a/tests/main.py +++ b/tests/main.py @@ -8,7 +8,7 @@ from test_pres_load import PresLoadTestSelenium from test_single_card_check import SingleCheckTestSelenium from test_version import VersionTestSelenium -from test_report_load import ReportLoadTestSelenium +from tests.test_file_load import FileLoadTestSelenium def parse_arguments(): parser = argparse.ArgumentParser(description='Run Selenium tests with specified data') @@ -29,8 +29,7 @@ def main(): 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))) - suite.addTest(BasicSeleniumTest.parametrize(ReportLoadTestSelenium, param=(args.host, args.login, args.password, args.report, args.report_doc))) - suite.addTest(BasicSeleniumTest.parametrize(PresLoadTestSelenium, param=(args.host, args.login, args.password, args.pres))) + suite.addTest(BasicSeleniumTest.parametrize(FileLoadTestSelenium, param=(args.host, args.login, args.password, args.report, args.report_doc, args.pres))) suite.addTest(BasicSeleniumTest.parametrize(SingleCheckTestSelenium, param=(args.host, args.login, args.password))) suite.addTest(BasicSeleniumTest.parametrize(VersionTestSelenium, param=(args.host, args.login, args.password))) diff --git a/tests/test_pres_load.py b/tests/test_pres_load.py deleted file mode 100644 index 9fa0fe43..00000000 --- a/tests/test_pres_load.py +++ /dev/null @@ -1,31 +0,0 @@ -import os -import time -from basic_selenium_test import BasicSeleniumTest -from selenium.webdriver.common.by import By - -class PresLoadTestSelenium(BasicSeleniumTest): - - def test_pres_load(self): - self.authorization() - pres = self.param[3] - URL = self.getUrl('/upload') - self.getDriver().get(URL) - self.getDriver().implicitly_wait(30) - obj = self.getDriver().find_element(By.XPATH, "/html/body/div/div[2]/div/p/b") - if obj.text == 'BasePresentationCriterionPack': - form_for_load = self.getDriver().find_element(By.CSS_SELECTOR, 'input[type=file]') - form_for_load.send_keys(pres) - load_button = self.getDriver().find_element(By.XPATH, '//*[@id="upload_upload_button"]') - load_button.click() - obj = self.getDriver().find_element(By.XPATH, '/html/body/div/div[2]/h4/i') - if obj.text == 'Производится проверка файла. Примерное время: 229999.1 секунд (перезагрузите страницу)': - time.sleep(30) - self.getDriver().refresh() - self.getDriver().implicitly_wait(30) - obj = self.getDriver().find_element(By.ID, 'results_table') - self.assertNotEquals(obj, None) - else: - self.fail("file didn't upload") - else: - self.skipTest("Current criteria pack is not for pres") - diff --git a/tests/test_report_load.py b/tests/test_report_load.py deleted file mode 100644 index 02252b46..00000000 --- a/tests/test_report_load.py +++ /dev/null @@ -1,41 +0,0 @@ -import time -from basic_selenium_test import BasicSeleniumTest -from selenium.webdriver.common.by import By - -class ReportLoadTestSelenium(BasicSeleniumTest): - - def upload_report(self, report_ext): - self.authorization() - report = report_ext - URL = self.getUrl('/upload') - self.getDriver().get(URL) - self.getDriver().implicitly_wait(240) - obj = self.getDriver().find_element(By.XPATH, "/html/body/div/div[2]/div/p/b") - if obj.text == 'BaseReportCriterionPack': - form_for_load = self.getDriver().find_element(By.CSS_SELECTOR, 'input[type=file]') - form_for_load.send_keys(report) - load_button = self.getDriver().find_element(By.XPATH, '//*[@id="upload_upload_button"]') - load_button.click() - time.sleep(10) - obj = self.getDriver().find_element(By.XPATH, '/html/body/div/div[2]/h4/i') - if obj.text == 'Производится проверка файла. Примерное время: 229999.1 секунд (перезагрузите страницу)': - start_time = time.time() - max_time = 240 - while time.time() - start_time < max_time: - time.sleep(10) - self.getDriver().refresh() - obj = self.getDriver().find_element(By.ID, 'results_table') - if obj is not None: - break - self.assertNotEquals(obj, None) - else: - self.fail("file didn't upload") - else: - self.skipTest("Current criteria pack is not for report") - - - def test_report_load_docx(self): - self.upload_report(self.param[3]) - - def test_report_load_doc(self): - self.upload_report(self.param[4]) diff --git a/tests/test_single_card_check.py b/tests/test_single_card_check.py index 8f7fff2c..ea4ee4c9 100644 --- a/tests/test_single_card_check.py +++ b/tests/test_single_card_check.py @@ -7,7 +7,6 @@ class SingleCheckTestSelenium(BasicSeleniumTest): def test_open_check_card(self): self.authorization() - time.sleep(10) URL = self.getUrl('/check_list') self.getDriver().get(URL) self.getDriver().implicitly_wait(240) diff --git a/tests/test_statistic.py b/tests/test_statistic.py index d4643a93..177971f3 100644 --- a/tests/test_statistic.py +++ b/tests/test_statistic.py @@ -7,7 +7,6 @@ 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) diff --git a/tests/test_version.py b/tests/test_version.py index 7d7c2544..e4fda151 100644 --- a/tests/test_version.py +++ b/tests/test_version.py @@ -2,12 +2,13 @@ import time from basic_selenium_test import BasicSeleniumTest from selenium.webdriver.common.by import By +from selenium.webdriver.support.wait import WebDriverWait +from selenium.webdriver.support import expected_conditions as EC class VersionTestSelenium(BasicSeleniumTest): def test_version(self): - self.authorization() - time.sleep(10) + self.authorization() URL = self.getUrl('/version') self.getDriver().get(URL) self.getDriver().implicitly_wait(30)