Skip to content

Commit a6288c6

Browse files
fix(popover): fix selectors for popover (#400)
* fix(multiselect): fix deselect function * fix * precommit * comment typo * extra prints * move popover_id declaration upper
1 parent 210ce72 commit a6288c6

File tree

4 files changed

+137
-160
lines changed

4 files changed

+137
-160
lines changed

pytest_splunk_addon_ui_smartx/components/controls/multi_select.py

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
import time
1716

1817
from selenium.common.exceptions import ElementClickInterceptedException
19-
from selenium.webdriver.common.by import By
18+
2019
from selenium.webdriver.common.keys import Keys
2120

2221
from ..base_component import Selector
@@ -26,7 +25,6 @@
2625
class MultiSelect(BaseControl):
2726
"""
2827
Entity-Component: Multiselect
29-
Select Javascript framework: select2
3028
A dropdown which can select more than one values
3129
"""
3230

@@ -37,20 +35,21 @@ def __init__(self, browser, container):
3735
"""
3836
super().__init__(browser, container)
3937

38+
root_selector = container.select + ' [data-test="multiselect"]'
39+
self.elements.update({"root": Selector(select=root_selector)})
40+
4041
self.elements.update(
4142
{
42-
"internal_container": Selector(
43-
select=container.select + ' [role="listbox"]'
44-
),
45-
"dropdown": Selector(select=container.select + ' [role="listbox"]'),
4643
"selected": Selector(
47-
select=container.select
48-
+ ' button[data-test="selected-option"][role="option"]'
44+
select=root_selector + ' [data-test="selected-option"]'
4945
),
46+
"""
47+
Click on selected element deselects it
48+
"""
5049
"deselect": Selector(
51-
select=container.select + ' [data-test="crossmark"]'
50+
select=root_selector + ' [data-test="selected-option"]'
5251
),
53-
"input": Selector(select=container.select + ' [data-test="textbox"]'),
52+
"input": Selector(select=root_selector + ' [data-test="textbox"]'),
5453
}
5554
)
5655

@@ -71,13 +70,12 @@ def search_get_list(self, value):
7170
"""
7271
search with the multiselect input and return the list
7372
:param value: string value to search
74-
:returns: list of values
73+
:return: list of values
7574
"""
7675
self.search(value)
7776
self.wait_for_search_list()
7877
searched_values = list(self._list_visible_values())
7978
self.input.send_keys(Keys.ESCAPE)
80-
self.wait_for("container")
8179
return searched_values
8280

8381
def select(self, value):
@@ -87,21 +85,18 @@ def select(self, value):
8785
:return: Bool returns true if selection was successful, else raises an exception
8886
"""
8987
try:
90-
time.sleep(1)
9188
try:
9289
self.input.click()
9390
except ElementClickInterceptedException:
9491
self.label_text.click()
95-
time.sleep(1)
9692
self.input.click()
97-
time.sleep(1)
98-
popoverid = "#" + self.dropdown.get_attribute("data-test-popover-id")
9993

10094
except:
10195
raise Exception("dropdown not found")
10296

97+
popover_id = "#" + self.root.get_attribute("data-test-popover-id")
10398
self.elements.update(
104-
{"values": Selector(select=popoverid + ' [data-test="option"]')}
99+
{"values": Selector(select=popover_id + ' [data-test="option"]')}
105100
)
106101
for each in self.get_elements("values"):
107102
if each.text.strip().lower() == value.lower():
@@ -119,11 +114,8 @@ def deselect(self, value):
119114
"""
120115
for each in self.get_child_elements("selected"):
121116
if each.text.strip().lower() == value.lower():
122-
time.sleep(1)
123-
each.find_element(
124-
*list(self.elements["deselect"]._asdict().values())
125-
).click()
126-
self.wait_for("internal_container")
117+
each.click()
118+
self.wait_for("root")
127119
return True
128120
else:
129121
raise ValueError("{} not found in select list".format(value))
@@ -138,24 +130,23 @@ def deselect_all(self):
138130
def get_values(self):
139131
"""
140132
get list selected values
141-
:returns: List of values selected within the multi-select
133+
:return: List of values selected within the multi-select
142134
"""
143135
return [each.text.strip() for each in self.get_child_elements("selected")]
144136

145137
def list_of_values(self):
146138
"""
147139
Get list of possible values to select from dropdown
148-
:returns: List of options within the multi-select dropdown
140+
:return: List of options within the multi-select dropdown
149141
"""
150-
self.wait_for("internal_container")
151-
time.sleep(1)
142+
self.wait_for("root")
152143
list_of_values = []
153144
self.input.click()
154-
popoverid = "#" + self.dropdown.get_attribute("data-test-popover-id")
145+
popover_id = "#" + self.root.get_attribute("data-test-popover-id")
155146
self.elements.update(
156147
{
157148
"values": Selector(
158-
select=popoverid + ' [data-test="option"] [data-test="label"]'
149+
select=popover_id + ' [data-test="option"] [data-test="label"]'
159150
)
160151
}
161152
)
@@ -172,14 +163,14 @@ def get_list_count(self):
172163
def _list_visible_values(self):
173164
"""
174165
Get list of values which are visible. Used while filtering
175-
:returns: List of visible options within the multi-select dropdown
166+
:return: List of visible options within the multi-select dropdown
176167
"""
177168
self.input.click()
178-
popoverid = "#" + self.dropdown.get_attribute("data-test-popover-id")
169+
popover_id = "#" + self.root.get_attribute("data-test-popover-id")
179170
self.elements.update(
180171
{
181172
"values": Selector(
182-
select=popoverid
173+
select=popover_id
183174
+ ' [data-test="option"]:not([data-test-selected="true"]) [data-test="label"]'
184175
)
185176
}

pytest_splunk_addon_ui_smartx/components/controls/oauth_select.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,13 @@
1414
# limitations under the License.
1515
#
1616

17-
import time
18-
19-
from selenium.webdriver.common.by import By
20-
from selenium.webdriver.common.keys import Keys
21-
2217
from ..base_component import Selector
2318
from .base_control import BaseControl
2419

2520

2621
class OAuthSelect(BaseControl):
2722
"""
28-
Entity-Component: OAuthSelect
23+
Entity-Component: Select
2924
3025
OAuthSelect Javascript framework: OAuthSelect
3126
@@ -41,8 +36,8 @@ def __init__(self, browser, container, searchable=True):
4136
super().__init__(browser, container)
4237
self.elements.update(
4338
{
39+
"root": Selector(select=container.select + ' [data-test="select"]'),
4440
"values": Selector(select=container.select + ' [data-test="option"]'),
45-
"dropdown": Selector(select=container.select + " .dropdownBox"),
4641
}
4742
)
4843

@@ -53,12 +48,12 @@ def select(self, value):
5348
:return: Bool if successful in selection, else raises an error
5449
"""
5550

56-
self.dropdown.click()
57-
popoverid = "#" + self.dropdown.get_attribute("data-test-popover-id")
51+
self.root.click()
52+
popover_id = "#" + self.root.get_attribute("data-test-popover-id")
5853
self.elements.update(
5954
{
6055
"values": Selector(
61-
select=popoverid
56+
select=popover_id
6257
+ ' [data-test="option"]:not([data-test-selected="true"]) [data-test="label"]'
6358
)
6459
}
@@ -76,8 +71,7 @@ def get_value(self):
7671
:return: Str The elected value within the dropdown, else returns blank
7772
"""
7873
try:
79-
element = self.get_element("dropdown")
80-
return element.get_attribute("data-test-value")
74+
return self.root.get_attribute("data-test-value")
8175
except:
8276
return ""
8377

@@ -87,12 +81,12 @@ def list_of_values(self):
8781
:returns: List of options from the single select
8882
"""
8983
selected_val = self.get_value()
90-
self.container.click()
84+
self.root.click()
9185
first_element = None
9286
list_of_values = []
93-
popoverid = "#" + self.dropdown.get_attribute("data-test-popover-id")
87+
popover_id = "#" + self.root.get_attribute("data-test-popover-id")
9488
self.elements.update(
95-
{"values": Selector(select=popoverid + ' [data-test="option"]')}
89+
{"values": Selector(select=popover_id + ' [data-test="option"]')}
9690
)
9791
for each in self.get_elements("values"):
9892
list_of_values.append(each.text.strip())

0 commit comments

Comments
 (0)