-
Notifications
You must be signed in to change notification settings - Fork 199
/
Copy pathexperiment_overview.py
217 lines (183 loc) · 7.65 KB
/
experiment_overview.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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
100
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
import random
import string
from selenium.webdriver.common.by import By
from pages.base import Base
class ExperimentOverview(Base):
_root_locator = (By.CSS_SELECTOR, ".form-group")
_experiment_feature_bugzilla_url_locator = (
By.CSS_SELECTOR,
"#id_feature_bugzilla_url",
)
_engineering_owner_locator = (By.CSS_SELECTOR, "#id_engineering_owner")
_experiment_owner_locator = (By.CSS_SELECTOR, "#id_owner > option")
_analysis_owner_locator = (
By.CSS_SELECTOR,
"#id_analysis_owner > option",
)
_experiment_public_description_locator = (
By.CSS_SELECTOR,
"#id_public_description",
)
_experiment_public_description_locator = (By.CSS_SELECTOR, "#id_public_description")
_experiment_public_name_locator = (By.CSS_SELECTOR, "#id_public_name")
_experiment_related_experiments_locator = (
By.CSS_SELECTOR,
".filter-option-inner-inner",
)
_experiment_related_work_url_locator = (By.CSS_SELECTOR, "#id_related_work")
_experiment_type_locator = (By.CSS_SELECTOR, "#id_type > option")
_related_experiments_dropdown = (By.CSS_SELECTOR, "ul.dropdown-menu > li > a")
_page_wait_locator = (By.CSS_SELECTOR, "body.page-edit-overview")
_name_locator = (By.CSS_SELECTOR, "#id_name")
_short_description_locator = (By.CSS_SELECTOR, "#id_short_description")
_ds_issue_url_locator = (
By.CSS_SELECTOR,
"#id_data_science_issue_url",
)
_overview_name_locator = (By.CSS_SELECTOR, "#id_name")
_overview_description_locator = (By.CSS_SELECTOR, "#id_short_description")
_overview_ds_issue_url_locator = (By.CSS_SELECTOR, "#id_data_science_issue_url")
_overview_data_science_owner_locator = (By.CSS_SELECTOR, "#id_analysis_owner")
_save_btn_locator = (By.CSS_SELECTOR, "#save-btn")
_save_and_continue_btn_locator = (By.CSS_SELECTOR, "#save-and-continue-btn")
@property
def experiment_type(self):
options = self.find_elements(*self._experiment_type_locator)
for item in options:
if item.get_property("selected"):
return item.get_attribute("value")
@experiment_type.setter
def experiment_type(self, exp_type=None):
types = self.find_elements(*self._experiment_type_locator)
for option in types:
if exp_type in option.text.replace("-", "").lower():
option.click()
@property
def name(self):
element = self.find_element(*self._name_locator)
return element.get_attribute("value")
@name.setter
def name(self, text=None):
element = self.find_element(*self._name_locator)
random_chars = "".join(
random.choices(string.ascii_uppercase + string.digits, k=6)
)
element.send_keys(f"{text}-{random_chars}")
return
@property
def short_description(self):
element = self.find_element(*self._short_description_locator)
return element.get_attribute("value")
@short_description.setter
def short_description(self, text=None):
element = self.find_element(*self._short_description_locator)
random_chars = "".join(
random.choices(string.ascii_uppercase + string.digits, k=6)
)
element.send_keys(f"{text}-{random_chars}")
return
@property
def ds_issue_url(self):
element = self.find_element(*self._ds_issue_url_locator)
return element.get_attribute("value")
@ds_issue_url.setter
def ds_issue_url(self, text=None):
element = self.find_element(*self._ds_issue_url_locator)
random_chars = "".join(random.choices(string.digits, k=6))
element.send_keys(f"{text}{random_chars}")
return
@property
def experiment_owner(self):
options = self.find_elements(*self._experiment_owner_locator)
for item in options:
if item.get_property("selected"):
return item.text
@experiment_owner.setter
def experiment_owner(self, owner=None):
owners = self.find_elements(*self._experiment_owner_locator)
for item in owners:
if owner in item.text:
item.click()
return
raise ValueError("Owner selection not found")
@property
def analysis_owner(self):
options = self.find_elements(*self._analysis_owner_locator)
for item in options:
if item.get_property("selected"):
return item.text
@analysis_owner.setter
def analysis_owner(self, owner=None):
owners = self.find_elements(*self._analysis_owner_locator)
for item in owners:
if owner in item.text:
item.click()
return
raise (Exception, "Owner selection not found")
@property
def engineering_owner(self):
element = self.find_element(*self._engineering_owner_locator)
return element.get_attribute("value")
@engineering_owner.setter
def engineering_owner(self, name=None):
element = self.find_element(*self._engineering_owner_locator)
element.send_keys(name)
@property
def public_name(self):
element = self.find_element(*self._experiment_public_name_locator)
return element.get_attribute("value")
@public_name.setter
def public_name(self, text=None):
element = self.find_element(*self._experiment_public_name_locator)
element.send_keys(text)
@property
def public_description(self):
element = self.find_element(*self._experiment_public_description_locator)
return element.get_attribute("value")
@public_description.setter
def public_description(self, text=None):
element = self.find_element(*self._experiment_public_description_locator)
element.send_keys(text)
@property
def feature_bugzilla_url(self):
element = self.find_element(*self._experiment_feature_bugzilla_url_locator)
return element.get_attribute("value")
@feature_bugzilla_url.setter
def feature_bugzilla_url(self, text=None):
element = self.find_element(*self._experiment_feature_bugzilla_url_locator)
element.send_keys(text)
@property
def related_work_urls(self):
element = self.find_element(*self._experiment_related_work_url_locator)
return element.get_attribute("value")
@related_work_urls.setter
def related_work_urls(self, text=None):
element = self.find_element(*self._experiment_related_work_url_locator)
element.send_keys(text)
@property
def related_experiments(self):
element = self.find_element(*self._experiment_related_experiments_locator)
return element.text
@related_experiments.setter
def related_experiments(self, experiment=None):
dropdown = self.find_element(By.CSS_SELECTOR, ".dropdown-toggle")
if type(experiment) is int:
dropdown.click()
elements = self.find_elements(*self._related_experiments_dropdown)
elements[experiment].click()
return
for item in elements:
if experiment in item.text:
item.click()
return
raise ValueError("Owner selection not found")
def save_btn(self):
self.find_element(*self._save_btn_locator).click()
from pages.experiment_detail import DetailPage
return DetailPage(self.driver, self.base_url).wait_for_page_to_load()
def save_and_continue_btn(self):
self.find_element(*self._save_and_continue_btn_locator).click()
from pages.experiment_timeline_and_population import TimelineAndPopulationPage
return TimelineAndPopulationPage(
self.driver, self.base_url
).wait_for_page_to_load()