From 9d5705eef905a4a73964a18f2d90216eab0f60a8 Mon Sep 17 00:00:00 2001 From: Viktor Tsvetkov <142901247+vtsvetkov-splunk@users.noreply.github.com> Date: Tue, 24 Oct 2023 15:53:20 +0200 Subject: [PATCH 1/6] fix(multiselect): fix deselect function --- .../components/controls/multi_select.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/pytest_splunk_addon_ui_smartx/components/controls/multi_select.py b/pytest_splunk_addon_ui_smartx/components/controls/multi_select.py index 31a44d81..e07d89d8 100644 --- a/pytest_splunk_addon_ui_smartx/components/controls/multi_select.py +++ b/pytest_splunk_addon_ui_smartx/components/controls/multi_select.py @@ -26,7 +26,7 @@ class MultiSelect(BaseControl): """ Entity-Component: Multiselect - Select Javascript framework: select2 + Reference: https://splunkui.splunk.com/Packages/react-ui/Multiselect?section=test A dropdown which can select more than one values """ @@ -40,15 +40,17 @@ def __init__(self, browser, container): self.elements.update( { "internal_container": Selector( - select=container.select + ' [role="listbox"]' + select=container.select + ' [data-test="multiselect"]' ), - "dropdown": Selector(select=container.select + ' [role="listbox"]'), + "dropdown": Selector(select=container.select + ' [data-test="menu"]'), "selected": Selector( - select=container.select - + ' button[data-test="selected-option"][role="option"]' + select=container.select + ' [data-test="selected-option"]' ), + """ + Click on selected element deselects it + """ "deselect": Selector( - select=container.select + ' [data-test="crossmark"]' + select=container.select + ' [data-test="selected-option"]' ), "input": Selector(select=container.select + ' [data-test="textbox"]'), } From 936ec123eeb78841fe971a7d14a5e497b57b512d Mon Sep 17 00:00:00 2001 From: Viktor Tsvetkov <142901247+vtsvetkov-splunk@users.noreply.github.com> Date: Wed, 25 Oct 2023 16:56:43 +0200 Subject: [PATCH 2/6] fix --- .../components/controls/multi_select.py | 74 ++++---- .../components/controls/oauth_select.py | 24 +-- .../components/controls/single_select.py | 169 ++++++++---------- .../components/dropdown.py | 53 +++--- 4 files changed, 140 insertions(+), 180 deletions(-) diff --git a/pytest_splunk_addon_ui_smartx/components/controls/multi_select.py b/pytest_splunk_addon_ui_smartx/components/controls/multi_select.py index e07d89d8..33de975c 100644 --- a/pytest_splunk_addon_ui_smartx/components/controls/multi_select.py +++ b/pytest_splunk_addon_ui_smartx/components/controls/multi_select.py @@ -13,10 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # -import time from selenium.common.exceptions import ElementClickInterceptedException -from selenium.webdriver.common.by import By + from selenium.webdriver.common.keys import Keys from ..base_component import Selector @@ -26,7 +25,6 @@ class MultiSelect(BaseControl): """ Entity-Component: Multiselect - Reference: https://splunkui.splunk.com/Packages/react-ui/Multiselect?section=test A dropdown which can select more than one values """ @@ -37,24 +35,23 @@ def __init__(self, browser, container): """ super().__init__(browser, container) - self.elements.update( - { - "internal_container": Selector( - select=container.select + ' [data-test="multiselect"]' - ), - "dropdown": Selector(select=container.select + ' [data-test="menu"]'), - "selected": Selector( - select=container.select + ' [data-test="selected-option"]' - ), - """ + root_selector = container.select + ' [data-test="multiselect"]' + self.elements.update({ + "root": Selector(select=root_selector) + }) + + self.elements.update({ + "selected": Selector( + select=root_selector + ' [data-test="selected-option"]' + ), + """ Click on selected element deselects it """ - "deselect": Selector( - select=container.select + ' [data-test="selected-option"]' - ), - "input": Selector(select=container.select + ' [data-test="textbox"]'), - } - ) + "deselect": Selector( + select=root_selector + ' [data-test="selected-option"]' + ), + "input": Selector(select=root_selector + ' [data-test="textbox"]'), + }) def search(self, value): """ @@ -73,37 +70,33 @@ def search_get_list(self, value): """ search with the multiselect input and return the list :param value: string value to search - :returns: list of values + :return list of values """ self.search(value) self.wait_for_search_list() searched_values = list(self._list_visible_values()) self.input.send_keys(Keys.ESCAPE) - self.wait_for("container") return searched_values def select(self, value): """ select a single value :param value: the value to select - :return: Bool returns true if selection was successful, else raises an exception + :return Bool returns true if selection was successful, else raises an exception """ try: - time.sleep(1) try: self.input.click() except ElementClickInterceptedException: self.label_text.click() - time.sleep(1) self.input.click() - time.sleep(1) - popoverid = "#" + self.dropdown.get_attribute("data-test-popover-id") except: raise Exception("dropdown not found") + popover_id = "#" + self.root.get_attribute("data-test-popover-id") self.elements.update( - {"values": Selector(select=popoverid + ' [data-test="option"]')} + {"values": Selector(select=popover_id + ' [data-test="option"]')} ) for each in self.get_elements("values"): if each.text.strip().lower() == value.lower(): @@ -117,15 +110,12 @@ def deselect(self, value): """ Remove an item from selected list. :param value: the value to deselect - :return: Bool returns true if deselect was successful, else raises an exception + :return Bool returns true if deselect was successful, else raises an exception """ for each in self.get_child_elements("selected"): if each.text.strip().lower() == value.lower(): - time.sleep(1) - each.find_element( - *list(self.elements["deselect"]._asdict().values()) - ).click() - self.wait_for("internal_container") + each.click() + self.wait_for("root") return True else: raise ValueError("{} not found in select list".format(value)) @@ -140,24 +130,23 @@ def deselect_all(self): def get_values(self): """ get list selected values - :returns: List of values selected within the multi-select + :return List of values selected within the multi-select """ return [each.text.strip() for each in self.get_child_elements("selected")] def list_of_values(self): """ Get list of possible values to select from dropdown - :returns: List of options within the multi-select dropdown + :return List of options within the multi-select dropdown """ - self.wait_for("internal_container") - time.sleep(1) + self.wait_for("root") list_of_values = [] self.input.click() - popoverid = "#" + self.dropdown.get_attribute("data-test-popover-id") + popover_id = "#" + self.root.get_attribute("data-test-popover-id") self.elements.update( { "values": Selector( - select=popoverid + ' [data-test="option"] [data-test="label"]' + select=popover_id + ' [data-test="option"] [data-test="label"]' ) } ) @@ -174,15 +163,14 @@ def get_list_count(self): def _list_visible_values(self): """ Get list of values which are visible. Used while filtering - :returns: List of visible options within the multi-select dropdown + :return List of visible options within the multi-select dropdown """ self.input.click() - popoverid = "#" + self.dropdown.get_attribute("data-test-popover-id") + popover_id = "#" + self.root.get_attribute("data-test-popover-id") self.elements.update( { "values": Selector( - select=popoverid - + ' [data-test="option"]:not([data-test-selected="true"]) [data-test="label"]' + select=popover_id + ' [data-test="option"]:not([data-test-selected="true"]) [data-test="label"]' ) } ) diff --git a/pytest_splunk_addon_ui_smartx/components/controls/oauth_select.py b/pytest_splunk_addon_ui_smartx/components/controls/oauth_select.py index efb09393..325b55ea 100644 --- a/pytest_splunk_addon_ui_smartx/components/controls/oauth_select.py +++ b/pytest_splunk_addon_ui_smartx/components/controls/oauth_select.py @@ -14,18 +14,13 @@ # limitations under the License. # -import time - -from selenium.webdriver.common.by import By -from selenium.webdriver.common.keys import Keys - from ..base_component import Selector from .base_control import BaseControl class OAuthSelect(BaseControl): """ - Entity-Component: OAuthSelect + Entity-Component: Select OAuthSelect Javascript framework: OAuthSelect @@ -41,8 +36,8 @@ def __init__(self, browser, container, searchable=True): super().__init__(browser, container) self.elements.update( { + "root": Selector(select=container.select + ' [data-test="select"]'), "values": Selector(select=container.select + ' [data-test="option"]'), - "dropdown": Selector(select=container.select + " .dropdownBox"), } ) @@ -53,12 +48,12 @@ def select(self, value): :return: Bool if successful in selection, else raises an error """ - self.dropdown.click() - popoverid = "#" + self.dropdown.get_attribute("data-test-popover-id") + self.root.click() + popover_id = "#" + self.root.get_attribute("data-test-popover-id") self.elements.update( { "values": Selector( - select=popoverid + select=popover_id + ' [data-test="option"]:not([data-test-selected="true"]) [data-test="label"]' ) } @@ -76,8 +71,7 @@ def get_value(self): :return: Str The elected value within the dropdown, else returns blank """ try: - element = self.get_element("dropdown") - return element.get_attribute("data-test-value") + return self.root.get_attribute("data-test-value") except: return "" @@ -87,12 +81,12 @@ def list_of_values(self): :returns: List of options from the single select """ selected_val = self.get_value() - self.container.click() + self.root.click() first_element = None list_of_values = [] - popoverid = "#" + self.dropdown.get_attribute("data-test-popover-id") + popover_id = "#" + self.root.get_attribute("data-test-popover-id") self.elements.update( - {"values": Selector(select=popoverid + ' [data-test="option"]')} + {"values": Selector(select=popover_id + ' [data-test="option"]')} ) for each in self.get_elements("values"): list_of_values.append(each.text.strip()) diff --git a/pytest_splunk_addon_ui_smartx/components/controls/single_select.py b/pytest_splunk_addon_ui_smartx/components/controls/single_select.py index 645b5de6..00dfd4fb 100644 --- a/pytest_splunk_addon_ui_smartx/components/controls/single_select.py +++ b/pytest_splunk_addon_ui_smartx/components/controls/single_select.py @@ -14,10 +14,6 @@ # limitations under the License. # -import time -from time import sleep - -from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys from ..base_component import Selector @@ -36,61 +32,55 @@ def __init__(self, browser, container, searchable=True, allow_new_values=False): :param browser: The selenium webdriver :param container: The locator of the container where the control is located in. :param searchable: Boolean indicating if the dropdown provides filter or not. - :param allow_new_values: Boolean indicating if the dropdown allows for user entered custom values excluding predefined list. + :param allow_new_values: Boolean indicating if the dropdown allows for user-entered custom values + excluding a predefined list. """ super().__init__(browser, container) self.searchable = searchable # Component is ComboBox in case of True self.allow_new_values = allow_new_values self.container = container - self.elements.update( - { - "internal_container": Selector( - select=container.select + " .dropdownBox" - ), - "dropdown": Selector(select=container.select + " .dropdownBox"), - "combobox": Selector( - select=container.select + ' [data-test="combo-box"]' - ), - "selected": Selector( - select=container.select + ' [data-test="textbox"]' - ), - "cancel_selected": Selector( - select=container.select + ' [data-test="clear"]' - ), - } - ) + if not self.searchable and self.allow_new_values: raise ValueError( "Invalid combination of values for searchable and allow_new_values flags" ) + self.element_selector = (container.select + + (' [data-test="combo-box"]' if allow_new_values else ' [data-test="select"]')) + + self.elements.update( + { + "root": Selector(select=self.element_selector), + "selected": Selector(select=container.select + ' [data-test="textbox"]'), + "cancel_selected": Selector(select=container.select + ' [data-test="clear"]'), + } + ) + def select(self, value, open_dropdown=True): """ Selects the value within the select dropdown :param value: the value to select - :param open_dropdown: Whether or not the dropdown should be opened + :param open_dropdown: Whether the dropdown should be opened :return: Bool if successful in selection, else raises an error """ if open_dropdown: - self.wait_to_be_clickable("dropdown") - self.dropdown.click() + self.root.click() - if self.allow_new_values: - if self.get_value(): - self.cancel_selected.click() - popoverid = "#" + self.combobox.get_attribute("data-test-popover-id") - else: - popoverid = "#" + self.dropdown.get_attribute("data-test-popover-id") - self.elements.update( - {"values": Selector(select=popoverid + ' [data-test="option"]')} - ) + if self.allow_new_values and self.get_value(): + self.cancel_selected.click() + + popover_id = "#" + self.root.get_attribute("data-test-popover-id") + + self.elements.update({ + "values": Selector(select=popover_id + ' [data-test="option"]'), + "dropdown": Selector(select=popover_id + ' [data-test="menu"]'), + "combobox": Selector(select=popover_id + ' [data-test="menu"]'), + }) for each in self.get_elements("values"): if each.text.strip().lower() == value.lower(): each.click() - self.wait_for("internal_container") - sleep(0.25) return True else: raise ValueError("{} not found in select list".format(value)) @@ -99,35 +89,32 @@ def search(self, value, open_dropdown=True): """ search with the singleselect input :param value: string value to search - :assert: Asserts whether or not the single select is seachable + :assert Asserts whether the single select is seachable """ assert self.searchable, "Can not search, as the Singleselect is not searchable" if open_dropdown: - self.wait_to_be_clickable("dropdown") - self.dropdown.click() + self.root.click() if self.searchable: if self.allow_new_values: - self.elements.update( - { + self.elements.update({ "input": Selector( - select=self.container.select + ' [data-test="textbox"]' + select=self.element_selector + ' [data-test="textbox"]' ) - } - ) + }) else: - popoverid = "#" + self.dropdown.get_attribute("data-test-popover-id") + popover_id = "#" + self.root.get_attribute("data-test-popover-id") self.elements.update( - {"input": Selector(select=popoverid + ' [data-test="textbox"]')} + {"input": Selector(select=popover_id + ' [data-test="textbox"]')} ) - # DEBUG: maybe we have to click the select button self.input.send_keys(value) + # DEBUG: maybe we have to click the select button def search_get_list(self, value): """ search with the singleselect input and return the list :param value: string value to search - :returns: list of values + :return list of values """ if self.searchable: @@ -135,15 +122,15 @@ def search_get_list(self, value): self.elements.update( { "input": Selector( - select=self.container.select + ' [data-test="textbox"]' + select=self.element_selector + ' [data-test="textbox"]' ) } ) else: - self.dropdown.click() - popoverid = "#" + self.dropdown.get_attribute("data-test-popover-id") + self.root.click() + popover_id = "#" + self.root.get_attribute("data-test-popover-id") self.elements.update( - {"input": Selector(select=popoverid + ' [data-test="textbox"]')} + {"input": Selector(select=popover_id + ' [data-test="textbox"]')} ) # as the dropdown is already open we dont try to open it self.search(value, open_dropdown=False) @@ -153,34 +140,37 @@ def search_get_list(self, value): self.wait_for_search_list() searched_values = list(self._list_visible_values(open_dropdown=False)) self.input.send_keys(Keys.ESCAPE) - self.wait_for("container") + self.wait_for("root") + + print('searched_values') + print(searched_values) return searched_values def _list_visible_values(self, open_dropdown=True): """ - Gets list of values which are visible. Used while filtering - :param open_dropdown: Whether or not the dropdown should be opened - :returns: List of the values that are visible + Gets a list of values which are visible. Used while filtering + :param open_dropdown: Whether the dropdown should be opened + :return List of the values that are visible """ if open_dropdown: - self.dropdown.click() + self.root.click() if self.allow_new_values: - popoverid = "#" + self.combobox.get_attribute("data-test-popover-id") + popover_id = "#" + self.root.get_attribute("data-test-popover-id") self.elements.update( - {"values": Selector(select=popoverid + ' [data-test="option"]')} + {"values": Selector(select=popover_id + ' [data-test="option"]')} ) else: - popoverid = "#" + self.dropdown.get_attribute("data-test-popover-id") + popover_id = "#" + self.root.get_attribute("data-test-popover-id") self.elements.update( { "values": Selector( - select=popoverid + select=popover_id + ' [data-test="option"]:not([data-test-selected="true"]) [data-test="label"]' ) } ) for each in self.get_elements("values"): - yield each.get_attribute("textContent") + yield each.get_attribute("data-test-current-value-option") or each.get_attribute("textContent") def get_value(self): """ @@ -191,10 +181,10 @@ def get_value(self): # ComboBox do not support label return self.selected.get_attribute("value") else: - if self.dropdown.get_attribute( + if self.root.get_attribute( "data-test-loading" - ) == "false" and self.dropdown.get_attribute("data-test-value"): - return self.dropdown.get_attribute("label") + ) == "false" and self.root.get_attribute("data-test-value"): + return self.root.get_attribute("label") else: return False @@ -212,10 +202,10 @@ def get_placeholder_value(self): } ) else: - self.dropdown.click() - popoverid = "#" + self.dropdown.get_attribute("data-test-popover-id") + self.root.click() + popover_id = "#" + self.root.get_attribute("data-test-popover-id") self.elements.update( - {"input": Selector(select=popoverid + ' [data-test="textbox"]')} + {"input": Selector(select=popover_id + ' [data-test="textbox"]')} ) return self.input.get_attribute("placeholder").strip() @@ -223,10 +213,9 @@ def get_placeholder_value(self): def cancel_selected_value(self): """ Cancels the currently selected value in the SingleSelect - :return: Bool whether or not canceling the selected item was successful, else raises a error + :return: Bool whether canceling the selected item was successful, else raises an error """ - sleep(1) - self.dropdown.click() + self.root.click() self.wait_to_be_clickable("cancel_selected") self.cancel_selected.click() return True @@ -234,14 +223,14 @@ def cancel_selected_value(self): def list_of_values(self): """ Gets the list of value from the Single Select - :returns: list of options avaialble within the single select + :return list of options avaialble within the single select """ selected_val = self.get_value() - sleep(1) - self.dropdown.click() + self.root.click() first_element = None list_of_values = [] + popover_id = "#" + self.root.get_attribute("data-test-popover-id") if self.allow_new_values: if self.searchable: self.elements.update( @@ -251,15 +240,13 @@ def list_of_values(self): ) } ) - popoverid = "#" + self.combobox.get_attribute("data-test-popover-id") else: - popoverid = "#" + self.dropdown.get_attribute("data-test-popover-id") if self.searchable: self.elements.update( - {"input": Selector(select=popoverid + ' [data-test="textbox"]')} + {"input": Selector(select=popover_id + ' [data-test="textbox"]')} ) self.elements.update( - {"values": Selector(select=popoverid + ' [data-test="option"]')} + {"values": Selector(select=popover_id + ' [data-test="option"]')} ) for each in self.get_elements("values"): @@ -273,7 +260,7 @@ def list_of_values(self): self.input.send_keys(Keys.ESCAPE) elif first_element: self.select(first_element.text.strip(), open_dropdown=False) - self.wait_for("internal_container") + self.wait_for("root") return list_of_values def get_single_value(self): @@ -281,10 +268,9 @@ def get_single_value(self): Return one value from Single Select """ selected_val = self.get_value() - first_element = None - self.wait_to_be_clickable("dropdown") - self.dropdown.click() + self.wait_to_be_clickable('root') + self.root.click() if self.allow_new_values: if self.searchable: self.elements.update( @@ -294,24 +280,23 @@ def get_single_value(self): ) } ) - popoverid = "#" + self.combobox.get_attribute("data-test-popover-id") + popover_id = "#" + self.root.get_attribute("data-test-popover-id") self.elements.update( { "values": Selector( - select=popoverid + select=popover_id + ' [data-test="option"]:not([data-test-selected="true"]) [data-test="label"]' ) } ) else: + popover_id = "#" + self.root.get_attribute("data-test-popover-id") if self.searchable: - popoverid = "#" + self.dropdown.get_attribute("data-test-popover-id") self.elements.update( - {"input": Selector(select=popoverid + ' [data-test="textbox"]')} + {"input": Selector(select=popover_id + ' [data-test="textbox"]')} ) - popoverid = "#" + self.dropdown.get_attribute("data-test-popover-id") self.elements.update( - {"values": Selector(select=popoverid + ' [data-test="option"]')} + {"values": Selector(select=popover_id + ' [data-test="option"]')} ) single_element = self.get_element("values") @@ -323,7 +308,7 @@ def get_single_value(self): self.input.send_keys(Keys.ESCAPE) else: self.select(single_element.text.strip(), open_dropdown=False) - self.wait_for("internal_container") + self.wait_for("root") return single_element def get_list_count(self): @@ -369,10 +354,10 @@ def is_editable(self): } ) else: - self.dropdown.click() - popoverid = "#" + self.dropdown.get_attribute("data-test-popover-id") + self.root.click() + popover_id = "#" + self.root.get_attribute("data-test-popover-id") self.elements.update( - {"input": Selector(select=popoverid + ' [data-test="textbox"]')} + {"input": Selector(select=popover_id + ' [data-test="textbox"]')} ) return not bool( self.input.get_attribute("readonly") diff --git a/pytest_splunk_addon_ui_smartx/components/dropdown.py b/pytest_splunk_addon_ui_smartx/components/dropdown.py index 2c16efa8..180e0cde 100644 --- a/pytest_splunk_addon_ui_smartx/components/dropdown.py +++ b/pytest_splunk_addon_ui_smartx/components/dropdown.py @@ -14,13 +14,6 @@ # limitations under the License. # -import re -import time - -from selenium.common import exceptions -from selenium.webdriver.common.by import By -from selenium.webdriver.common.keys import Keys - from .base_component import BaseComponent, Selector @@ -30,7 +23,7 @@ class Dropdown(BaseComponent): Base class of Input & Configuration table """ - def __init__(self, browser, container, mapping=dict()): + def __init__(self, browser, container): """ :param browser: The selenium webdriver :param container: Container in which the table is located. Of type dictionary: {"by":..., "select":...} @@ -39,14 +32,12 @@ def __init__(self, browser, container, mapping=dict()): super().__init__(browser, container) self.elements.update( { + "root": Selector(select=container.select), "currunt_value": Selector( select=container.select + ' [data-test="select"] [data-test="label"]' ), - "pagination_dropdown": Selector(select='button[data-test="select"]'), - "type_dropdown": Selector(select=container.select), - "add_input": Selector(by=By.ID, select="addInputBtn"), - "type_filter_list": Selector(select='button[data-test="option"]'), + "type_dropdown": Selector(select=container.select) } ) @@ -56,11 +47,11 @@ def select_page_option(self, value): :param value: The value in which we want to select :return: Returns True if successful, otherwise raises an error """ - self.pagination_dropdown.click() - popoverid = "#" + self.pagination_dropdown.get_attribute("data-test-popover-id") + self.root.click() + popover_id = "#" + self.root.get_attribute("data-test-popover-id") self.elements.update( { - "page_list": Selector(select=popoverid + ' [data-test="label"]'), + "page_list": Selector(select=popover_id + ' [data-test="label"]'), } ) for each in self.get_elements("page_list"): @@ -84,16 +75,18 @@ def select(self, value): :return: Returns True if successful, otherwise raises an error """ - self.add_input.click() - popoverid = "#" + self.add_input.get_attribute("data-test-popover-id") + self.root.click() + popover_id = "#" + self.root.get_attribute("data-test-popover-id") self.elements.update( { + "pagination_dropdown": Selector(select=popover_id + '[data-test="menu"]'), "values": Selector( - select=popoverid + select=popover_id + ' [data-test="item"]:not([data-test-selected="true"]) [data-test="label"]' ) } ) + for each in self.get_elements("values"): if each.text.strip().lower() == value.lower(): each.click() @@ -109,11 +102,11 @@ def select_input_type(self, value, open_dropdown=True): :return: Returns True if successful, otherwise raises an error """ if open_dropdown: - self.type_dropdown.click() - popoverid = "#" + self.type_dropdown.get_attribute("data-test-popover-id") + self.root.click() + popover_id = "#" + self.root.get_attribute("data-test-popover-id") self.elements.update( { - "type_filter_list": Selector(select=popoverid + ' [data-test="label"]'), + "type_filter_list": Selector(select=popover_id + ' [data-test="label"]'), } ) for each in self.get_elements("type_filter_list"): @@ -128,11 +121,11 @@ def get_inputs_list(self): Returns a generator list for the options available in the add input dropdown :return: Returns Generator list of values """ - self.add_input.click() - popoverid = "#" + self.add_input.get_attribute("data-test-popover-id") + self.root.click() + popover_id = "#" + self.root.get_attribute("data-test-popover-id") self.elements.update( { - "type_list": Selector(select=popoverid + ' [data-test="item"]'), + "type_list": Selector(select=popover_id + ' [data-test="item"]'), } ) return [each.text.strip() for each in self.get_elements("type_list")] @@ -142,11 +135,11 @@ def get_pagination_list(self): Returns a generator list for the pagination text available in the add input dropdown :return: Returns Generator list of values """ - self.pagination_dropdown.click() - popoverid = "#" + self.pagination_dropdown.get_attribute("data-test-popover-id") + self.root.click() + popover_id = "#" + self.root.get_attribute("data-test-popover-id") self.elements.update( { - "page_list": Selector(select=popoverid + ' [data-test="label"]'), + "page_list": Selector(select=popover_id + ' [data-test="label"]'), } ) return [each.text.strip() for each in self.get_elements("page_list")] @@ -156,11 +149,11 @@ def get_input_type_list(self): Returns a generator list for the input types available in the add input dropdown :return: Returns Generator list of values """ - self.type_dropdown.click() - popoverid = "#" + self.type_dropdown.get_attribute("data-test-popover-id") + self.root.click() + popover_id = "#" + self.root.get_attribute("data-test-popover-id") self.elements.update( { - "type_filter_list": Selector(select=popoverid + ' [data-test="label"]'), + "type_filter_list": Selector(select=popover_id + ' [data-test="label"]'), } ) return [each.text.strip() for each in self.get_elements("type_filter_list")] From 649be62f9b40f77d0e61aa15e0366c062e067b43 Mon Sep 17 00:00:00 2001 From: Viktor Tsvetkov <142901247+vtsvetkov-splunk@users.noreply.github.com> Date: Wed, 25 Oct 2023 16:59:33 +0200 Subject: [PATCH 3/6] precommit --- .../components/controls/multi_select.py | 31 ++++++++------- .../components/controls/single_select.py | 39 ++++++++++++------- .../components/dropdown.py | 16 +++++--- 3 files changed, 52 insertions(+), 34 deletions(-) diff --git a/pytest_splunk_addon_ui_smartx/components/controls/multi_select.py b/pytest_splunk_addon_ui_smartx/components/controls/multi_select.py index 33de975c..60a13f03 100644 --- a/pytest_splunk_addon_ui_smartx/components/controls/multi_select.py +++ b/pytest_splunk_addon_ui_smartx/components/controls/multi_select.py @@ -36,22 +36,22 @@ def __init__(self, browser, container): super().__init__(browser, container) root_selector = container.select + ' [data-test="multiselect"]' - self.elements.update({ - "root": Selector(select=root_selector) - }) - - self.elements.update({ - "selected": Selector( - select=root_selector + ' [data-test="selected-option"]' - ), - """ + self.elements.update({"root": Selector(select=root_selector)}) + + self.elements.update( + { + "selected": Selector( + select=root_selector + ' [data-test="selected-option"]' + ), + """ Click on selected element deselects it """ - "deselect": Selector( - select=root_selector + ' [data-test="selected-option"]' - ), - "input": Selector(select=root_selector + ' [data-test="textbox"]'), - }) + "deselect": Selector( + select=root_selector + ' [data-test="selected-option"]' + ), + "input": Selector(select=root_selector + ' [data-test="textbox"]'), + } + ) def search(self, value): """ @@ -170,7 +170,8 @@ def _list_visible_values(self): self.elements.update( { "values": Selector( - select=popover_id + ' [data-test="option"]:not([data-test-selected="true"]) [data-test="label"]' + select=popover_id + + ' [data-test="option"]:not([data-test-selected="true"]) [data-test="label"]' ) } ) diff --git a/pytest_splunk_addon_ui_smartx/components/controls/single_select.py b/pytest_splunk_addon_ui_smartx/components/controls/single_select.py index 00dfd4fb..232e45f0 100644 --- a/pytest_splunk_addon_ui_smartx/components/controls/single_select.py +++ b/pytest_splunk_addon_ui_smartx/components/controls/single_select.py @@ -46,14 +46,19 @@ def __init__(self, browser, container, searchable=True, allow_new_values=False): "Invalid combination of values for searchable and allow_new_values flags" ) - self.element_selector = (container.select + - (' [data-test="combo-box"]' if allow_new_values else ' [data-test="select"]')) + self.element_selector = container.select + ( + ' [data-test="combo-box"]' if allow_new_values else ' [data-test="select"]' + ) self.elements.update( { "root": Selector(select=self.element_selector), - "selected": Selector(select=container.select + ' [data-test="textbox"]'), - "cancel_selected": Selector(select=container.select + ' [data-test="clear"]'), + "selected": Selector( + select=container.select + ' [data-test="textbox"]' + ), + "cancel_selected": Selector( + select=container.select + ' [data-test="clear"]' + ), } ) @@ -72,11 +77,13 @@ def select(self, value, open_dropdown=True): popover_id = "#" + self.root.get_attribute("data-test-popover-id") - self.elements.update({ - "values": Selector(select=popover_id + ' [data-test="option"]'), - "dropdown": Selector(select=popover_id + ' [data-test="menu"]'), - "combobox": Selector(select=popover_id + ' [data-test="menu"]'), - }) + self.elements.update( + { + "values": Selector(select=popover_id + ' [data-test="option"]'), + "dropdown": Selector(select=popover_id + ' [data-test="menu"]'), + "combobox": Selector(select=popover_id + ' [data-test="menu"]'), + } + ) for each in self.get_elements("values"): if each.text.strip().lower() == value.lower(): @@ -96,11 +103,13 @@ def search(self, value, open_dropdown=True): self.root.click() if self.searchable: if self.allow_new_values: - self.elements.update({ + self.elements.update( + { "input": Selector( select=self.element_selector + ' [data-test="textbox"]' ) - }) + } + ) else: popover_id = "#" + self.root.get_attribute("data-test-popover-id") self.elements.update( @@ -142,7 +151,7 @@ def search_get_list(self, value): self.input.send_keys(Keys.ESCAPE) self.wait_for("root") - print('searched_values') + print("searched_values") print(searched_values) return searched_values @@ -170,7 +179,9 @@ def _list_visible_values(self, open_dropdown=True): } ) for each in self.get_elements("values"): - yield each.get_attribute("data-test-current-value-option") or each.get_attribute("textContent") + yield each.get_attribute( + "data-test-current-value-option" + ) or each.get_attribute("textContent") def get_value(self): """ @@ -269,7 +280,7 @@ def get_single_value(self): """ selected_val = self.get_value() - self.wait_to_be_clickable('root') + self.wait_to_be_clickable("root") self.root.click() if self.allow_new_values: if self.searchable: diff --git a/pytest_splunk_addon_ui_smartx/components/dropdown.py b/pytest_splunk_addon_ui_smartx/components/dropdown.py index 180e0cde..0fcbbb54 100644 --- a/pytest_splunk_addon_ui_smartx/components/dropdown.py +++ b/pytest_splunk_addon_ui_smartx/components/dropdown.py @@ -37,7 +37,7 @@ def __init__(self, browser, container): select=container.select + ' [data-test="select"] [data-test="label"]' ), - "type_dropdown": Selector(select=container.select) + "type_dropdown": Selector(select=container.select), } ) @@ -79,11 +79,13 @@ def select(self, value): popover_id = "#" + self.root.get_attribute("data-test-popover-id") self.elements.update( { - "pagination_dropdown": Selector(select=popover_id + '[data-test="menu"]'), + "pagination_dropdown": Selector( + select=popover_id + '[data-test="menu"]' + ), "values": Selector( select=popover_id + ' [data-test="item"]:not([data-test-selected="true"]) [data-test="label"]' - ) + ), } ) @@ -106,7 +108,9 @@ def select_input_type(self, value, open_dropdown=True): popover_id = "#" + self.root.get_attribute("data-test-popover-id") self.elements.update( { - "type_filter_list": Selector(select=popover_id + ' [data-test="label"]'), + "type_filter_list": Selector( + select=popover_id + ' [data-test="label"]' + ), } ) for each in self.get_elements("type_filter_list"): @@ -153,7 +157,9 @@ def get_input_type_list(self): popover_id = "#" + self.root.get_attribute("data-test-popover-id") self.elements.update( { - "type_filter_list": Selector(select=popover_id + ' [data-test="label"]'), + "type_filter_list": Selector( + select=popover_id + ' [data-test="label"]' + ), } ) return [each.text.strip() for each in self.get_elements("type_filter_list")] From 0e4c8c6aaac3118cc820c461343b95e3b278023f Mon Sep 17 00:00:00 2001 From: Viktor Tsvetkov <142901247+vtsvetkov-splunk@users.noreply.github.com> Date: Wed, 25 Oct 2023 17:03:31 +0200 Subject: [PATCH 4/6] comment typo --- .../components/controls/multi_select.py | 12 ++++++------ .../components/controls/single_select.py | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pytest_splunk_addon_ui_smartx/components/controls/multi_select.py b/pytest_splunk_addon_ui_smartx/components/controls/multi_select.py index 60a13f03..2c3ec741 100644 --- a/pytest_splunk_addon_ui_smartx/components/controls/multi_select.py +++ b/pytest_splunk_addon_ui_smartx/components/controls/multi_select.py @@ -70,7 +70,7 @@ def search_get_list(self, value): """ search with the multiselect input and return the list :param value: string value to search - :return list of values + :return: list of values """ self.search(value) self.wait_for_search_list() @@ -82,7 +82,7 @@ def select(self, value): """ select a single value :param value: the value to select - :return Bool returns true if selection was successful, else raises an exception + :return: Bool returns true if selection was successful, else raises an exception """ try: try: @@ -110,7 +110,7 @@ def deselect(self, value): """ Remove an item from selected list. :param value: the value to deselect - :return Bool returns true if deselect was successful, else raises an exception + :return: Bool returns true if deselect was successful, else raises an exception """ for each in self.get_child_elements("selected"): if each.text.strip().lower() == value.lower(): @@ -130,14 +130,14 @@ def deselect_all(self): def get_values(self): """ get list selected values - :return List of values selected within the multi-select + :return: List of values selected within the multi-select """ return [each.text.strip() for each in self.get_child_elements("selected")] def list_of_values(self): """ Get list of possible values to select from dropdown - :return List of options within the multi-select dropdown + :return: List of options within the multi-select dropdown """ self.wait_for("root") list_of_values = [] @@ -163,7 +163,7 @@ def get_list_count(self): def _list_visible_values(self): """ Get list of values which are visible. Used while filtering - :return List of visible options within the multi-select dropdown + :return: List of visible options within the multi-select dropdown """ self.input.click() popover_id = "#" + self.root.get_attribute("data-test-popover-id") diff --git a/pytest_splunk_addon_ui_smartx/components/controls/single_select.py b/pytest_splunk_addon_ui_smartx/components/controls/single_select.py index 232e45f0..6136db61 100644 --- a/pytest_splunk_addon_ui_smartx/components/controls/single_select.py +++ b/pytest_splunk_addon_ui_smartx/components/controls/single_select.py @@ -123,7 +123,7 @@ def search_get_list(self, value): """ search with the singleselect input and return the list :param value: string value to search - :return list of values + :return: list of values """ if self.searchable: @@ -159,7 +159,7 @@ def _list_visible_values(self, open_dropdown=True): """ Gets a list of values which are visible. Used while filtering :param open_dropdown: Whether the dropdown should be opened - :return List of the values that are visible + :return: List of the values that are visible """ if open_dropdown: self.root.click() @@ -234,7 +234,7 @@ def cancel_selected_value(self): def list_of_values(self): """ Gets the list of value from the Single Select - :return list of options avaialble within the single select + :return: list of options avaialble within the single select """ selected_val = self.get_value() self.root.click() @@ -276,7 +276,7 @@ def list_of_values(self): def get_single_value(self): """ - Return one value from Single Select + :return: one value from Single Select """ selected_val = self.get_value() From 5cedf0e88adfe232d5e9cb518ef2081630151ef8 Mon Sep 17 00:00:00 2001 From: Viktor Tsvetkov <142901247+vtsvetkov-splunk@users.noreply.github.com> Date: Wed, 25 Oct 2023 21:25:56 +0200 Subject: [PATCH 5/6] extra prints --- .../components/controls/single_select.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pytest_splunk_addon_ui_smartx/components/controls/single_select.py b/pytest_splunk_addon_ui_smartx/components/controls/single_select.py index 6136db61..3d6d416d 100644 --- a/pytest_splunk_addon_ui_smartx/components/controls/single_select.py +++ b/pytest_splunk_addon_ui_smartx/components/controls/single_select.py @@ -151,8 +151,6 @@ def search_get_list(self, value): self.input.send_keys(Keys.ESCAPE) self.wait_for("root") - print("searched_values") - print(searched_values) return searched_values def _list_visible_values(self, open_dropdown=True): From f6513ec26101cf1105270e2cf98cc7dc0dece060 Mon Sep 17 00:00:00 2001 From: Viktor Tsvetkov <142901247+vtsvetkov-splunk@users.noreply.github.com> Date: Fri, 27 Oct 2023 09:40:37 +0200 Subject: [PATCH 6/6] move popover_id declaration upper --- .../components/controls/single_select.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/pytest_splunk_addon_ui_smartx/components/controls/single_select.py b/pytest_splunk_addon_ui_smartx/components/controls/single_select.py index 3d6d416d..6b46a1b5 100644 --- a/pytest_splunk_addon_ui_smartx/components/controls/single_select.py +++ b/pytest_splunk_addon_ui_smartx/components/controls/single_select.py @@ -22,7 +22,7 @@ class SingleSelect(BaseControl): """ - Entity-Component: SingleSelect + Entity-Component: Select, ComboBox A dropdown which can select only one value """ @@ -96,7 +96,7 @@ def search(self, value, open_dropdown=True): """ search with the singleselect input :param value: string value to search - :assert Asserts whether the single select is seachable + :assert Asserts whether the single select is searchable """ assert self.searchable, "Can not search, as the Singleselect is not searchable" if open_dropdown: @@ -123,7 +123,7 @@ def search_get_list(self, value): """ search with the singleselect input and return the list :param value: string value to search - :return: list of values + :return: a list of values """ if self.searchable: @@ -161,13 +161,13 @@ def _list_visible_values(self, open_dropdown=True): """ if open_dropdown: self.root.click() + + popover_id = "#" + self.root.get_attribute("data-test-popover-id") if self.allow_new_values: - popover_id = "#" + self.root.get_attribute("data-test-popover-id") self.elements.update( {"values": Selector(select=popover_id + ' [data-test="option"]')} ) else: - popover_id = "#" + self.root.get_attribute("data-test-popover-id") self.elements.update( { "values": Selector( @@ -280,6 +280,7 @@ def get_single_value(self): self.wait_to_be_clickable("root") self.root.click() + popover_id = "#" + self.root.get_attribute("data-test-popover-id") if self.allow_new_values: if self.searchable: self.elements.update( @@ -289,7 +290,6 @@ def get_single_value(self): ) } ) - popover_id = "#" + self.root.get_attribute("data-test-popover-id") self.elements.update( { "values": Selector( @@ -299,7 +299,6 @@ def get_single_value(self): } ) else: - popover_id = "#" + self.root.get_attribute("data-test-popover-id") if self.searchable: self.elements.update( {"input": Selector(select=popover_id + ' [data-test="textbox"]')} @@ -311,7 +310,7 @@ def get_single_value(self): single_element = self.get_element("values") if selected_val and not self.allow_new_values: - # as the dropdown is already open we dont try to open it + # as the dropdown is already open, we don't try to open it self.select(selected_val, open_dropdown=False) elif self.searchable: self.input.send_keys(Keys.ESCAPE)