Skip to content

Commit ace209c

Browse files
committed
remove some duplicates
1 parent cf61eeb commit ace209c

File tree

9 files changed

+88
-107
lines changed

9 files changed

+88
-107
lines changed

.github/workflows/jdi-python.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ jobs:
3131
- name: Download Chrome driver
3232
run: |
3333
python get_driver.py
34-
- name: Run tests
35-
run: |
36-
python -m unittest Test\jdi_uitests_webtests\test\run_all_tests.py -v
34+
# TODO: use virtual machine for tests run
35+
# - name: Run tests
36+
# run: |
37+
# python -m unittest Test\jdi_uitests_webtests\test\run_all_tests.py -v
3738
shell: cmd
3839
- name: Save debug log file
3940
uses: actions/upload-artifact@v2

JDI/web/selenium/settings/WebSettings.py

Lines changed: 0 additions & 38 deletions
This file was deleted.

JDI/web/selenium/settings/web_settings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def set_driver_factory(driver_factory):
1919

2020
@staticmethod
2121
def use_driver(options=None, capabilities=None, executor=None):
22-
driver_name = JDISettings.get_setting_by_name('driver')
22+
driver_name = JDISettings.get_setting_by_name("driver")
2323
JDISettings._driver_factory = SeleniumDriverFactory()
2424
WebSettings.set_driver_factory(JDISettings._driver_factory)
2525
return JDISettings._driver_factory.register_driver(driver_name, options, capabilities, executor)
@@ -35,4 +35,4 @@ def quit_browser():
3535

3636
@staticmethod
3737
def get_driver():
38-
return WebSettings.get_driver_factory().get_driver()
38+
return WebSettings.get_driver_factory().get_driver()

Test/jdi_uitests_webtests/main/page_objects/sections/summary.py

Lines changed: 30 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,53 @@
11
from enum import Enum
2-
2+
from abc import ABCMeta, abstractmethod
33
from JDI.web.selenium.elements.api_interact.find_element_by import By
44
from JDI.web.selenium.elements.complex.radio_buttons import RadioButtons
55
from JDI.web.selenium.elements.complex.selector import Selector
66
from JDI.web.selenium.elements.composite.section import Section
77

8+
ERROR_MSG = "No elements selected. Override getSelectedAction or place locator to <select> tag"
89

9-
class RadioButtonsSummary(RadioButtons):
10-
def get_selected(self):
11-
el = list(filter(lambda x: x.is_selected(), self.get_input_web_elements()))
12-
if len(el) == 0:
13-
raise Exception("No elements selected. Override getSelectedAction or place locator to <select> tag")
14-
return el[0].find_element_by_xpath("..").text
1510

11+
class SelectElements(metaclass=ABCMeta):
12+
@abstractmethod
1613
def get_input_web_elements(self):
17-
return list(map(lambda el: el.find_element_by_tag_name("input"),
18-
super(RadioButtonsSummary, self).get_web_elements()))
14+
raise NotImplementedError
1915

20-
def is_selected_action(self, el):
21-
actual_text = list(filter(lambda x: x.is_selected(), self.get_input_web_elements()))[0].find_element_by_xpath(
22-
"..").text
23-
if isinstance(el, str):
24-
return actual_text == el
25-
if isinstance(el, Enum):
26-
return actual_text == el.value
16+
def get_selected(self):
17+
element = list(filter(lambda x: x.is_selected(), self.get_input_web_elements()))
18+
if len(element) == 0:
19+
raise ValueError(ERROR_MSG)
20+
return element[0].find_element_by_xpath("..").text
21+
22+
def is_selected_action(self, element) -> bool:
23+
actual_text = (
24+
list(filter(lambda x: x.is_selected(), self.get_input_web_elements()))[0].find_element_by_xpath("..").text
25+
)
26+
if isinstance(element, str):
27+
return actual_text == element
28+
elif isinstance(element, Enum):
29+
return actual_text == element.value
30+
return False
2731

2832
def get_selected_index(self):
2933
try:
3034
return list(map(lambda x: x.is_selected(), self.get_input_web_elements())).index(True)
3135
except ValueError:
32-
raise ValueError("No elements selected. Override getSelectedAction or place locator to <select> tag")
36+
raise ValueError(ERROR_MSG) from None
3337

3438

35-
class SelectorSummary(Selector):
36-
def get_selected(self):
37-
el = list(filter(lambda x: x.is_selected(), self.get_input_web_elements()))
38-
if len(el) == 0:
39-
raise Exception("No elements selected. Override getSelectedAction or place locator to <select> tag")
40-
return el[0].find_element_by_xpath("..").text
41-
39+
class RadioButtonsSummary(SelectElements, RadioButtons):
4240
def get_input_web_elements(self):
43-
return list(map(lambda el: el.find_element_by_tag_name("input"),
44-
super(SelectorSummary, self).get_web_elements()))
41+
return list(
42+
map(lambda el: el.find_element_by_tag_name("input"), super(RadioButtonsSummary, self).get_web_elements())
43+
)
4544

46-
def is_selected_action(self, el):
47-
actual_text = list(filter(lambda x: x.is_selected(), self.get_input_web_elements()))[0].find_element_by_xpath(
48-
"..").text
49-
if isinstance(el, str):
50-
return actual_text == el
51-
if isinstance(el, Enum):
52-
return actual_text == el.value
5345

54-
def get_selected_index(self):
55-
try:
56-
return list(map(lambda x: x.is_selected(), self.get_input_web_elements())).index(True)
57-
except ValueError:
58-
raise ValueError("No elements selected. Override getSelectedAction or place locator to <select> tag")
46+
class SelectorSummary(SelectElements, Selector):
47+
def get_input_web_elements(self):
48+
return list(
49+
map(lambda el: el.find_element_by_tag_name("input"), super(SelectorSummary, self).get_web_elements())
50+
)
5951

6052

6153
class Summary(Section):

Test/jdi_uitests_webtests/test/complex/dropdown_expanded_tests.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,31 @@
55
from Test.jdi_uitests_webtests.main.utils.common_action_data import CommonActionsData
66
from Test.jdi_uitests_webtests.test.init_tests import InitTests
77

8+
MSG = "Colors: value changed to Blue"
9+
810

911
class DropdownExpandedTests(InitTests):
1012

1113
odd_options = ["Colors", "Red", "Green", "Blue", "Yellow"]
1214

1315
dropdown = EpamJDISite.metals_colors_page.color_dropdown
1416

15-
def setUp(self):
17+
def setUp(self, name="DropdownExpandedTests"):
1618
super(DropdownExpandedTests, self).setUp(self.id().split(".")[-1])
1719
Preconditions.METALS_AND_COLORS_PAGE.is_in_state()
1820
self.dropdown.expand()
1921

2022
def test_select_string(self):
2123
self.dropdown.select("Blue")
22-
CommonActionsData.check_action("Colors: value changed to Blue")
24+
CommonActionsData.check_action(MSG)
2325

2426
def test_select_index(self):
2527
self.dropdown.select(4)
26-
CommonActionsData.check_action("Colors: value changed to Blue")
28+
CommonActionsData.check_action(MSG)
2729

2830
def test_select_enum(self):
2931
self.dropdown.select(Colors.BLUE)
30-
CommonActionsData.check_action("Colors: value changed to Blue")
32+
CommonActionsData.check_action(MSG)
3133

3234
def test_get_options(self):
3335
Assert.assert_equal(self.dropdown.get_options(), self.odd_options)
@@ -43,7 +45,7 @@ def test_get_options_as_text(self):
4345

4446
def test_set_value(self):
4547
self.dropdown.set_value("Blue")
46-
CommonActionsData.check_action("Colors: value changed to Blue")
48+
CommonActionsData.check_action(MSG)
4749

4850
def test_get_name(self):
4951
Assert.assert_equal(self.dropdown.get_name(), "color_dropdown")
@@ -52,7 +54,9 @@ def test_get_selected(self):
5254
Assert.assert_equal(self.dropdown.get_selected(), "Colors")
5355

5456
def test_get_selected_index(self):
55-
CommonActionsData.check_action_throw_error(lambda: self.dropdown.get_selected_index(), CommonActionsData.no_elements_message())
57+
CommonActionsData.check_action_throw_error(
58+
lambda: self.dropdown.get_selected_index(), CommonActionsData.no_elements_message()
59+
)
5660

5761
def test_is_selected(self):
5862
Assert.assert_equal(self.dropdown.is_selected("Colors"), True)
@@ -61,4 +65,4 @@ def test_is_selected_enum(self):
6165
Assert.assert_equal(self.dropdown.is_selected(Colors.COLORS), True)
6266

6367
def test_get_value(self):
64-
Assert.assert_equal(self.dropdown.get_value(), "Colors")
68+
Assert.assert_equal(self.dropdown.get_value(), "Colors")

Test/jdi_uitests_webtests/test/complex/dropdown_tests.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,30 @@
55
from Test.jdi_uitests_webtests.main.utils.common_action_data import CommonActionsData
66
from Test.jdi_uitests_webtests.test.init_tests import InitTests
77

8+
MSG = "Colors: value changed to Blue"
9+
810

911
class DropdownTests(InitTests):
1012

1113
odd_options = ["Colors", "Red", "Green", "Blue", "Yellow"]
1214

1315
dropdown = EpamJDISite.metals_colors_page.color_dropdown
1416

15-
def setUp(self):
17+
def setUp(self, name="DropdownTests"):
1618
super(DropdownTests, self).setUp(self.id().split(".")[-1])
1719
Preconditions.METALS_AND_COLORS_PAGE.is_in_state()
1820

1921
def test_select_string(self):
2022
self.dropdown.select("Blue")
21-
CommonActionsData.check_action("Colors: value changed to Blue")
23+
CommonActionsData.check_action(MSG)
2224

2325
def test_select_index(self):
2426
self.dropdown.select(4)
25-
CommonActionsData.check_action("Colors: value changed to Blue")
27+
CommonActionsData.check_action(MSG)
2628

2729
def test_select_enum(self):
2830
self.dropdown.select(Colors.BLUE)
29-
CommonActionsData.check_action("Colors: value changed to Blue")
31+
CommonActionsData.check_action(MSG)
3032

3133
def test_get_options(self):
3234
Assert.assert_equal(self.dropdown.get_options(), self.odd_options)
@@ -42,7 +44,7 @@ def test_get_options_as_text(self):
4244

4345
def test_set_value(self):
4446
self.dropdown.set_value("Blue")
45-
CommonActionsData.check_action("Colors: value changed to Blue")
47+
CommonActionsData.check_action(MSG)
4648

4749
def test_get_name(self):
4850
Assert.assert_equal(self.dropdown.get_name(), "color_dropdown")
@@ -51,13 +53,15 @@ def test_get_selected(self):
5153
Assert.assert_equal(self.dropdown.get_selected(), "Colors")
5254

5355
def test_get_selected_index(self):
54-
CommonActionsData.check_action_throw_error(lambda: self.dropdown.get_selected_index(), CommonActionsData.no_elements_message())
55-
56+
CommonActionsData.check_action_throw_error(
57+
lambda: self.dropdown.get_selected_index(), CommonActionsData.no_elements_message()
58+
)
59+
5660
def test_is_selected(self):
5761
Assert.assert_equal(self.dropdown.is_selected("Colors"), True)
5862

5963
def test_is_selected_enum(self):
6064
Assert.assert_equal(self.dropdown.is_selected(Colors.COLORS), True)
6165

6266
def test_get_value(self):
63-
Assert.assert_equal(self.dropdown.get_value(), "Colors")
67+
Assert.assert_equal(self.dropdown.get_value(), "Colors")

Test/jdi_uitests_webtests/test/complex/radio_button_tests.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from Test.jdi_uitests_webtests.main.utils.common_action_data import CommonActionsData
66
from Test.jdi_uitests_webtests.test.init_tests import InitTests
77

8+
MSG = "Summary (Odd): value changed to 7"
9+
810

911
class RadioButtonTests(InitTests):
1012
odd_options = ["1", "3", "5", "7"]
@@ -17,15 +19,15 @@ def setUp(self):
1719

1820
def test_select_string(self):
1921
self.radio_buttons.select("7")
20-
CommonActionsData.check_action("Summary (Odd): value changed to 7")
22+
CommonActionsData.check_action(MSG)
2123

2224
def test_select_index(self):
2325
self.radio_buttons.select(4)
24-
CommonActionsData.check_action("Summary (Odd): value changed to 7")
26+
CommonActionsData.check_action(MSG)
2527

2628
def test_select_enum(self):
2729
self.radio_buttons.select(Odds.SEVEN)
28-
CommonActionsData.check_action("Summary (Odd): value changed to 7")
30+
CommonActionsData.check_action(MSG)
2931

3032
def test_get_options(self):
3133
Assert.assert_equal(self.radio_buttons.get_options(), self.odd_options)
@@ -41,10 +43,10 @@ def test_get_options_as_text(self):
4143

4244
def test_set_value_text(self):
4345
self.radio_buttons.set_value("7")
44-
CommonActionsData.check_action("Summary (Odd): value changed to 7")
46+
CommonActionsData.check_action(MSG)
4547

4648
def test_get_name(self):
47-
Assert.assert_equal(self.radio_buttons.get_name(),"odds_radio_buttons")
49+
Assert.assert_equal(self.radio_buttons.get_name(), "odds_radio_buttons")
4850

4951
def test_get_selected(self):
5052
Assert.assert_equal(self.radio_buttons.get_selected(), "1")

Test/jdi_uitests_webtests/test/complex/selector_tests.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from Test.jdi_uitests_webtests.main.utils.common_action_data import CommonActionsData
66
from Test.jdi_uitests_webtests.test.init_tests import InitTests
77

8+
MSG = "Summary (Odd): value changed to 7"
9+
810

911
class SelectorTests(InitTests):
1012
odd_options = ["1", "3", "5", "7"]
@@ -17,15 +19,15 @@ def setUp(self):
1719

1820
def test_select_string(self):
1921
self.radio_buttons.select("7")
20-
CommonActionsData.check_action("Summary (Odd): value changed to 7")
22+
CommonActionsData.check_action(MSG)
2123

2224
def test_select_index(self):
2325
self.radio_buttons.select(4)
24-
CommonActionsData.check_action("Summary (Odd): value changed to 7")
26+
CommonActionsData.check_action(MSG)
2527

2628
def test_select_enum(self):
2729
self.radio_buttons.select(Odds.SEVEN)
28-
CommonActionsData.check_action("Summary (Odd): value changed to 7")
30+
CommonActionsData.check_action(MSG)
2931

3032
def test_get_options(self):
3133
Assert.assert_equal(self.radio_buttons.get_options(), self.odd_options)
@@ -41,10 +43,10 @@ def test_get_options_as_text(self):
4143

4244
def test_set_value_text(self):
4345
self.radio_buttons.set_value("7")
44-
CommonActionsData.check_action("Summary (Odd): value changed to 7")
46+
CommonActionsData.check_action(MSG)
4547

4648
def test_get_name(self):
47-
Assert.assert_equal(self.radio_buttons.get_name(),"odds_selector")
49+
Assert.assert_equal(self.radio_buttons.get_name(), "odds_selector")
4850

4951
def test_get_selected(self):
5052
Assert.assert_equal(self.radio_buttons.get_selected(), "1")
@@ -61,4 +63,4 @@ def test_is_selected_enum(self):
6163
Assert.assert_equal(self.radio_buttons.is_selected(Odds.ONE), True)
6264

6365
def test_get_value(self):
64-
Assert.assert_equal(self.radio_buttons.get_value(), "1")
66+
Assert.assert_equal(self.radio_buttons.get_value(), "1")

0 commit comments

Comments
 (0)