-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpage.py
87 lines (61 loc) · 2.89 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
""" Modified from docs boilerplate code https://selenium-python.readthedocs.io/page-objects.html """
import re
from selenium.webdriver.common.by import By
class BasePage(object):
"""Base class to initialize the base page that will be called from all pages"""
def __init__(self, driver):
self.driver = driver
def is_title_match(self):
"""Verifies that the supplied text appears in page title"""
text = ""
return text in self.driver.title
class MainPage(BasePage):
"""Home page action methods come here. I.e. Python.org"""
#Declares a variable that will contain the retrieved text
# search_text_element = SearchTextElement()
def is_title_match(self):
"""Verifies that the hardcoded text "Narrative Science" appears in page title"""
super().is_title_match()
text="Narrative Science"
return text in self.driver.title
def accept_cookie_policy(self):
""" Gets the cookie banner out of our way. """
element = self.driver.find_element(*MainPageLocators.COOKIES_OK_BUTTON)
element.click()
def navigate_to(self, link_text):
""" There is more than one link to the desired destination, could use first or a specific.
Tried to make dynamic naming; didn't work and didn't want to spend
time troubleshooting before test was complete.
"""
# link_text = f"NAV_{link_text.upper().replace(' ', '_')}"
# locator = f"*MainPageLocators.{link_text}"
# element = self.driver.find_element(locator)
if link_text == 'About Us':
element = self.driver.find_element(*MainPageLocators.NAV_ABOUT_US)
element.click()
class AboutUsPage(BasePage):
""" About Us page action methods come here """
def is_title_match(self):
"""Verifies that the hardcoded text "About Us" appears in page title"""
super().is_title_match()
text="About Us"
return text in self.driver.title
def has_specific_patents(self, patents):
LINK_FILL = r'Patent <a href[=\s\w\.\"\-\?\:/,&;%]+>'
for patent in patents:
if not re.search(f"{LINK_FILL}{patent}", self.driver.page_source):
return False
return True
################################################################################
# 6.4. Locators
# One of the practices is to separate the locator strings from the place where they are being used.
# In this example, locators of the same page belong to same class.
# The locators.py will look like this:
# from selenium.webdriver.common.by import By
class MainPageLocators(object):
"""A class for main page locators. All main page locators should come here"""
COOKIES_OK_BUTTON = (By.ID, 'catapultCookie')
NAV_ABOUT_US = (By.LINK_TEXT, 'About Us')
class AboutUsPageLocators(object):
"""A class for About Us locators. All About Us locators should come here"""
pass