-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpage.py
192 lines (153 loc) · 6.63 KB
/
page.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
from locators import SurveyPageLocators as SurveyLocators
from selenium.webdriver.support.ui import Select
import random
class BasePage(object):
"""Base class to initialize the base page to be called from all pages"""
def __init__(self, driver):
self.driver = driver
class SurveyPage(BasePage):
"""Survey page action methods come here"""
def is_title_matches(self, title):
"""Verifies that the title text appears in page title"""
return title in self.driver.title
def description_id_exists(self):
if self.driver.find_element(*SurveyLocators.DESCRIPTION):
return True
return False
def survey_form_id_exists(self):
if self.driver.find_element(*SurveyLocators.SURVEY_FORM):
return True
return False
def h1_title_id_exists(self):
element = self.driver.find_elements(*SurveyLocators.HEADER)
if element:
return True
return False
def name_input_and_label_coupling_exists(self):
input_element = self.driver.find_elements(*SurveyLocators.NAME_INPUT)
label_element = self.driver.find_elements(*SurveyLocators.NAME_LABEL)
if input_element and label_element:
return True
return False
def email_input_and_label_coupling_exists(self):
input_element = self.driver.find_elements(*SurveyLocators.EMAIL_INPUT)
label_element = self.driver.find_elements(*SurveyLocators.EMAIL_LABEL)
if input_element and label_element:
return True
return False
def age_input_and_label_coupling_exists(self):
input_element = self.driver.find_elements(*SurveyLocators.AGE_INPUT)
label_element = self.driver.find_elements(*SurveyLocators.AGE_LABEL)
if input_element and label_element:
return True
return False
def radio_input_with_name_attribute_exists(self):
element = self.driver.find_elements(*SurveyLocators.RADIO_OPTIONS)
assert len(element) > 1
return all(item.get_attribute("value") for item in element)
def select_tag_with_dropdown_id_exists(self):
element = self.driver.find_elements(*SurveyLocators.SELECT_DROPDOWN)
if element:
return True
return False
def checkbox_input_type_exists(self):
element = self.driver.find_elements(*SurveyLocators.CHECKBOX_INPUT)
if element:
return True
return False
def checkboxes_with_value_attribute_exist(self):
element = self.driver.find_elements(*SurveyLocators.CHECKBOX_INPUT)
assert len(element) > 1
return all(item.get_attribute("value") for item in element)
def name_input_is_required_attribute(self):
element = self.driver.find_element(*SurveyLocators.NAME_INPUT)
return "true" in element.get_attribute("required")
def email_input_is_required_attribute(self):
element = self.driver.find_element(*SurveyLocators.EMAIL_INPUT)
return "true" in element.get_attribute("required")
def insert_name(self, name):
element = self.driver.find_element(*SurveyLocators.NAME_INPUT)
element.send_keys(name)
def get_inserted_name(self):
element = self.driver.find_element(*SurveyLocators.NAME_INPUT)
return element.get_attribute("value")
def is_name_html_validation_error(self):
element = self.driver.find_element(*SurveyLocators.NAME_INPUT)
validation_message = element.get_attribute("validationMessage")
if validation_message:
return True
return False
def insert_email(self, email):
element = self.driver.find_element(*SurveyLocators.EMAIL_INPUT)
element.send_keys(email)
def get_inserted_email(self):
element = self.driver.find_element(*SurveyLocators.EMAIL_INPUT)
return element.get_attribute("value")
def is_email_html_validation_error(self):
element = self.driver.find_element(*SurveyLocators.EMAIL_INPUT)
validation_message = element.get_attribute("validationMessage")
if validation_message:
return True
return False
def insert_age(self, age):
element = self.driver.find_element(*SurveyLocators.AGE_INPUT)
element.send_keys(age)
def get_inserted_age(self):
element = self.driver.find_element(*SurveyLocators.AGE_INPUT)
return element.get_attribute("value")
def is_age_html_validation_error(self):
element = self.driver.find_element(*SurveyLocators.AGE_INPUT)
validation_message = element.get_attribute("validationMessage")
if validation_message:
return True
return False
def can_select_random_input_radio_options(self):
element = self.driver.find_elements(*SurveyLocators.RADIO_OPTIONS)
choice = random.choice(element)
choice.click()
return any(item.is_selected() for item in element)
def can_select_random_dropdown_options(self):
element = Select(
self.driver.find_element(*SurveyLocators.SELECT_DROPDOWN))
options = element.options
values = [
item.get_attribute("value")
for item in options
if item.get_attribute("value") != ''
]
value = random.choice(values) # select random value from values
element.select_by_value(value)
return value in values
def can_select_random_checkbox_options(self):
element = self.driver.find_elements(
*SurveyLocators.CHECKBOX_INPUT
)
random.choice(element).click()
random.choice(element).click()
random.choice(element).click()
return any(item.is_selected() for item in element)
def textarea_tag_exists(self):
element = self.driver.find_elements(*SurveyLocators.TEXT_AREA)
if element:
return True
return False
def can_insert_text_into_text_area(self):
element = self.driver.find_element(*SurveyLocators.TEXT_AREA)
text = "Hello, World!"
element.send_keys(text)
return text in element.get_attribute("value")
def button_tag_with_submit_id_exists(self):
element = self.driver.find_elements(*SurveyLocators.SUBMIT_BUTTON)
if element:
return True
return False
def click_submit_button(self):
"""Submits the form"""
element = self.driver.find_element(*SurveyLocators.SUBMIT_BUTTON)
element.click()
def does_flash_submission_message_exist(self):
"""Gets the text from "id='flash-message" if any"""
element = self.driver.find_element(*SurveyLocators.FLASH)
if element.text:
return True
return False