-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpage.py
More file actions
130 lines (101 loc) · 4.68 KB
/
page.py
File metadata and controls
130 lines (101 loc) · 4.68 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
import logging
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
from locators import *
logger = logging.getLogger(__name__)
filehandler = logging.FileHandler('logfile.log')
formatter = logging.Formatter("%(asctime)s : %(levelname)s : %(name)s : %(message)s")
filehandler.setFormatter(formatter)
logger.addHandler(filehandler)
logger.setLevel(logging.INFO)
class BasePage:
def __init__(self, driver):
self.driver = driver
self.base_url = "https://sbis.ru/"
def find_element(self, locator, time=10):
logger.info(f"Finding element by locator: {locator}")
return WebDriverWait(self.driver, time).until(
EC.visibility_of_element_located(locator),
message=f"Can't find element by locator {locator}")
def find_elements(self, locator, time=10):
logger.info(f"Finding elements by locator: {locator}")
return WebDriverWait(self.driver, time).until(
EC.visibility_of_all_elements_located(locator),
message=f"Can't find elements by locator {locator}")
def go_to_site(self):
logger.info(f"Navigating to site: {self.base_url}")
return self.driver.get(self.base_url)
def go_to_new_tab(self):
try:
self.driver.switch_to.window(self.driver.window_handles[-1])
except IndexError:
raise Exception("No new tab found to switch to")
def get_page_title(self):
logger.info(f"Getting the page title: {self.driver.title}")
return self.driver.title
def get_page_url(self):
logger.info(f"Getting the page URL: {self.driver.current_url}")
return self.driver.current_url
class SbisPage(BasePage):
def click_contacts(self):
logger.info("Clicking on the Contacts link")
self.find_element(SbisPageLocators.CONTACTS, time=5).click()
return SbisContactsPage(self.driver)
class SbisContactsPage(BasePage):
def click_banner(self):
logger.info("Clicking on the banner")
self.find_element(SbisContactsPageLocators.BANNER, time=5).click()
self.go_to_new_tab()
return TensorPage(self.driver)
def get_region(self):
logger.info("Getting the region title")
region_title = self.find_element(SbisContactsPageLocators.REGION).text
logger.info(f"Got the region title: {region_title}")
return region_title
def check_region(self, value):
logger.info(f"Comparing region title with expected: {value}")
try:
return WebDriverWait(self.driver, 3).until(
EC.text_to_be_present_in_element(SbisContactsPageLocators.REGION, value))
except TimeoutException:
return False
def click_region_chooser(self):
logger.info("Clicking on the region chooser")
self.find_element(SbisContactsPageLocators.REGION).click()
def choose_41_region(self):
logger.info("Choosing region 41")
try:
return WebDriverWait(self.driver, 3).until(
EC.element_to_be_clickable(SbisContactsPageLocators.REGION_41)).click()
except TimeoutException:
return False
def get_region_partner_name(self):
logger.info("Getting the region partner")
name = self.find_element(SbisContactsPageLocators.PARTNER).text
logger.info(f"Got the region partner: {name}")
return name
class TensorPage(BasePage):
def get_card(self):
logger.info("Getting the card on the tensor.ru")
return self.find_element(TensorPageLocators.CARD_CONTAINER)
def get_card_title(self, element):
logger.info("Getting the card title")
return element.find_element(*TensorPageLocators.CARD_TITLE).text
def navigate_to_about(self, element):
logger.info("Navigating to the tensor.ru/about")
about_link = element.find_element(*TensorPageLocators.CARD_ABOUT)
logger.info(f"About page URL: {about_link.get_attribute('href')}")
about_link.click()
return TensorAboutPage(self.driver)
class TensorAboutPage(BasePage):
def get_block(self):
logger.info("Checking the block on the tensor.ru/about")
return self.find_element(TensorAboutPageLocators.BLOCK_CONTAINER)
def get_block_title(self, element):
logger.info("Getting the block title")
return element.find_element(*TensorAboutPageLocators.BLOCK_TITLE).text
def get_block_images(self, element):
logger.info("Checking image sizes in the block")
grid = element.find_element(*TensorAboutPageLocators.BLOCK_GRID)
return grid.find_elements(*TensorAboutPageLocators.BLOCK_IMAGES)