From 358c8f2ff6c192f1c7da004273e24e36f7b6b114 Mon Sep 17 00:00:00 2001 From: "PETERSBURG\\Elena_Veldina" Date: Wed, 26 May 2021 17:54:45 +0300 Subject: [PATCH 01/10] issue 51 --- requirements-dev.txt | 1 - requirements.txt | 1 - .../test/common/check_box_test.py | 65 ++++++------------ .../test/complex/check_list_test.py | 67 +++++++++---------- 4 files changed, 49 insertions(+), 85 deletions(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 70dba52..17f0c39 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -6,7 +6,6 @@ chardet==4.0.0 click==7.1.2 colorama==0.4.4 comtypes==1.1.8 -ddt==1.4.1 flake8==3.8.4 idna==2.10 isort==5.7.0 diff --git a/requirements.txt b/requirements.txt index 838a0e6..b3d39ed 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,3 @@ -ddt==1.4.1 pywin32==300 selenium==3.141.0 urllib3==1.26.4 diff --git a/tests/jdi_uitests_webtests/test/common/check_box_test.py b/tests/jdi_uitests_webtests/test/common/check_box_test.py index 778639b..5e93d81 100644 --- a/tests/jdi_uitests_webtests/test/common/check_box_test.py +++ b/tests/jdi_uitests_webtests/test/common/check_box_test.py @@ -1,62 +1,35 @@ -import unittest - import pytest -from ddt import data, ddt, unpack -from JDI.core.settings.jdi_settings import JDISettings from JDI.jdi_assert.testing.assertion import Assert from tests.jdi_uitests_webtests.main.enums.preconditions import Preconditions from tests.jdi_uitests_webtests.main.page_objects.epam_jdi_site import EpamJDISite from tests.jdi_uitests_webtests.main.utils.common_action_data import CommonActionsData -from tests.jdi_uitests_webtests.test.init_tests import InitTests MSG_TRUE = "Water: condition changed to true" MSG_FALSE = "Water: condition changed to false" -@pytest.mark.web -@ddt -class CheckBoxText(InitTests): +@pytest.fixture +def checkbox_setup(site): + Preconditions.METALS_AND_COLORS_PAGE.is_in_state() - check_box = EpamJDISite.metals_colors_page.cb_water - def setUp(self): - super(CheckBoxText, self).setUp(self.id().split(".")[-1]) - Preconditions.METALS_AND_COLORS_PAGE.is_in_state() +@pytest.mark.web +class TestCheckBoxText: - def tearDown(self): - JDISettings.get_driver_factory().get_driver().refresh() + check_box = EpamJDISite.metals_colors_page.cb_water - @data(("True", True), ("1", True), ("False", False), ("0", False)) - @unpack - def test_set_value(self, input, expected): + @pytest.mark.parametrize("input, expected", [("True", True), ("1", True), ("False", False), ("0", False)]) + def test_set_value(self, checkbox_setup, input, expected): if not expected: EpamJDISite.metals_colors_page.cb_water.click() EpamJDISite.metals_colors_page.cb_water.set_value(input) CommonActionsData.check_action("Water: condition changed to " + str(expected).lower()) - @data( - "true ", - "1 ", - " false", - "0 ", - " ", - "123", - " 1", - " 0", - "!@#$%^&*", - "qwdewf", - "1qwe", - "1qwe", - "true123", - "123true", - "false123", - "123false", - "o", - "O", - "tr ue", - ) - def test_set_value_nothing_changes(self, input): + @pytest.mark.parametrize("input", ["true ", "1 ", " false", "0 ", " ", "123", " 1", " 0", "!@#$%^&*", + "qwdewf", "1qwe", "1qwe", "true123", "123true", "false123", "123false", + "o", "O", "tr ue", ]) + def test_set_value_nothing_changes(self, checkbox_setup, input): self.check_box.click() self.check_box.set_value(input) CommonActionsData.check_action(MSG_TRUE) @@ -64,33 +37,33 @@ def test_set_value_nothing_changes(self, input): self.check_box.set_value(input) CommonActionsData.check_action(MSG_FALSE) - def test_check_single(self): + def test_check_single(self, checkbox_setup): self.check_box.check() CommonActionsData.check_action(MSG_TRUE) - def test_uncheck_single(self): + def test_uncheck_single(self, checkbox_setup): self.check_box.click() self.check_box.uncheck() CommonActionsData.check_action(MSG_FALSE) - def test_is_check(self): + def test_is_check(self, checkbox_setup): Assert.assert_false(self.check_box.is_checked()) self.check_box.click() Assert.assert_true(self.check_box.is_checked()) - def test_multi_uncheck(self): + def test_multi_uncheck(self, checkbox_setup): self.check_box.click() self.check_box.uncheck() self.check_box.uncheck() CommonActionsData.check_action(MSG_FALSE) - def test_multi_check(self): + def test_multi_check(self, checkbox_setup): self.check_box.check() self.check_box.check() CommonActionsData.check_action(MSG_TRUE) - def test_click(self): + def test_click(self, checkbox_setup): self.check_box.click() CommonActionsData.check_action(MSG_TRUE) self.check_box.click() - CommonActionsData.check_action(MSG_FALSE) + CommonActionsData.check_action(MSG_FALSE) \ No newline at end of file diff --git a/tests/jdi_uitests_webtests/test/complex/check_list_test.py b/tests/jdi_uitests_webtests/test/complex/check_list_test.py index 432f177..b1a97e6 100644 --- a/tests/jdi_uitests_webtests/test/complex/check_list_test.py +++ b/tests/jdi_uitests_webtests/test/complex/check_list_test.py @@ -1,7 +1,5 @@ -import unittest - import pytest -from ddt import data, ddt + from selenium.webdriver.common.by import By from JDI.core.settings.jdi_settings import JDISettings @@ -10,65 +8,64 @@ from tests.jdi_uitests_webtests.main.enums.preconditions import Preconditions from tests.jdi_uitests_webtests.main.page_objects.epam_jdi_site import EpamJDISite from tests.jdi_uitests_webtests.main.utils.common_action_data import CommonActionsData -from tests.jdi_uitests_webtests.test.init_tests import InitTests FIRE_MSG = "Fire: condition changed to true" WATER_MSG = "Water: condition changed to true" +@pytest.fixture +def check_list_setup(site): + Preconditions.METALS_AND_COLORS_PAGE.is_in_state() + + @pytest.mark.web -@ddt -class CheckListTests(InitTests): +class TestCheckList: nature_options = ["Water", "Earth", "Wind", "Fire"] all_values = "Water, Earth, Wind, Fire" check_list = EpamJDISite.metals_colors_page.nature_check_list - def setUp(self): - super(CheckListTests, self).setUp(self.id().split(".")[-1]) - Preconditions.METALS_AND_COLORS_PAGE.is_in_state() - - @data("Fire", 4, Nature.FIRE) - def test_select(self, value): + @pytest.mark.parametrize("value", ("Fire", 4, Nature.FIRE)) + def test_select(self, check_list_setup, value): self.check_list.select(value) CommonActionsData.check_action(FIRE_MSG) - def test_select_2_string(self): + def test_select_2_string(self, check_list_setup): self.check_list.select("Water", "Fire") CommonActionsData.check_action(FIRE_MSG, line_number=0) CommonActionsData.check_action(WATER_MSG, line_number=1) - def test_select_2_index(self): + def test_select_2_index(self, check_list_setup): self.check_list.select(1, 4) CommonActionsData.check_action(FIRE_MSG, line_number=0) CommonActionsData.check_action(WATER_MSG, line_number=1) - def test_select_2_enum(self): + def test_select_2_enum(self, check_list_setup): self.check_list.select(Nature.WATER, Nature.FIRE) CommonActionsData.check_action(FIRE_MSG, line_number=0) CommonActionsData.check_action(WATER_MSG, line_number=1) - @data("Fire", 4, Nature.FIRE) - def test_check(self, value): + @pytest.mark.parametrize("value", ("Fire", 4, Nature.FIRE)) + def test_check(self, check_list_setup, value): self.check_list.check(value) CommonActionsData.check_action(FIRE_MSG) - def test_check_2_string(self): + def test_check_2_string(self, check_list_setup): self.check_list.check("Water", "Fire") CommonActionsData.check_action(FIRE_MSG, line_number=0) CommonActionsData.check_action(WATER_MSG, line_number=1) - def test_check_2_index(self): + def test_check_2_index(self, check_list_setup): self.check_list.check(1, 4) CommonActionsData.check_action(FIRE_MSG, line_number=0) CommonActionsData.check_action(WATER_MSG, line_number=1) - def test_check_2_enum(self): + def test_check_2_enum(self, check_list_setup): self.check_list.check(Nature.WATER, Nature.FIRE) CommonActionsData.check_action(FIRE_MSG, line_number=0) CommonActionsData.check_action(WATER_MSG, line_number=1) - def test_select_all(self): + def test_select_all(self, check_list_setup): self.check_list.select_all() CommonActionsData.check_action(FIRE_MSG, line_number=0) CommonActionsData.check_action("Wind: condition changed to true", line_number=1) @@ -76,7 +73,7 @@ def test_select_all(self): CommonActionsData.check_action(WATER_MSG, line_number=3) self.check_all_checked() - def test_check_all(self): + def test_check_all(self, check_list_setup): self.check_list.check_all() CommonActionsData.check_action(FIRE_MSG, line_number=0) CommonActionsData.check_action("Wind: condition changed to true", line_number=1) @@ -84,44 +81,44 @@ def test_check_all(self): CommonActionsData.check_action(WATER_MSG, line_number=3) self.check_all_checked() - def test_clear_all(self): + def test_clear_all(self, check_list_setup): self.check_list.check_all() self.check_all_checked() self.check_list.clear() self.check_all_unchecked() - def test_uncheck_all(self): + def test_uncheck_all(self, check_list_setup): self.check_list.check_all() self.check_all_checked() self.check_list.uncheck_all() self.check_all_unchecked() - def test_get_options(self): + def test_get_options(self, check_list_setup): Assert.assert_equal(self.check_list.get_options(), self.nature_options) - def test_get_names(self): + def test_get_names(self, check_list_setup): Assert.assert_equal(self.check_list.get_names(), self.nature_options) - def test_get_values(self): + def test_get_values(self, check_list_setup): Assert.assert_equal(self.check_list.get_values(), self.nature_options) - def test_get_options_as_text(self): + def test_get_options_as_text(self, check_list_setup): Assert.assert_equal(self.check_list.get_options_as_text(), self.all_values) - def test_set_value(self): + def test_set_value(self, check_list_setup): self.check_list.set_value("Fire") CommonActionsData.check_action(FIRE_MSG) - def test_get_name(self): + def test_get_name(self, check_list_setup): Assert.assert_equal(self.check_list.get_name(), "nature_check_list") - def test_are_selected(self): + def test_are_selected(self, check_list_setup): Assert.assert_equal(self.check_list.are_selected(), []) - def test_are_deselected(self): + def test_are_deselected(self, check_list_setup): Assert.assert_equal(self.check_list.are_deselected(), self.nature_options) - def test_get_value(self): + def test_get_value(self, check_list_setup): Assert.assert_equal(self.check_list.get_value(), None) def check_all_checked(self): @@ -135,7 +132,3 @@ def check_all_unchecked(self): els = driver.find_elements(By.CSS_SELECTOR, value="#elements-checklist input") for el in els: Assert.assert_true(el.get_attribute("checked") in ["false", None]) - - -if __name__ == "__main__": - unittest.main() From b48a6f5e2fe20965834f1f22852f9053935cb8af Mon Sep 17 00:00:00 2001 From: "PETERSBURG\\Elena_Veldina" Date: Thu, 27 May 2021 12:36:00 +0300 Subject: [PATCH 02/10] fix 'Codacy Static Code Analysis' --- tests/jdi_uitests_webtests/test/common/check_box_test.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/jdi_uitests_webtests/test/common/check_box_test.py b/tests/jdi_uitests_webtests/test/common/check_box_test.py index 5e93d81..5c7557b 100644 --- a/tests/jdi_uitests_webtests/test/common/check_box_test.py +++ b/tests/jdi_uitests_webtests/test/common/check_box_test.py @@ -19,17 +19,17 @@ class TestCheckBoxText: check_box = EpamJDISite.metals_colors_page.cb_water - @pytest.mark.parametrize("input, expected", [("True", True), ("1", True), ("False", False), ("0", False)]) - def test_set_value(self, checkbox_setup, input, expected): + @pytest.mark.parametrize("input_value, expected", [("True", True), ("1", True), ("False", False), ("0", False)]) + def test_set_value(self, checkbox_setup, input_value, expected): if not expected: EpamJDISite.metals_colors_page.cb_water.click() EpamJDISite.metals_colors_page.cb_water.set_value(input) CommonActionsData.check_action("Water: condition changed to " + str(expected).lower()) - @pytest.mark.parametrize("input", ["true ", "1 ", " false", "0 ", " ", "123", " 1", " 0", "!@#$%^&*", + @pytest.mark.parametrize("input_value", ["true ", "1 ", " false", "0 ", " ", "123", " 1", " 0", "!@#$%^&*", "qwdewf", "1qwe", "1qwe", "true123", "123true", "false123", "123false", "o", "O", "tr ue", ]) - def test_set_value_nothing_changes(self, checkbox_setup, input): + def test_set_value_nothing_changes(self, checkbox_setup, input_value): self.check_box.click() self.check_box.set_value(input) CommonActionsData.check_action(MSG_TRUE) From 1add2ec3825af2c1a715d65bdedbfced66c3f1f6 Mon Sep 17 00:00:00 2001 From: "PETERSBURG\\Elena_Veldina" Date: Thu, 27 May 2021 12:53:22 +0300 Subject: [PATCH 03/10] fix 'Codacy Static Code Analysis' one more --- tests/jdi_uitests_webtests/test/common/check_box_test.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/jdi_uitests_webtests/test/common/check_box_test.py b/tests/jdi_uitests_webtests/test/common/check_box_test.py index 5c7557b..cc92d5c 100644 --- a/tests/jdi_uitests_webtests/test/common/check_box_test.py +++ b/tests/jdi_uitests_webtests/test/common/check_box_test.py @@ -19,8 +19,9 @@ class TestCheckBoxText: check_box = EpamJDISite.metals_colors_page.cb_water + @staticmethod @pytest.mark.parametrize("input_value, expected", [("True", True), ("1", True), ("False", False), ("0", False)]) - def test_set_value(self, checkbox_setup, input_value, expected): + def test_set_value(checkbox_setup, input_value, expected): if not expected: EpamJDISite.metals_colors_page.cb_water.click() EpamJDISite.metals_colors_page.cb_water.set_value(input) From ce3b14edf325318105a92b7759ae6a3a3d37cef3 Mon Sep 17 00:00:00 2001 From: "PETERSBURG\\Elena_Veldina" Date: Thu, 27 May 2021 13:10:02 +0300 Subject: [PATCH 04/10] one more --- tests/jdi_uitests_webtests/test/common/check_box_test.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/jdi_uitests_webtests/test/common/check_box_test.py b/tests/jdi_uitests_webtests/test/common/check_box_test.py index cc92d5c..39f84ef 100644 --- a/tests/jdi_uitests_webtests/test/common/check_box_test.py +++ b/tests/jdi_uitests_webtests/test/common/check_box_test.py @@ -20,17 +20,17 @@ class TestCheckBoxText: check_box = EpamJDISite.metals_colors_page.cb_water @staticmethod - @pytest.mark.parametrize("input_value, expected", [("True", True), ("1", True), ("False", False), ("0", False)]) - def test_set_value(checkbox_setup, input_value, expected): + @pytest.mark.parametrize("input, expected", [("True", True), ("1", True), ("False", False), ("0", False)]) + def test_set_value(checkbox_setup, input, expected): if not expected: EpamJDISite.metals_colors_page.cb_water.click() EpamJDISite.metals_colors_page.cb_water.set_value(input) CommonActionsData.check_action("Water: condition changed to " + str(expected).lower()) - @pytest.mark.parametrize("input_value", ["true ", "1 ", " false", "0 ", " ", "123", " 1", " 0", "!@#$%^&*", + @pytest.mark.parametrize("input", ["true ", "1 ", " false", "0 ", " ", "123", " 1", " 0", "!@#$%^&*", "qwdewf", "1qwe", "1qwe", "true123", "123true", "false123", "123false", "o", "O", "tr ue", ]) - def test_set_value_nothing_changes(self, checkbox_setup, input_value): + def test_set_value_nothing_changes(self, checkbox_setup, input): self.check_box.click() self.check_box.set_value(input) CommonActionsData.check_action(MSG_TRUE) From 31dc98fdc4131dca6a753f84939a5c9ee47cea40 Mon Sep 17 00:00:00 2001 From: "PETERSBURG\\Elena_Veldina" Date: Thu, 27 May 2021 13:25:03 +0300 Subject: [PATCH 05/10] one more --- .../test/common/check_box_test.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/jdi_uitests_webtests/test/common/check_box_test.py b/tests/jdi_uitests_webtests/test/common/check_box_test.py index 39f84ef..ecdb701 100644 --- a/tests/jdi_uitests_webtests/test/common/check_box_test.py +++ b/tests/jdi_uitests_webtests/test/common/check_box_test.py @@ -20,22 +20,22 @@ class TestCheckBoxText: check_box = EpamJDISite.metals_colors_page.cb_water @staticmethod - @pytest.mark.parametrize("input, expected", [("True", True), ("1", True), ("False", False), ("0", False)]) - def test_set_value(checkbox_setup, input, expected): + @pytest.mark.parametrize("input_value, expected", [("True", True), ("1", True), ("False", False), ("0", False)]) + def test_set_value(checkbox_setup, input_value, expected): if not expected: EpamJDISite.metals_colors_page.cb_water.click() - EpamJDISite.metals_colors_page.cb_water.set_value(input) + EpamJDISite.metals_colors_page.cb_water.set_value(input_value) CommonActionsData.check_action("Water: condition changed to " + str(expected).lower()) - @pytest.mark.parametrize("input", ["true ", "1 ", " false", "0 ", " ", "123", " 1", " 0", "!@#$%^&*", - "qwdewf", "1qwe", "1qwe", "true123", "123true", "false123", "123false", - "o", "O", "tr ue", ]) - def test_set_value_nothing_changes(self, checkbox_setup, input): + @pytest.mark.parametrize("input_value", ["true ", "1 ", " false", "0 ", " ", "123", " 1", " 0", "!@#$%^&*", + "qwdewf", "1qwe", "1qwe", "true123", "123true", "false123", "123false", + "o", "O", "tr ue", ]) + def test_set_value_nothing_changes(self, checkbox_setup, input_value): self.check_box.click() - self.check_box.set_value(input) + self.check_box.set_value(input_value) CommonActionsData.check_action(MSG_TRUE) self.check_box.click() - self.check_box.set_value(input) + self.check_box.set_value(input_value) CommonActionsData.check_action(MSG_FALSE) def test_check_single(self, checkbox_setup): From 2b385f31e5625d165f2c67ad5163cb559a6892d3 Mon Sep 17 00:00:00 2001 From: "PETERSBURG\\Elena_Veldina" Date: Fri, 4 Jun 2021 15:49:40 +0300 Subject: [PATCH 06/10] small fix --- .../api_interact/get_element_module.py | 58 +++++++++---------- 1 file changed, 27 insertions(+), 31 deletions(-) diff --git a/JDI/web/selenium/elements/api_interact/get_element_module.py b/JDI/web/selenium/elements/api_interact/get_element_module.py index 89f387f..1686058 100644 --- a/JDI/web/selenium/elements/api_interact/get_element_module.py +++ b/JDI/web/selenium/elements/api_interact/get_element_module.py @@ -14,7 +14,7 @@ def __init__(self, by_locator=None, element=None): self.frame_locator = None def get_element(self): - return self.web_element if self.web_element is not None else self.__get_element_action() + return self.web_element if self.web_element else self.__get_element_action() def get_elements(self): result = self.__search_elements() @@ -38,13 +38,15 @@ def __get_one_or_more_elements(self): return self.web_elements if self.web_elements else self.__search_elements() def __search_elements(self): - search_context = self.get_driver() \ - if WebDriverByUtils.contains_root(self.by_locator) \ - else self.get_search_context(self.element.parent) + if WebDriverByUtils.contains_root(self.by_locator): + search_context = self.get_driver() + else: + search_context = self.get_search_context(self.element.parent) - locator = WebDriverByUtils.trim_root(self.by_locator) \ - if WebDriverByUtils.contains_root(self.by_locator) \ - else self.by_locator + if WebDriverByUtils.contains_root(self.by_locator): + locator = WebDriverByUtils.trim_root(self.by_locator) + else: + locator = self.by_locator if search_context is None: search_context = self.get_driver() @@ -58,36 +60,30 @@ def get_search_context(self, element): driver = self.get_driver() if element is None: return driver - from JDI.web.selenium.elements.composite.web_site import WebSite try: - if isinstance(element, WebSite) or isinstance(element.get_parent(), WebSite): - return driver - except: pass + if element.get_parent() is None and element.avatar.frame_locator is None: + return self.get_driver().switch_to.default_content() + except: + return driver + try: - if issubclass(element, WebSite) or issubclass(element.get_parent(), WebSite): - return driver - except: pass - from JDI.web.selenium.elements.base.base_element import BaseElement - from JDI.web.selenium.elements.base.element import Element - if (element is None or type(element) is BaseElement) or \ - (element.get_parent() is None and element.avatar.frame_locator is None): - return self.get_driver().switch_to.default_content() - if type(element) is Element and element.avatar.has_web_element(): - return element.get_web_element + if element.avatar.has_web_element(): + return element.get_web_element + except: + return driver locator = element.get_locator() - search_context = self.get_driver().switch_to.default_content() \ - if WebDriverByUtils.contains_root(locator) \ - else self.get_search_context(element.get_parent()) - locator = WebDriverByUtils.trim_root(locator) \ - if WebDriverByUtils.contains_root(locator) \ - else locator + if WebDriverByUtils.contains_root(locator): + search_context = self.get_driver().switch_to.default_content() + locator = WebDriverByUtils.trim_root(locator) + else: + return driver frame = element.avatar.frame_locator - if frame is not None: + if frame: self.switch_to_last_opened_window() res = search_context.find_element(element.avatar.frame_locator[0], element.avatar.frame_locator[1]) driver.switch_to.frame(res) - return search_context.find_element(locator[0], locator[1]) if locator is not None else search_context + return search_context.find_element(locator[0], locator[1]) if locator else search_context def switch_to_last_opened_window(self): self.get_driver().switch_to.window(self.get_driver().window_handles[-1]) @@ -96,7 +92,7 @@ def set_web_element(self, web_element): self.web_element = web_element def has_locator(self): - return self.by_locator is not None + return self.by_locator def has_we_element(self): - return self.web_element is not None + return self.web_element From f6cfda36ddbf2e6203f304968a9272dd16fd1c30 Mon Sep 17 00:00:00 2001 From: "PETERSBURG\\Elena_Veldina" Date: Fri, 4 Jun 2021 16:12:04 +0300 Subject: [PATCH 07/10] small fix --- .../elements/api_interact/get_element_module.py | 7 ++++--- JDI/web/selenium/elements/base/base_element.py | 12 ------------ 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/JDI/web/selenium/elements/api_interact/get_element_module.py b/JDI/web/selenium/elements/api_interact/get_element_module.py index 1686058..b2ea8e6 100644 --- a/JDI/web/selenium/elements/api_interact/get_element_module.py +++ b/JDI/web/selenium/elements/api_interact/get_element_module.py @@ -63,13 +63,14 @@ def get_search_context(self, element): try: if element.get_parent() is None and element.avatar.frame_locator is None: return self.get_driver().switch_to.default_content() - except: + except AttributeError as e: + print(e) return driver - try: if element.avatar.has_web_element(): return element.get_web_element - except: + except AttributeError as e: + print(e) return driver locator = element.get_locator() if WebDriverByUtils.contains_root(locator): diff --git a/JDI/web/selenium/elements/base/base_element.py b/JDI/web/selenium/elements/base/base_element.py index 83beddc..666d068 100644 --- a/JDI/web/selenium/elements/base/base_element.py +++ b/JDI/web/selenium/elements/base/base_element.py @@ -42,17 +42,5 @@ def set_parent(self, parent): def get_locator(self): return self.avatar.by_locator - def __str__(self): - s = "Name " + self.__class__.__name__ - if "by_locator" in dir(self.avatar): - if self.avatar.by_locator is not None: - s += "; Locator: %s:'%s'" % (self.avatar.by_locator[0], self.avatar.by_locator[1]) - if self.parent is not None: - if "avatar" in dir(self.parent): - if self.parent.avatar.by_locator is not None: - s += "; Parent: %s:'%s'" % (self.parent.avatar.by_locator[0], self.parent.avatar.by_locator[1]) - - return s - def has_locator(self): return self.avatar.has_locator() From 2e6c412bd647aadd1c0d192edaf6e61e70b62cac Mon Sep 17 00:00:00 2001 From: "PETERSBURG\\Elena_Veldina" Date: Mon, 7 Jun 2021 17:50:22 +0300 Subject: [PATCH 08/10] small fix --- .../selenium/elements/api_interact/get_element_module.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/JDI/web/selenium/elements/api_interact/get_element_module.py b/JDI/web/selenium/elements/api_interact/get_element_module.py index b2ea8e6..afe774c 100644 --- a/JDI/web/selenium/elements/api_interact/get_element_module.py +++ b/JDI/web/selenium/elements/api_interact/get_element_module.py @@ -71,20 +71,19 @@ def get_search_context(self, element): return element.get_web_element except AttributeError as e: print(e) - return driver locator = element.get_locator() if WebDriverByUtils.contains_root(locator): search_context = self.get_driver().switch_to.default_content() locator = WebDriverByUtils.trim_root(locator) - else: - return driver frame = element.avatar.frame_locator if frame: self.switch_to_last_opened_window() res = search_context.find_element(element.avatar.frame_locator[0], element.avatar.frame_locator[1]) driver.switch_to.frame(res) - return search_context.find_element(locator[0], locator[1]) if locator else search_context + return search_context.find_element(locator[0], locator[1]) if locator else search_context + else: + return driver def switch_to_last_opened_window(self): self.get_driver().switch_to.window(self.get_driver().window_handles[-1]) From 2a1da925157405c33dcd12eb1aad295ab1226b4f Mon Sep 17 00:00:00 2001 From: "PETERSBURG\\Elena_Veldina" Date: Mon, 7 Jun 2021 18:02:15 +0300 Subject: [PATCH 09/10] small fix --- .../selenium/elements/api_interact/get_element_module.py | 7 +++---- tests/test_get_driver.py | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/JDI/web/selenium/elements/api_interact/get_element_module.py b/JDI/web/selenium/elements/api_interact/get_element_module.py index afe774c..bfd4ced 100644 --- a/JDI/web/selenium/elements/api_interact/get_element_module.py +++ b/JDI/web/selenium/elements/api_interact/get_element_module.py @@ -75,15 +75,14 @@ def get_search_context(self, element): if WebDriverByUtils.contains_root(locator): search_context = self.get_driver().switch_to.default_content() locator = WebDriverByUtils.trim_root(locator) - + else: + search_context = self.get_search_context(element.get_parent()) frame = element.avatar.frame_locator if frame: self.switch_to_last_opened_window() res = search_context.find_element(element.avatar.frame_locator[0], element.avatar.frame_locator[1]) driver.switch_to.frame(res) - return search_context.find_element(locator[0], locator[1]) if locator else search_context - else: - return driver + return search_context.find_element(locator[0], locator[1]) if locator else search_context def switch_to_last_opened_window(self): self.get_driver().switch_to.window(self.get_driver().window_handles[-1]) diff --git a/tests/test_get_driver.py b/tests/test_get_driver.py index b9bd1e2..d10b3bc 100644 --- a/tests/test_get_driver.py +++ b/tests/test_get_driver.py @@ -13,7 +13,7 @@ def test_download_chromedriver(self): assert os.path.exists("chromedriver.exe") is True def test_get_last_release(self): - assert get_driver.get_last_release() == "90.0.4430.24" + assert get_driver.get_last_release() == "91.0.4472.19" def test_get_last_release_for_build(self): assert get_driver.get_last_release(build="90") == "90.0.4430.24" From a5bd91ed23e97d5dc6638306129127df2a5ac1f7 Mon Sep 17 00:00:00 2001 From: "PETERSBURG\\Elena_Veldina" Date: Mon, 7 Jun 2021 18:45:05 +0300 Subject: [PATCH 10/10] Revert "issue 51" This reverts commit 358c8f2f --- requirements-dev.txt | 1 + requirements.txt | 1 + .../test/common/check_box_test.py | 72 +++++++++++++------ .../test/complex/check_list_test.py | 67 +++++++++-------- 4 files changed, 88 insertions(+), 53 deletions(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 17f0c39..70dba52 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -6,6 +6,7 @@ chardet==4.0.0 click==7.1.2 colorama==0.4.4 comtypes==1.1.8 +ddt==1.4.1 flake8==3.8.4 idna==2.10 isort==5.7.0 diff --git a/requirements.txt b/requirements.txt index b3d39ed..838a0e6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +ddt==1.4.1 pywin32==300 selenium==3.141.0 urllib3==1.26.4 diff --git a/tests/jdi_uitests_webtests/test/common/check_box_test.py b/tests/jdi_uitests_webtests/test/common/check_box_test.py index ecdb701..778639b 100644 --- a/tests/jdi_uitests_webtests/test/common/check_box_test.py +++ b/tests/jdi_uitests_webtests/test/common/check_box_test.py @@ -1,70 +1,96 @@ +import unittest + import pytest +from ddt import data, ddt, unpack +from JDI.core.settings.jdi_settings import JDISettings from JDI.jdi_assert.testing.assertion import Assert from tests.jdi_uitests_webtests.main.enums.preconditions import Preconditions from tests.jdi_uitests_webtests.main.page_objects.epam_jdi_site import EpamJDISite from tests.jdi_uitests_webtests.main.utils.common_action_data import CommonActionsData +from tests.jdi_uitests_webtests.test.init_tests import InitTests MSG_TRUE = "Water: condition changed to true" MSG_FALSE = "Water: condition changed to false" -@pytest.fixture -def checkbox_setup(site): - Preconditions.METALS_AND_COLORS_PAGE.is_in_state() - - @pytest.mark.web -class TestCheckBoxText: +@ddt +class CheckBoxText(InitTests): check_box = EpamJDISite.metals_colors_page.cb_water - @staticmethod - @pytest.mark.parametrize("input_value, expected", [("True", True), ("1", True), ("False", False), ("0", False)]) - def test_set_value(checkbox_setup, input_value, expected): + def setUp(self): + super(CheckBoxText, self).setUp(self.id().split(".")[-1]) + Preconditions.METALS_AND_COLORS_PAGE.is_in_state() + + def tearDown(self): + JDISettings.get_driver_factory().get_driver().refresh() + + @data(("True", True), ("1", True), ("False", False), ("0", False)) + @unpack + def test_set_value(self, input, expected): if not expected: EpamJDISite.metals_colors_page.cb_water.click() - EpamJDISite.metals_colors_page.cb_water.set_value(input_value) + EpamJDISite.metals_colors_page.cb_water.set_value(input) CommonActionsData.check_action("Water: condition changed to " + str(expected).lower()) - @pytest.mark.parametrize("input_value", ["true ", "1 ", " false", "0 ", " ", "123", " 1", " 0", "!@#$%^&*", - "qwdewf", "1qwe", "1qwe", "true123", "123true", "false123", "123false", - "o", "O", "tr ue", ]) - def test_set_value_nothing_changes(self, checkbox_setup, input_value): + @data( + "true ", + "1 ", + " false", + "0 ", + " ", + "123", + " 1", + " 0", + "!@#$%^&*", + "qwdewf", + "1qwe", + "1qwe", + "true123", + "123true", + "false123", + "123false", + "o", + "O", + "tr ue", + ) + def test_set_value_nothing_changes(self, input): self.check_box.click() - self.check_box.set_value(input_value) + self.check_box.set_value(input) CommonActionsData.check_action(MSG_TRUE) self.check_box.click() - self.check_box.set_value(input_value) + self.check_box.set_value(input) CommonActionsData.check_action(MSG_FALSE) - def test_check_single(self, checkbox_setup): + def test_check_single(self): self.check_box.check() CommonActionsData.check_action(MSG_TRUE) - def test_uncheck_single(self, checkbox_setup): + def test_uncheck_single(self): self.check_box.click() self.check_box.uncheck() CommonActionsData.check_action(MSG_FALSE) - def test_is_check(self, checkbox_setup): + def test_is_check(self): Assert.assert_false(self.check_box.is_checked()) self.check_box.click() Assert.assert_true(self.check_box.is_checked()) - def test_multi_uncheck(self, checkbox_setup): + def test_multi_uncheck(self): self.check_box.click() self.check_box.uncheck() self.check_box.uncheck() CommonActionsData.check_action(MSG_FALSE) - def test_multi_check(self, checkbox_setup): + def test_multi_check(self): self.check_box.check() self.check_box.check() CommonActionsData.check_action(MSG_TRUE) - def test_click(self, checkbox_setup): + def test_click(self): self.check_box.click() CommonActionsData.check_action(MSG_TRUE) self.check_box.click() - CommonActionsData.check_action(MSG_FALSE) \ No newline at end of file + CommonActionsData.check_action(MSG_FALSE) diff --git a/tests/jdi_uitests_webtests/test/complex/check_list_test.py b/tests/jdi_uitests_webtests/test/complex/check_list_test.py index b1a97e6..432f177 100644 --- a/tests/jdi_uitests_webtests/test/complex/check_list_test.py +++ b/tests/jdi_uitests_webtests/test/complex/check_list_test.py @@ -1,5 +1,7 @@ -import pytest +import unittest +import pytest +from ddt import data, ddt from selenium.webdriver.common.by import By from JDI.core.settings.jdi_settings import JDISettings @@ -8,64 +10,65 @@ from tests.jdi_uitests_webtests.main.enums.preconditions import Preconditions from tests.jdi_uitests_webtests.main.page_objects.epam_jdi_site import EpamJDISite from tests.jdi_uitests_webtests.main.utils.common_action_data import CommonActionsData +from tests.jdi_uitests_webtests.test.init_tests import InitTests FIRE_MSG = "Fire: condition changed to true" WATER_MSG = "Water: condition changed to true" -@pytest.fixture -def check_list_setup(site): - Preconditions.METALS_AND_COLORS_PAGE.is_in_state() - - @pytest.mark.web -class TestCheckList: +@ddt +class CheckListTests(InitTests): nature_options = ["Water", "Earth", "Wind", "Fire"] all_values = "Water, Earth, Wind, Fire" check_list = EpamJDISite.metals_colors_page.nature_check_list - @pytest.mark.parametrize("value", ("Fire", 4, Nature.FIRE)) - def test_select(self, check_list_setup, value): + def setUp(self): + super(CheckListTests, self).setUp(self.id().split(".")[-1]) + Preconditions.METALS_AND_COLORS_PAGE.is_in_state() + + @data("Fire", 4, Nature.FIRE) + def test_select(self, value): self.check_list.select(value) CommonActionsData.check_action(FIRE_MSG) - def test_select_2_string(self, check_list_setup): + def test_select_2_string(self): self.check_list.select("Water", "Fire") CommonActionsData.check_action(FIRE_MSG, line_number=0) CommonActionsData.check_action(WATER_MSG, line_number=1) - def test_select_2_index(self, check_list_setup): + def test_select_2_index(self): self.check_list.select(1, 4) CommonActionsData.check_action(FIRE_MSG, line_number=0) CommonActionsData.check_action(WATER_MSG, line_number=1) - def test_select_2_enum(self, check_list_setup): + def test_select_2_enum(self): self.check_list.select(Nature.WATER, Nature.FIRE) CommonActionsData.check_action(FIRE_MSG, line_number=0) CommonActionsData.check_action(WATER_MSG, line_number=1) - @pytest.mark.parametrize("value", ("Fire", 4, Nature.FIRE)) - def test_check(self, check_list_setup, value): + @data("Fire", 4, Nature.FIRE) + def test_check(self, value): self.check_list.check(value) CommonActionsData.check_action(FIRE_MSG) - def test_check_2_string(self, check_list_setup): + def test_check_2_string(self): self.check_list.check("Water", "Fire") CommonActionsData.check_action(FIRE_MSG, line_number=0) CommonActionsData.check_action(WATER_MSG, line_number=1) - def test_check_2_index(self, check_list_setup): + def test_check_2_index(self): self.check_list.check(1, 4) CommonActionsData.check_action(FIRE_MSG, line_number=0) CommonActionsData.check_action(WATER_MSG, line_number=1) - def test_check_2_enum(self, check_list_setup): + def test_check_2_enum(self): self.check_list.check(Nature.WATER, Nature.FIRE) CommonActionsData.check_action(FIRE_MSG, line_number=0) CommonActionsData.check_action(WATER_MSG, line_number=1) - def test_select_all(self, check_list_setup): + def test_select_all(self): self.check_list.select_all() CommonActionsData.check_action(FIRE_MSG, line_number=0) CommonActionsData.check_action("Wind: condition changed to true", line_number=1) @@ -73,7 +76,7 @@ def test_select_all(self, check_list_setup): CommonActionsData.check_action(WATER_MSG, line_number=3) self.check_all_checked() - def test_check_all(self, check_list_setup): + def test_check_all(self): self.check_list.check_all() CommonActionsData.check_action(FIRE_MSG, line_number=0) CommonActionsData.check_action("Wind: condition changed to true", line_number=1) @@ -81,44 +84,44 @@ def test_check_all(self, check_list_setup): CommonActionsData.check_action(WATER_MSG, line_number=3) self.check_all_checked() - def test_clear_all(self, check_list_setup): + def test_clear_all(self): self.check_list.check_all() self.check_all_checked() self.check_list.clear() self.check_all_unchecked() - def test_uncheck_all(self, check_list_setup): + def test_uncheck_all(self): self.check_list.check_all() self.check_all_checked() self.check_list.uncheck_all() self.check_all_unchecked() - def test_get_options(self, check_list_setup): + def test_get_options(self): Assert.assert_equal(self.check_list.get_options(), self.nature_options) - def test_get_names(self, check_list_setup): + def test_get_names(self): Assert.assert_equal(self.check_list.get_names(), self.nature_options) - def test_get_values(self, check_list_setup): + def test_get_values(self): Assert.assert_equal(self.check_list.get_values(), self.nature_options) - def test_get_options_as_text(self, check_list_setup): + def test_get_options_as_text(self): Assert.assert_equal(self.check_list.get_options_as_text(), self.all_values) - def test_set_value(self, check_list_setup): + def test_set_value(self): self.check_list.set_value("Fire") CommonActionsData.check_action(FIRE_MSG) - def test_get_name(self, check_list_setup): + def test_get_name(self): Assert.assert_equal(self.check_list.get_name(), "nature_check_list") - def test_are_selected(self, check_list_setup): + def test_are_selected(self): Assert.assert_equal(self.check_list.are_selected(), []) - def test_are_deselected(self, check_list_setup): + def test_are_deselected(self): Assert.assert_equal(self.check_list.are_deselected(), self.nature_options) - def test_get_value(self, check_list_setup): + def test_get_value(self): Assert.assert_equal(self.check_list.get_value(), None) def check_all_checked(self): @@ -132,3 +135,7 @@ def check_all_unchecked(self): els = driver.find_elements(By.CSS_SELECTOR, value="#elements-checklist input") for el in els: Assert.assert_true(el.get_attribute("checked") in ["false", None]) + + +if __name__ == "__main__": + unittest.main()