Skip to content

Commit e812c9f

Browse files
Align python select tests with Java ones for more coverage
1 parent 54042ac commit e812c9f

File tree

1 file changed

+60
-8
lines changed

1 file changed

+60
-8
lines changed

py/test/selenium/webdriver/common/select_element_handling_tests.py

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# distributed with this work for additional information
44
# regarding copyright ownership. The SFC licenses this file
55
# to you under the Apache License, Version 2.0 (the
6-
# "License"); you may not use this file except in compliance
6+
# "License") you may not use this file except in compliance
77
# with the License. You may obtain a copy of the License at
88
#
99
# http://www.apache.org/licenses/LICENSE-2.0
@@ -21,10 +21,26 @@
2121

2222
class SelectElementHandlingTests(unittest.TestCase):
2323

24-
def testShouldBeAbleToChangeTheSelectedOptionInASelect(self):
24+
def testShouldBePossibleToDeselectASingleOptionFromASelectWhichAllowsMultipleChoice(self):
2525
self._loadPage("formPage")
26-
selectBox = self.driver.find_element(by=By.XPATH, value="//select[@name='selectomatic']")
27-
options = selectBox.find_elements(by=By.TAG_NAME, value="option")
26+
27+
multiSelect = self.driver.find_element(By.ID, "multi")
28+
options = multiSelect.find_elements(By.TAG_NAME, "option")
29+
30+
option = options[0]
31+
self.assertTrue(option.is_selected())
32+
option.click()
33+
self.assertFalse(option.is_selected())
34+
option.click()
35+
self.assertTrue(option.is_selected())
36+
37+
option = options[2]
38+
self.assertTrue(option.is_selected())
39+
40+
def testShouldBeAbleToChangeTheSelectedOptionInASelec(self):
41+
self._loadPage("formPage")
42+
selectBox = self.driver.find_element(By.XPATH, "//select[@name='selectomatic']")
43+
options = selectBox.find_elements(By.TAG_NAME, "option")
2844
one = options[0]
2945
two = options[1]
3046
self.assertTrue(one.is_selected())
@@ -34,18 +50,49 @@ def testShouldBeAbleToChangeTheSelectedOptionInASelect(self):
3450
self.assertFalse(one.is_selected())
3551
self.assertTrue(two.is_selected())
3652

37-
def testShouldBeAbleToSelectMoreThanOneOptionFromASelectWhichAllowsMultipleChoices(self):
53+
def testShouldBeAbleToSelectMoreThanOneOptionFromASelectWhichAllowsMultipleChoice(self):
3854
self._loadPage("formPage")
3955

40-
multiSelect = self.driver.find_element(by=By.ID, value="multi")
41-
options = multiSelect.find_elements(by=By.TAG_NAME, value="option")
56+
multiSelect = self.driver.find_element(By.ID, "multi")
57+
options = multiSelect.find_elements(By.TAG_NAME, "option")
4258
for option in options:
4359
if not option.is_selected():
4460
option.click()
4561

4662
for i in range(len(options)):
4763
option = options[i]
48-
self.assertTrue(option.is_selected(), "Option at index is not selected but should be: " + str(i))
64+
self.assertTrue(option.is_selected(), "Option at index is not selected but should be: {0}".format(i))
65+
66+
def testShouldSelectFirstOptionaultIfNoneIsSelecte(self):
67+
self._loadPage("formPage")
68+
selectBox = self.driver.find_element(By.XPATH, "//select[@name='select-default']")
69+
options = selectBox.find_elements(By.TAG_NAME, "option")
70+
one = options[0]
71+
two = options[1]
72+
self.assertTrue(one.is_selected())
73+
self.assertFalse(two.is_selected())
74+
75+
two.click()
76+
self.assertFalse(one.is_selected())
77+
self.assertTrue(two.is_selected())
78+
79+
def testCanSelectElementsInOptGroup(self):
80+
self._loadPage("selectPage")
81+
element = self.driver.find_element(By.ID, "two-in-group")
82+
element.click()
83+
self.assertTrue(element.is_selected(), "Expected to be selected")
84+
85+
def testCanGetValueFromOptionViaAttributeWhenAttributeDoesntExis(self):
86+
self._loadPage("formPage")
87+
element = self.driver.find_element(By.CSS_SELECTOR, "select[name='select-default'] option")
88+
self.assertEqual(element.get_attribute("value"), "One")
89+
element = self.driver.find_element(By.ID, "blankOption")
90+
self.assertEqual(element.get_attribute("value"), "")
91+
92+
def testCanGetValueFromOptionViaAttributeWhenAttributeIsEmptyString(self):
93+
self._loadPage("formPage")
94+
element = self.driver.find_element(By.ID, "optionEmptyValueSet")
95+
self.assertEqual(element.get_attribute("value"), "")
4996

5097
def _pageURL(self, name):
5198
return self.webserver.where_is(name + '.html')
@@ -54,4 +101,9 @@ def _loadSimplePage(self):
54101
self._loadPage("simpleTest")
55102

56103
def _loadPage(self, name):
104+
try:
105+
# just in case a previous test left open an alert
106+
self.driver.switch_to.alert().dismiss()
107+
except Exception:
108+
pass
57109
self.driver.get(self._pageURL(name))

0 commit comments

Comments
 (0)