From e812c9f5daaf271b648a7e7a0c78fd07ad92e8ac Mon Sep 17 00:00:00 2001 From: AutomatedTester Date: Thu, 15 Sep 2016 23:08:27 +0100 Subject: [PATCH] Align python select tests with Java ones for more coverage --- .../common/select_element_handling_tests.py | 68 ++++++++++++++++--- 1 file changed, 60 insertions(+), 8 deletions(-) diff --git a/py/test/selenium/webdriver/common/select_element_handling_tests.py b/py/test/selenium/webdriver/common/select_element_handling_tests.py index fa39533a2420d..b64907d735eb9 100644 --- a/py/test/selenium/webdriver/common/select_element_handling_tests.py +++ b/py/test/selenium/webdriver/common/select_element_handling_tests.py @@ -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 @@ -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()) @@ -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') @@ -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))