forked from VenkateshDoijode/selenium_with_python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasepage.py
More file actions
190 lines (157 loc) · 6.31 KB
/
Copy pathbasepage.py
File metadata and controls
190 lines (157 loc) · 6.31 KB
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
"""
@package base
Base Page class implementation
It implements methods which are common to all the pages throughout the application
This class needs to be inherited by all the page classes
This should not be used by creating object instances
Example:
Class PageClassName(BasePage)
"""
from abc import abstractmethod
from base.selenium_driver import SeleniumDriver
from traceback import print_stack
from utilities.util import Util
class BasePage(SeleniumDriver):
def __init__(self, driver):
"""
Inits BasePage class
Required Parameters:
driver: WebDriver Object
Optional Parameters:
None
Returns:
None
"""
super(BasePage, self).__init__(driver)
self._validate_page(driver)
self.driver = driver
self.util = Util()
self.bkend = BEConnection()
def verifyFlashMessage(self, textToVerify, timeout=6):
"""
Validate the flash message after completing an action
Required Parameters:
textToVerify: Text on the flash message that needs to be verified
Optional Parameters:
None
Returns:
Boolean
"""
try:
flashMessageElement = self.waitForElement(locator=".nmbl-flash-message-content", locatorType="css",
info="flash message", timeout=timeout)
if flashMessageElement is not None:
elementText = self.getText(flashMessageElement,
"Getting text on flash message")
# elementText = self.getText(self.getElementByClassName("flash-message"),
# "Getting text on flash message")
result = self.util.verifyTextContains(elementText, textToVerify)
# flashMessageClose = self.getElementByClassName("flash-message-close")
flashMessageClose = self.getElementByCss(".nmbl-flash-message-close")
self.clickElement(flashMessageClose, "Flash message 'X' close button", 1)
return result
else:
# If element does not show up before timeout, return False
return False
except:
self.log.error("Failed to get text on flash message")
print_stack()
return False
def verifyModalMessage(self, textToVerify, textLocator, buttonToClickLocator, buttonInfo=""):
"""
Validate the message on the modal and click Ok/Close button to close the modal
Required Parameters:
textToVerify: Text on the modal that needs to be verified
textLocator: Locator of the message
buttonToClickLocator: Locator of the button to click on modal
Optional Parameters:
None
Returns:
Boolean
"""
try:
result = False
elementPresent = self.isElementPresent(textLocator)
if elementPresent:
elementText = self.getText(self.getElement(textLocator), "Getting text on modal")
result = self.util.verifyTextContains(elementText, textToVerify)
if not result:
self.util.screenShot("FAIL-Modal-Message-Verification")
self.clickElement(self.getElement(buttonToClickLocator), buttonInfo)
return result
except:
self.log.error("Failed to get text on modal")
print_stack()
return False
def verifyModalConfirmation(self, buttonLocator, info, locatorType="id"):
"""
Verify the confirmation modal is present and click the 'Confirmation' button
'Confirmation' button can be OK/Close/Delete
Required Parameters:
buttonLocator: Locator of the button on confirmation modal
info: Information about the button, usually text on the button
Optional Parameters:
locatorType: Type of the locator(id(default), xpath, css, className, linkText)
Returns:
Boolean
"""
try:
elementPresent = self.isElementPresent(buttonLocator, locatorType)
if elementPresent:
return self.clickElement(self.getElement(buttonLocator), info)
return False
except:
self.log.error("Failed to find button on confirmation modal")
print_stack()
return False
def verifyFieldErrorMessage(self, locator, textToVerify, locatorType="id"):
"""
Validate the flash message after completing an action
Required Parameters:
locator: Locator of the error message
textToVerify: Text on the flash message that needs to be verified
Optional Parameters:
locatorType: Type of the locator, default is 'id'
Returns:
Boolean
"""
try:
elementPresent = self.isElementPresent(locator, locatorType)
if elementPresent:
elementText = self.getText(self.getElement(locator),
"Getting text on field error message")
result = self.util.verifyTextContains(elementText, textToVerify)
return result
return False
except:
self.log.error("Failed to get text on field error message")
print_stack()
return False
def verifyPageTitle(self, titleToVerify):
"""
Verify the page Title
Required Parameters:
titleToVerify: Title on the page that needs to be verified
Optional Parameters:
None
Returns:
Boolean
"""
try:
actualTitle = self.getBrowserTitle()
return self.util.verifyTextContains(actualTitle, titleToVerify)
except:
self.log.error("Failed to get page title")
print_stack()
return False
@abstractmethod
def _validate_page(self, driver):
pass
""" Regions define functionality available through all page objects """
# @property
# def search(self):
# from search import SearchRegion
# return SearchRegion(self.driver)
class InvalidPageException(Exception):
""" Throw this exception when you don't find the correct page """
pass