Skip to content

dropdown

Dropdown(browser, container)

Bases: BaseComponent

Component: Dropdown Base class of Input & Configuration table

Parameters:

Name Type Description Default
browser

The selenium webdriver

required
container

Container in which the table is located. Of type dictionary: {“by”:…, “select”:…}

required
Source code in pytest_splunk_addon_ui_smartx/components/dropdown.py
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
def __init__(self, browser, container):
    """
    :param browser: The selenium webdriver
    :param container: Container in which the table is located. Of type dictionary: {"by":..., "select":...}
    """
    super().__init__(browser, container)
    self.elements.update(
        {
            "root": Selector(select=container.select),
            "currunt_value": Selector(
                select=container.select
                + ' [data-test="select"] [data-test="label"]'
            ),
            "type_dropdown": Selector(select=container.select),
        }
    )

get_input_type_list()

Returns a generator list for the input types available in the add input dropdown :return: Returns Generator list of values

Source code in pytest_splunk_addon_ui_smartx/components/dropdown.py
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
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.wait_to_be_clickable("root")
    self.root.click()
    popover_id = "#" + self.root.get_attribute("data-test-popover-id")
    self.elements.update(
        {
            "type_filter_list": Selector(
                select=popover_id + ' [data-test="label"]'
            ),
        }
    )
    return [each.text.strip() for each in self.get_elements("type_filter_list")]

get_inputs_list()

Returns a generator list for the options available in the add input dropdown :return: Returns Generator list of values

Source code in pytest_splunk_addon_ui_smartx/components/dropdown.py
161
162
163
164
165
166
167
168
169
170
171
172
173
174
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.wait_to_be_clickable("root")
    self.root.click()
    popover_id = "#" + self.root.get_attribute("data-test-popover-id")
    self.elements.update(
        {
            "type_list": Selector(select=popover_id + ' [data-test="item"]'),
        }
    )
    return [each.text.strip() for each in self.get_elements("type_list")]

get_pagination_list()

Returns a generator list for the pagination text available in the add input dropdown :return: Returns Generator list of values

Source code in pytest_splunk_addon_ui_smartx/components/dropdown.py
176
177
178
179
180
181
182
183
184
185
186
187
188
189
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.wait_to_be_clickable("root")
    self.root.click()
    popover_id = "#" + self.root.get_attribute("data-test-popover-id")
    self.elements.update(
        {
            "page_list": Selector(select=popover_id + ' [data-test="label"]'),
        }
    )
    return [each.text.strip() for each in self.get_elements("page_list")]

get_value()

Returns the current value for the dropdown :return: Str The current value for the dropdown

Source code in pytest_splunk_addon_ui_smartx/components/dropdown.py
66
67
68
69
70
71
def get_value(self):
    """
    Returns the current value for the dropdown
        :return: Str The current value for the dropdown
    """
    return self.currunt_value.text.strip()

select(value)

Selects the value we want from the type list :param value: The value in which we want to select :return: Returns True if successful, otherwise raises an error

Source code in pytest_splunk_addon_ui_smartx/components/dropdown.py
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
def select(self, value):
    """
    Selects the value we want from the type list
        :param value: The value in which we want to select
        :return: Returns True if successful, otherwise raises an error
    """
    self.wait_to_be_clickable("root")
    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=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()
            return True
    else:
        raise ValueError("{} not found in select list".format(value))

select_input_type(value, open_dropdown=True)

Selects the input type option that the user specifies in value :param value: The value in which we want to select :param open_dropdown: Whether the dropdown should be opened :return: Returns True if successful, otherwise raises an error

Source code in pytest_splunk_addon_ui_smartx/components/dropdown.py
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
def select_input_type(self, value, open_dropdown=True):
    """
    Selects the input type option that the user specifies in value
        :param value: The value in which we want to select
        :param open_dropdown: Whether the dropdown should be opened
        :return: Returns True if successful, otherwise raises an error
    """
    if open_dropdown:
        self.wait_to_be_clickable("root")
        self.root.click()
    popover_id = "#" + self.root.get_attribute("data-test-popover-id")
    self.elements.update(
        {
            "type_filter_list": Selector(
                select=popover_id + ' [data-test="label"]'
            ),
        }
    )
    for each in self.get_elements("type_filter_list"):
        if each.text.strip().lower() == value.lower():
            each.click()
            return True
    else:
        raise ValueError("{} not found in select list".format(value))

select_nested(values)

Selects the values we want from the type list in defined order :param values: Dropdown values list in order we want to select :return: Returns True if successful, otherwise raises an error

Source code in pytest_splunk_addon_ui_smartx/components/dropdown.py
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
def select_nested(self, values: list):
    """
    Selects the values we want from the type list in defined order
        :param values: Dropdown values list in order we want to select
        :return: Returns True if successful, otherwise raises an error
    """
    if not isinstance(values, list):
        raise ValueError("{} has to be of type list".format(values))
    self.wait_to_be_clickable("root")
    self.root.click()
    popoverid = "#" + self.root.get_attribute("data-test-popover-id")
    dropdown_selector = ' [data-test="item"] [data-test="label"]'
    for value in values:
        found = False
        self.elements.update(
            {"dropdown_options": Selector(select=popoverid + dropdown_selector)}
        )
        for each in self.get_elements("dropdown_options"):
            if each.text.strip().lower() == value.lower():
                found = True
                try:
                    each.click()
                except ElementClickInterceptedException:
                    self.hover_over_element("root")  # avoid tooltip interception
                    each.click()
                time.sleep(
                    1
                )  # sleep here prevents broken animation resulting in unclicable button
                break
        if not found:
            raise ValueError(
                f"{value} not found in select list. Values found {[_.text.strip().lower() for _ in self.get_elements('dropdown_options')]}"
            )
    return True

select_page_option(value)

Selects the page option that the user specifies in value :param value: The value in which we want to select :return: Returns True if successful, otherwise raises an error

Source code in pytest_splunk_addon_ui_smartx/components/dropdown.py
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
def select_page_option(self, value):
    """
    Selects the page option that the user specifies in value
        :param value: The value in which we want to select
        :return: Returns True if successful, otherwise raises an error
    """
    self.wait_to_be_clickable("root")
    self.root.click()
    popover_id = "#" + self.root.get_attribute("data-test-popover-id")
    self.elements.update(
        {
            "page_list": Selector(select=popover_id + ' [data-test="label"]'),
        }
    )
    for each in self.get_elements("page_list"):
        if each.text.strip().lower() == value.lower():
            each.click()
            return True
    else:
        raise ValueError("{} not found in select list".format(value))