diff --git a/src/SeleniumLibrary/keywords/selectelement.py b/src/SeleniumLibrary/keywords/selectelement.py index 9973e9270..e0330809f 100644 --- a/src/SeleniumLibrary/keywords/selectelement.py +++ b/src/SeleniumLibrary/keywords/selectelement.py @@ -18,206 +18,196 @@ from selenium.webdriver.support.ui import Select from SeleniumLibrary.base import LibraryComponent, keyword -from SeleniumLibrary.utils import is_truthy +from SeleniumLibrary.utils import is_truthy, plural_or_not as s class SelectElementKeywords(LibraryComponent): @keyword - def get_list_items(self, locator, value=False): - """Returns the labels or values in the select list identified by `locator`. + def get_list_items(self, locator, values=False): + """Returns all labels or values of selection list ``locator``. - Select list keywords work on both lists and combo boxes. Key attributes for - select lists are `id` and `name`. See `introduction` for details about - locating elements. + See the `Locating elements` section for details about the locator + syntax. + + Returns visible labels by default, but values can be returned by + setting the ``values`` argument to a true value (see `Boolean + arguments`). Example: - | ${labels1} = | Get List Items | xpath=//h1 | - | ${labels2} = | Get List Items | xpath=//h1 | value=${False} | - | ${values} = | Get List Items | xpath=//h1 | value=True | - | Should Be Equal | ${labels1} | ${labels2} | + | ${labels} = | Get List Items | mylist | | + | ${values} = | Get List Items | css:#container select | values=True | + + Support to return values is new in SeleniumLibrary 3.0. """ - select, options = self._get_select_list_options(locator) - if is_truthy(value): - return self._get_values_for_options(options) + options = self._get_options(locator) + if is_truthy(values): + return self._get_values(options) else: - return self._get_labels_for_options(options) + return self._get_labels(options) @keyword def get_selected_list_label(self, locator): - """Returns the visible label of the selected element from the select list identified by `locator`. + """Returns label of selected option from selection list ``locator``. + + If there are multiple selected options, label of the first option + is returned. - Select list keywords work on both lists and combo boxes. Key attributes for - select lists are `id` and `name`. See `introduction` for details about - locating elements. + See the `Locating elements` section for details about the locator + syntax. """ select = self._get_select_list(locator) return select.first_selected_option.text @keyword def get_selected_list_labels(self, locator): - """Returns the visible labels of selected elements (as a list) from the select list identified by `locator`. + """Returns labels of selected options from selection list ``locator``. - Fails if there is no selection. + Starting from SeleniumLibrary 3.0, returns an empty list if there + are no selections. In earlier versions this caused an error. - Select list keywords work on both lists and combo boxes. Key attributes for - select lists are `id` and `name`. See `introduction` for details about - locating elements. + See the `Locating elements` section for details about the locator + syntax. """ - select, options = self._get_select_list_options_selected(locator) - if not options: - raise ValueError("List '%s' does not have any selected values." - % locator) - return self._get_labels_for_options(options) + options = self._get_selected_options(locator) + return self._get_labels(options) @keyword def get_selected_list_value(self, locator): - """Returns the value of the selected element from the select list identified by `locator`. + """Returns value of selected option from selection list ``locator``. - Return value is read from `value` attribute of the selected element. + If there are multiple selected options, value of the first option + is returned. - Select list keywords work on both lists and combo boxes. Key attributes for - select lists are `id` and `name`. See `introduction` for details about - locating elements. + See the `Locating elements` section for details about the locator + syntax. """ select = self._get_select_list(locator) return select.first_selected_option.get_attribute('value') @keyword def get_selected_list_values(self, locator): - """Returns the values of selected elements (as a list) from the select list identified by `locator`. + """Returns values of selected options from selection list ``locator``. - Fails if there is no selection. + Starting from SeleniumLibrary 3.0, returns an empty list if there + are no selections. In earlier versions this caused an error. - Select list keywords work on both lists and combo boxes. Key attributes for - select lists are `id` and `name`. See `introduction` for details about - locating elements. + See the `Locating elements` section for details about the locator + syntax. """ - select, options = self._get_select_list_options_selected(locator) - # TODO: Should return an empty list, not fail - if not options: - raise ValueError("Select list with locator '%s' does not have any selected values") - return self._get_values_for_options(options) + options = self._get_selected_options(locator) + return self._get_values(options) @keyword - def list_selection_should_be(self, locator, *items): - """Verifies the selection of select list identified by `locator` is exactly `*items`. + def list_selection_should_be(self, locator, *expected): + """Verifies selection list ``locator`` has ``expected`` options selected. - If you want to test that no option is selected, simply give no `items`. + It is possible to give expected options both as visible labels and + as values. Starting from SeleniumLibrary 3.0, mixing labels and + values is not possible. Order of the selected options is not + validated. - Select list keywords work on both lists and combo boxes. Key attributes for - select lists are `id` and `name`. See `introduction` for details about - locating elements. + If no expected options are given, validates that the list has + no selections. A more explicit alternative is using `List Should + Have No Selections`. + + See the `Locating elements` section for details about the locator + syntax. + + Examples: + | `List Selection Should Be` | gender | Female | | + | `List Selection Should Be` | interests | Test Automation | Python | """ - items_str = items and "option(s) [ %s ]" % " | ".join(items) or "no options" - self.info("Verifying list '%s' has %s selected." % (locator, items_str)) - items = list(items) + self.info("Verifying list '%s' has option%s [ %s ] selected." + % (locator, s(expected), ' | '.join(expected))) self.page_should_contain_list(locator) - select, options = self._get_select_list_options_selected(locator) - if not items and len(options) == 0: - return - selected_values = self._get_values_for_options(options) - selected_labels = self._get_labels_for_options(options) - err = "List '%s' should have had selection [ %s ] but it was [ %s ]" \ - % (locator, ' | '.join(items), ' | '.join(selected_labels)) - for item in items: - if item not in selected_values + selected_labels: - raise AssertionError(err) - for selected_value, selected_label in zip(selected_values, selected_labels): - if selected_value not in items and selected_label not in items: - raise AssertionError(err) + options = self._get_selected_options(locator) + labels = self._get_labels(options) + values = self._get_values(options) + if sorted(expected) not in [sorted(labels), sorted(values)]: + raise AssertionError("List '%s' should have had selection [ %s ] " + "but selection was [ %s ]." + % (locator, ' | '.join(expected), + self._format_selection(labels, values))) + + def _format_selection(self, labels, values): + return ' | '.join('%s (%s)' % (label, value) + for label, value in zip(labels, values)) @keyword def list_should_have_no_selections(self, locator): - """Verifies select list identified by `locator` has no selections. + """Verifies selection list ``locator`` has no options selected. - Select list keywords work on both lists and combo boxes. Key attributes for - select lists are `id` and `name`. See `introduction` for details about - locating elements. + See the `Locating elements` section for details about the locator + syntax. """ - self.info("Verifying list '%s' has no selection." % locator) - select, options = self._get_select_list_options_selected(locator) + self.info("Verifying list '%s' has no selections." % locator) + options = self._get_selected_options(locator) if options: - selected_labels = self._get_labels_for_options(options) - items_str = " | ".join(selected_labels) + selection = self._format_selection(self._get_labels(options), + self._get_values(options)) raise AssertionError("List '%s' should have had no selection " - "(selection was [ %s ])" % (locator, items_str)) + "but selection was [ %s ]." + % (locator, selection)) @keyword def page_should_contain_list(self, locator, message=None, loglevel='INFO'): - """Verifies select list identified by `locator` is found from current page. + """Verifies selection list ``locator`` is found from current page. - See `Page Should Contain Element` for explanation about `message` and - `loglevel` arguments. + See `Page Should Contain Element` for explanation about ``message`` + and ``loglevel`` arguments. - Key attributes for lists are `id` and `name`. See `introduction` for - details about locating elements. + See the `Locating elements` section for details about the locator + syntax. """ self.assert_page_contains(locator, 'list', message, loglevel) @keyword def page_should_not_contain_list(self, locator, message=None, loglevel='INFO'): - """Verifies select list identified by `locator` is not found from current page. + """Verifies selection list ``locator`` is not found from current page. - See `Page Should Contain Element` for explanation about `message` and - `loglevel` arguments. + See `Page Should Contain Element` for explanation about ``message`` + and ``loglevel`` arguments. - Key attributes for lists are `id` and `name`. See `introduction` for - details about locating elements. + See the `Locating elements` section for details about the locator + syntax. """ self.assert_page_not_contains(locator, 'list', message, loglevel) @keyword def select_all_from_list(self, locator): - """Selects all values from multi-select list identified by `id`. + """Selects all options from multi-selection list ``locator``. - Key attributes for lists are `id` and `name`. See `introduction` for - details about locating elements. + See the `Locating elements` section for details about the locator + syntax. """ self.info("Selecting all options from list '%s'." % locator) - select = self._get_select_list(locator) if not select.is_multiple: - raise RuntimeError("Keyword 'Select all from list' works only for " - "multiselect lists.") - + raise RuntimeError("'Select All From List' works only with " + "multi-selection lists.") for i in range(len(select.options)): select.select_by_index(i) @keyword - def select_from_list(self, locator, *items): - """Selects `*items` from list identified by `locator` - - If more than one value is given for a single-selection list, the last - value will be selected. If the target list is a multi-selection list, - and `*items` is an empty list, all values of the list will be selected. - - *items try to select by value then by label. - - It's faster to use 'by index/value/label' functions. - - An exception is raised for a single-selection list if the last - value does not exist in the list and a warning for all other non- - existing items. For a multi-selection list, an exception is raised - for any and all non-existing values. - - Select list keywords work on both lists and combo boxes. Key attributes for - select lists are `id` and `name`. See `introduction` for details about - locating elements. + def select_from_list(self, locator, *options): + """Deprecated. Use `Select From List By Label/Value/Index` instead. + + This keyword selects options based on labels or values, which makes + it very complicated and slow. It has been deprecated in + SeleniumLibrary 3.0, and dedicated keywords `Select From List By + Label`, `Select From List By Value` and `Select From List By Index` + should be used instead. """ non_existing_items = [] - - items_str = items and "option(s) '%s'" % ", ".join(items) or "all options" + items_str = options and "option(s) '%s'" % ", ".join(options) or "all options" self.info("Selecting %s from list '%s'." % (items_str, locator)) - select = self._get_select_list(locator) - - if not items: + if not options: for i in range(len(select.options)): select.select_by_index(i) return - - for item in items: + for item in options: try: select.select_by_value(item) except: @@ -226,7 +216,6 @@ def select_from_list(self, locator, *items): except: non_existing_items = non_existing_items + [item] continue - if any(non_existing_items): if select.is_multiple: raise ValueError("Options '%s' not in list '%s'." % (", ".join(non_existing_items), locator)) @@ -234,87 +223,106 @@ def select_from_list(self, locator, *items): if any (non_existing_items[:-1]): items_str = non_existing_items[:-1] and "Option(s) '%s'" % ", ".join(non_existing_items[:-1]) self.warn("%s not found within list '%s'." % (items_str, locator)) - if items and items[-1] in non_existing_items: - raise ValueError("Option '%s' not in list '%s'." % (items[-1], locator)) + if options and options[-1] in non_existing_items: + raise ValueError("Option '%s' not in list '%s'." % (options[-1], locator)) @keyword def select_from_list_by_index(self, locator, *indexes): - """Selects `*indexes` from list identified by `locator` + """Selects options from selection list ``locator`` by ``indexes``. - Select list keywords work on both lists and combo boxes. Key attributes for - select lists are `id` and `name`. See `introduction` for details about - locating elements. + Indexes of list options start from 0. + + If more than one option is given for a single-selection list, + the last value will be selected. With multi-selection lists all + specified options are selected, but possible old selections are + not cleared. + + See the `Locating elements` section for details about the locator + syntax. """ if not indexes: - raise ValueError("No index given.") - items_str = "index(es) '%s'" % ", ".join(indexes) - self.info("Selecting %s from list '%s'." % (items_str, locator)) - + raise ValueError("No indexes given.") + self.info("Selecting options from selection list '%s' by index%s %s." + % (locator, '' if len(indexes) == 1 else 'es', + ', '.join(indexes))) select = self._get_select_list(locator) for index in indexes: select.select_by_index(int(index)) @keyword def select_from_list_by_value(self, locator, *values): - """Selects `*values` from list identified by `locator` + """Selects options from selection list ``locator`` by ``values``. - Select list keywords work on both lists and combo boxes. Key attributes for - select lists are `id` and `name`. See `introduction` for details about - locating elements. + If more than one option is given for a single-selection list, + the last value will be selected. With multi-selection lists all + specified options are selected, but possible old selections are + not cleared. + + See the `Locating elements` section for details about the locator + syntax. """ if not values: - raise ValueError("No value given.") - items_str = "value(s) '%s'" % ", ".join(values) - self.info("Selecting %s from list '%s'." % (items_str, locator)) - + raise ValueError("No values given.") + self.info("Selecting options from selection list '%s' by value%s %s." + % (locator, s(values), ', '.join(values))) select = self._get_select_list(locator) for value in values: select.select_by_value(value) @keyword def select_from_list_by_label(self, locator, *labels): - """Selects `*labels` from list identified by `locator` + """Selects options from selection list ``locator`` by ``labels``. + + If more than one option is given for a single-selection list, + the last value will be selected. With multi-selection lists all + specified options are selected, but possible old selections are + not cleared. - Select list keywords work on both lists and combo boxes. Key attributes for - select lists are `id` and `name`. See `introduction` for details about - locating elements. + See the `Locating elements` section for details about the locator + syntax. """ if not labels: - raise ValueError("No value given.") - items_str = "label(s) '%s'" % ", ".join(labels) - self.info("Selecting %s from list '%s'." % (items_str, locator)) - + raise ValueError("No labels given.") + self.info("Selecting options from selection list '%s' by label%s %s." + % (locator, s(labels), ', '.join(labels))) select = self._get_select_list(locator) for label in labels: select.select_by_visible_text(label) @keyword - def unselect_from_list(self, locator, *items): - """Unselects given values from select list identified by locator. + def unselect_all_from_list(self, locator): + """Unselects all options from multi-selection list ``locator``. - As a special case, giving empty list as `*items` will remove all - selections. + See the `Locating elements` section for details about the locator + syntax. - *items try to unselect by value AND by label. + New in SeleniumLibrary 3.0. + """ + self.info("Unselecting all options from list '%s'." % locator) + select = self._get_select_list(locator) + if not select.is_multiple: + raise RuntimeError("Un-selecting options works only with " + "multi-selection lists.") + select.deselect_all() - It's faster to use 'by index/value/label' functions. + @keyword + def unselect_from_list(self, locator, *items): + """Deprecated. Use `Unselect From List By Label/Value/Index` instead. - Select list keywords work on both lists and combo boxes. Key attributes for - select lists are `id` and `name`. See `introduction` for details about - locating elements. + This keyword unselects options based on labels or values, which makes + it very complicated and slow. It has been deprecated in + SeleniumLibrary 3.0, and dedicated keywords `Unselect From List By + Label`, `Unselect From List By Value` and `Unselect From List By + Index` should be used instead. """ items_str = items and "option(s) '%s'" % ", ".join(items) or "all options" self.info("Unselecting %s from list '%s'." % (items_str, locator)) - select = self._get_select_list(locator) if not select.is_multiple: raise RuntimeError("Keyword 'Unselect from list' works only for multiselect lists.") - if not items: select.deselect_all() return - - select, options = self._get_select_list_options(select) for item in items: # Only Selenium 2.52 and newer raise exceptions when there is no match. # For backwards compatibility reasons we want to ignore them. @@ -329,102 +337,78 @@ def unselect_from_list(self, locator, *items): @keyword def unselect_from_list_by_index(self, locator, *indexes): - """Unselects `*indexes` from list identified by `locator` + """Unselects options from selection list ``locator`` by ``indexes``. + + Indexes of list options start from 0. This keyword works only with + multi-selection lists. - Select list keywords work on both lists and combo boxes. Key attributes for - select lists are `id` and `name`. See `introduction` for details about - locating elements. + See the `Locating elements` section for details about the locator + syntax. """ if not indexes: - raise ValueError("No index given.") - - items_str = "index(es) '%s'" % ", ".join(indexes) - self.info("Unselecting %s from list '%s'." % (items_str, locator)) - + raise ValueError("No indexes given.") + self.info("Un-selecting options from selection list '%s' by index%s " + "%s." % (locator, '' if len(indexes) == 1 else 'es', + ', '.join(indexes))) select = self._get_select_list(locator) if not select.is_multiple: - raise RuntimeError("Keyword 'Unselect from list' works only for multiselect lists.") - + raise RuntimeError("Un-selecting options works only with " + "multi-selection lists.") for index in indexes: select.deselect_by_index(int(index)) @keyword def unselect_from_list_by_value(self, locator, *values): - """Unselects `*values` from list identified by `locator` + """Unselects options from selection list ``locator`` by ``values``. + + This keyword works only with multi-selection lists. - Select list keywords work on both lists and combo boxes. Key attributes for - select lists are `id` and `name`. See `introduction` for details about - locating elements. + See the `Locating elements` section for details about the locator + syntax. """ if not values: - raise ValueError("No value given.") - items_str = "value(s) '%s'" % ", ".join(values) - self.info("Unselecting %s from list '%s'." % (items_str, locator)) - + raise ValueError("No values given.") + self.info("Un-selecting options from selection list '%s' by value%s " + "%s." % (locator, s(values), ', '.join(values))) select = self._get_select_list(locator) if not select.is_multiple: - raise RuntimeError("Keyword 'Unselect from list' works only for multiselect lists.") - + raise RuntimeError("Un-selecting options works only with " + "multi-selection lists.") for value in values: select.deselect_by_value(value) @keyword def unselect_from_list_by_label(self, locator, *labels): - """Unselects `*labels` from list identified by `locator` + """Unselects options from selection list ``locator`` by ``labels``. - Select list keywords work on both lists and combo boxes. Key attributes for - select lists are `id` and `name`. See `introduction` for details about - locating elements. + This keyword works only with multi-selection lists. + + See the `Locating elements` section for details about the locator + syntax. """ if not labels: - raise ValueError("No value given.") - items_str = "label(s) '%s'" % ", ".join(labels) - self.info("Unselecting %s from list '%s'." % (items_str, locator)) - + raise ValueError("No labels given.") + self.info("Un-selecting options from selection list '%s' by label%s " + "%s." % (locator, s(labels), ', '.join(labels))) select = self._get_select_list(locator) if not select.is_multiple: - raise RuntimeError("Keyword 'Unselect from list' works only for multiselect lists.") - + raise RuntimeError("Un-selecting options works only with " + "multi-selection lists.") for label in labels: select.deselect_by_visible_text(label) - def _get_labels_for_options(self, options): - labels = [] - for option in options: - labels.append(option.text) - return labels - def _get_select_list(self, locator): el = self.find_element(locator, tag='list') return Select(el) - def _get_select_list_options(self, select_list_or_locator): - if isinstance(select_list_or_locator, Select): - select = select_list_or_locator - else: - select = self._get_select_list(select_list_or_locator) - return select, select.options + def _get_options(self, locator): + return self._get_select_list(locator).options - def _get_select_list_options_selected(self, locator): - select = self._get_select_list(locator) - # TODO: Handle possible exception thrown by all_selected_options - return select, select.all_selected_options - - def _get_values_for_options(self, options): - values = [] - for option in options: - values.append(option.get_attribute('value')) - return values - - def _is_multiselect_list(self, select): - multiple_value = select.get_attribute('multiple') - if multiple_value is not None and (multiple_value == 'true' or multiple_value == 'multiple'): - return True - return False - - def _unselect_all_options_from_multi_select_list(self, select): - self.browser.execute_script("arguments[0].selectedIndex = -1;", select) - - def _unselect_option_from_multi_select_list(self, select, options, index): - if options[index].is_selected(): - options[index].click() + def _get_selected_options(self, locator): + return self._get_select_list(locator).all_selected_options + + def _get_labels(self, options): + return [opt.text for opt in options] + + def _get_values(self, options): + return [opt.get_attribute('value') for opt in options] diff --git a/src/SeleniumLibrary/locators/elementfinder.py b/src/SeleniumLibrary/locators/elementfinder.py index edecf99ad..979afdc69 100644 --- a/src/SeleniumLibrary/locators/elementfinder.py +++ b/src/SeleniumLibrary/locators/elementfinder.py @@ -63,7 +63,7 @@ def find(self, locator, tag=None, first_only=True, required=True, element_type = 'Element' if not tag else tag.capitalize() if parent and not self._is_webelement(parent): raise ValueError('Parent must be Selenium WebElement but it ' - 'was {}'.format(type(parent))) + 'was {}.'.format(type(parent))) if self._is_webelement(locator): return locator prefix, criteria = self._parse_locator(locator) diff --git a/test/acceptance/keywords/lists.robot b/test/acceptance/keywords/lists.robot index be2f9fe8a..af4059314 100644 --- a/test/acceptance/keywords/lists.robot +++ b/test/acceptance/keywords/lists.robot @@ -1,5 +1,4 @@ *** Settings *** -Documentation Tests lists Test Setup Go To Page "forms/prefilled_email_form.html" Resource ../resource.robot Force Tags Known Issue Internet Explorer @@ -33,6 +32,8 @@ Get Selected List Values ${selected}= Get Selected List Values preferred_channel ${expected}= Create List phone Should Be Equal ${selected} ${expected} + ${selected}= Get Selected List Values interests + Should Be Empty ${selected} Get Selected List Label ${selected}= Get Selected List Label preferred_channel @@ -42,25 +43,29 @@ Get Selected List Label Should Be Equal ${selected} Males Get Selected List Labels - [Documentation] Get Selected List Labels ${selected}= Get Selected List Labels possible_channels ${expected}= Create List Email Telephone Should Be Equal ${selected} ${expected} + ${selected}= Get Selected List Labels interests + Should Be Empty ${selected} List Selection Should Be - [Documentation] LOG 2 Verifying list 'interests' has no options selected. - ... LOG 5 Verifying list 'possible_channels' has option(s) [ email | Telephone ] selected. + [Documentation] + ... LOG 2 Verifying list 'interests' has options [${SPACE*2}] selected. + ... LOG 5 Verifying list 'possible_channels' has options [ Email | Telephone ] selected. List Selection Should Be interests List Selection Should Be preferred_channel Telephone List Selection Should Be preferred_channel phone - List Selection Should Be possible_channels email Telephone + List Selection Should Be possible_channels Email Telephone + List Selection Should Be possible_channels Telephone Email + List Selection Should Be possible_channels phone email Run Keyword And Expect Error - ... List 'possible_channels' should have had selection [ email | Telephone | Direct mail ] but it was [ Email | Telephone ] - ... List Selection Should Be possible_channels email Telephone Direct mail + ... List 'possible_channels' should have had selection [ Email | Telephone | Direct mail ] but selection was [ Email (email) | Telephone (phone) ]. + ... List Selection Should Be possible_channels Email Telephone Direct mail List Selection Should Be When Extraneous Options Are Selected Run Keyword And Expect Error - ... List 'possible_channels' should have had selection [ email ] but it was [ Email | Telephone ] + ... List 'possible_channels' should have had selection [ email ] but selection was [ Email (email) | Telephone (phone) ]. ... List Selection Should Be possible_channels email List Selection Should Be When List Does Not Exist @@ -78,10 +83,20 @@ UnSelect Single Value From List ... Keyword 'Unselect from list' works only for multiselect lists. ... Unselect From List preferred_channel -UnSelect All From List +Unselect all options using Unselect From List [Documentation] LOG 2 Unselecting all options from list 'possible_channels'. Unselect From List possible_channels - List Selection Should Be possible_channels + List Should Have No Selections possible_channels + +Unselect All From List + [Documentation] LOG 2 Unselecting all options from list 'possible_channels'. + Unselect All From List possible_channels + List Should Have No Selections possible_channels + Unselect All From List interests + List Should Have No Selections interests + Select All From List interests + Unselect All From List interests + List Should Have No Selections interests Select From Single Selection List [Documentation] LOG 2.1 Selecting option(s) 'Email' from list 'preferred_channel'. @@ -125,38 +140,37 @@ Unselect Non-Existing Item From List Unselect From List possible_channels Tin Can Phone Smoke Signals Email Select From Multiselect List - [Documentation] LOG 5 Selecting option(s) 'Direct mail, phone' from list 'possible_channels'. - Select And verify selection possible_channels email email Telephone - Select And verify selection possible_channels - ... Direct mail Direct mail email Telephone + [Documentation] LOG 6 Selecting option(s) 'Direct mail, phone' from list 'possible_channels'. + Select And verify selection possible_channels Email Email Telephone + Select And verify selection possible_channels email email phone + Select And verify selection possible_channels Direct mail Direct mail Email Telephone Unselect from List possible_channels Select From List possible_channels Direct mail phone - List Selection Should Be possible_channels Telephone directmail + List Selection Should Be possible_channels Telephone Direct mail Select All From List [Documentation] LOG 2 Selecting all options from list 'interests'. Select All From List interests List Selection Should Be interests Males Females Others - Run Keyword And Expect Error Keyword 'Select all from list' works only for multiselect lists. + Run Keyword And Expect Error + ... 'Select All From List' works only with multi-selection lists. ... Select All From List preferred_channel List Should Have No Selections - [Documentation] LOG 2 Verifying list 'interests' has no selection. + [Documentation] LOG 2 Verifying list 'interests' has no selections. List Should Have No Selections interests Select All From List interests Run Keyword And Expect Error - ... List 'interests' should have had no selection (selection was [ Males | Females | Others ]) + ... List 'interests' should have had no selection but selection was [ Males (males) | Females (females) | Others (others) ]. ... List Should Have No Selections interests *** Keywords *** Unselect And Verify Selection - [Documentation] Unselect And Verify Selection [Arguments] ${list_id} ${unselection} @{exp_selection} Unselect From List ${list_id} ${unselection} List Selection Should Be ${list_id} @{exp_selection} Select And Verify Selection - [Documentation] Select And Verify Selection [Arguments] ${list_id} ${selection} @{exp_selection} Select From list ${list_id} ${selection} List Selection Should Be ${list_id} @{exp_selection} diff --git a/test/unit/keywords/test_keyword_arguments_selectelement.py b/test/unit/keywords/test_keyword_arguments_selectelement.py index 71e76544f..8aa981c75 100644 --- a/test/unit/keywords/test_keyword_arguments_selectelement.py +++ b/test/unit/keywords/test_keyword_arguments_selectelement.py @@ -19,25 +19,18 @@ def tearDown(self): def test_get_list_items_false(self): locator = '//select' - select = mock() element = mock() element.text = 'foo' - elements = [element] - when(self.element)._get_select_list_options(locator).thenReturn( - (select, elements)) + when(self.element)._get_options(locator).thenReturn([element]) self.element.get_list_items(locator) self.element.get_list_items(locator, 'None') self.element.get_list_items(locator, 'No') def test_get_list_items_true(self): locator = '//select' - select = mock() element = mock() - elements = [element] when(element).get_attribute('value').thenReturn('text') - # when(element).get_attribute('value').thenReturn('text') - when(self.element)._get_select_list_options(locator).thenReturn( - (select, elements)) + when(self.element)._get_options(locator).thenReturn([element]) self.element.get_list_items(locator, True) self.element.get_list_items(locator, 'True') self.element.get_list_items(locator, 'Yes')