Skip to content

Commit

Permalink
Align python select tests with Java ones for more coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
AutomatedTester committed Sep 15, 2016
1 parent 54042ac commit e812c9f
Showing 1 changed file with 60 additions and 8 deletions.
68 changes: 60 additions & 8 deletions py/test/selenium/webdriver/common/select_element_handling_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# distributed with this work for additional information
# regarding copyright ownership. The SFC licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# "License") you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
Expand All @@ -21,10 +21,26 @@

class SelectElementHandlingTests(unittest.TestCase):

def testShouldBeAbleToChangeTheSelectedOptionInASelect(self):
def testShouldBePossibleToDeselectASingleOptionFromASelectWhichAllowsMultipleChoice(self):
self._loadPage("formPage")
selectBox = self.driver.find_element(by=By.XPATH, value="//select[@name='selectomatic']")
options = selectBox.find_elements(by=By.TAG_NAME, value="option")

multiSelect = self.driver.find_element(By.ID, "multi")
options = multiSelect.find_elements(By.TAG_NAME, "option")

option = options[0]
self.assertTrue(option.is_selected())
option.click()
self.assertFalse(option.is_selected())
option.click()
self.assertTrue(option.is_selected())

option = options[2]
self.assertTrue(option.is_selected())

def testShouldBeAbleToChangeTheSelectedOptionInASelec(self):
self._loadPage("formPage")
selectBox = self.driver.find_element(By.XPATH, "//select[@name='selectomatic']")
options = selectBox.find_elements(By.TAG_NAME, "option")
one = options[0]
two = options[1]
self.assertTrue(one.is_selected())
Expand All @@ -34,18 +50,49 @@ def testShouldBeAbleToChangeTheSelectedOptionInASelect(self):
self.assertFalse(one.is_selected())
self.assertTrue(two.is_selected())

def testShouldBeAbleToSelectMoreThanOneOptionFromASelectWhichAllowsMultipleChoices(self):
def testShouldBeAbleToSelectMoreThanOneOptionFromASelectWhichAllowsMultipleChoice(self):
self._loadPage("formPage")

multiSelect = self.driver.find_element(by=By.ID, value="multi")
options = multiSelect.find_elements(by=By.TAG_NAME, value="option")
multiSelect = self.driver.find_element(By.ID, "multi")
options = multiSelect.find_elements(By.TAG_NAME, "option")
for option in options:
if not option.is_selected():
option.click()

for i in range(len(options)):
option = options[i]
self.assertTrue(option.is_selected(), "Option at index is not selected but should be: " + str(i))
self.assertTrue(option.is_selected(), "Option at index is not selected but should be: {0}".format(i))

def testShouldSelectFirstOptionaultIfNoneIsSelecte(self):
self._loadPage("formPage")
selectBox = self.driver.find_element(By.XPATH, "//select[@name='select-default']")
options = selectBox.find_elements(By.TAG_NAME, "option")
one = options[0]
two = options[1]
self.assertTrue(one.is_selected())
self.assertFalse(two.is_selected())

two.click()
self.assertFalse(one.is_selected())
self.assertTrue(two.is_selected())

def testCanSelectElementsInOptGroup(self):
self._loadPage("selectPage")
element = self.driver.find_element(By.ID, "two-in-group")
element.click()
self.assertTrue(element.is_selected(), "Expected to be selected")

def testCanGetValueFromOptionViaAttributeWhenAttributeDoesntExis(self):
self._loadPage("formPage")
element = self.driver.find_element(By.CSS_SELECTOR, "select[name='select-default'] option")
self.assertEqual(element.get_attribute("value"), "One")
element = self.driver.find_element(By.ID, "blankOption")
self.assertEqual(element.get_attribute("value"), "")

def testCanGetValueFromOptionViaAttributeWhenAttributeIsEmptyString(self):
self._loadPage("formPage")
element = self.driver.find_element(By.ID, "optionEmptyValueSet")
self.assertEqual(element.get_attribute("value"), "")

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

def _loadPage(self, name):
try:
# just in case a previous test left open an alert
self.driver.switch_to.alert().dismiss()
except Exception:
pass
self.driver.get(self._pageURL(name))

0 comments on commit e812c9f

Please sign in to comment.