-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpage.py
93 lines (65 loc) · 3.21 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
from locators import MainPageLocators
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from time import sleep
class BasePage(object):
"""Base class to initialize the base page that will be called from all pages"""
def __init__(self, driver):
self.driver = driver
class MainPage(BasePage):
"""Home page action methods come here. I.e. fill searchbox, select drop down, click on button"""
def send_keys_to_searchbox(self, inputText):
"""Send keys to the search"""
element = self.driver.find_element(*MainPageLocators.SEARCH_BOX)
element.send_keys(inputText)
def get_value_from_searchbox(self):
return self.driver.find_element(*MainPageLocators.SEARCH_BOX).get_attribute('value')
def clear_searchbox(self):
self.driver.find_element(*MainPageLocators.SEARCH_BOX).click()
element = WebDriverWait(self.driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR , '.autocomplete-clear')))
element.click()
def get_autocomplete_error(self):
try:
self.driver.find_element(*MainPageLocators.SEARCHBOX_AUTOCOMPLETE_ERROR_MESSAGE)
return True
except Exception:
return False
def select_range_dropdown(self, inputText):
select = Select(self.driver.find_element(*MainPageLocators.RANGE_DROPDOWN))
#select.select_by_index(index)
select.select_by_visible_text(inputText)
def get_last_searched_text(self):
return self.driver.find_element(*MainPageLocators.LAST_SEARCHED_DATA).text
def select_from_dropdown(self, inputText):
select = Select(self.driver.find_element(*MainPageLocators.FROM_DROPDOWN))
select.select_by_visible_text(inputText)
def select_uptil_dropdown(self, inputText):
select = Select(self.driver.find_element(*MainPageLocators.UPTIL_DROPDOWN))
select.select_by_visible_text(inputText)
def click_on_search(self):
self.driver.find_element(*MainPageLocators.SEARCH_BUTTON).click()
sleep(1)
def set_uptil_specific_amt(self, inputText):
self.driver.find_element(*MainPageLocators.UPTIL_SPECIFIC_AMT).send_keys(inputText)
class SearchResultsPage(BasePage):
"""Search results page action methods come here"""
def if_element_exists(self, *el):
try:
self.driver.find_element(*el)
return True
except NoSuchElementException:
return False
except Exception:
return False
return True
def are_results_found(self):
return self.if_element_exists(*MainPageLocators.SEARCH_RESULT)
def are_search_results_for_minimum_values_found(self):
return self.if_element_exists(*MainPageLocators.SEARCH_RESULT_FOR_MINIMUM_VALUES)
def get_no_search_result_found_text(self):
return self.driver.find_element(*MainPageLocators.NO_SEARCH_RESULT_FOUND).text
def get_malfunctioning_page_text(self):
return self.driver.find_element(*MainPageLocators.MALFUNCTIONING_PAGE_TEXT).text