This repository has been archived by the owner on Feb 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathbase.py
167 lines (130 loc) · 6.34 KB
/
base.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
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from pypom import Page
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as expected
from selenium.webdriver.support.select import Select
from pages.auth0 import Auth0
from tests import restmail
class Base(Page):
URL_TEMPLATE = '/{locale}'
_logout_locator = (By.ID, 'nav-logout')
_pending_approval_locator = (By.ID, 'pending-approval')
_account_created_successfully_locator = (By.CSS_SELECTOR, 'div.alert:nth-child(2)')
# Not logged in
_sign_in_button_locator = (By.ID, 'nav-login')
def __init__(self, selenium, base_url, locale='en-US', **url_kwargs):
super(Base, self).__init__(selenium, base_url, locale=locale, **url_kwargs)
@property
def page_title(self):
return self.wait.until(lambda s: self.selenium.title)
@property
def is_pending_approval_visible(self):
return self.is_element_displayed(*self._pending_approval_locator)
@property
def was_account_created_successfully(self):
return self.is_element_displayed(*self._account_created_successfully_locator)
# Not logged in
@property
def is_sign_in_button_present(self):
return self.is_element_present(*self._sign_in_button_locator)
@property
def is_user_loggedin(self):
return self.is_element_present(*self._logout_locator)
def click_sign_in_button(self):
self.find_element(*self._sign_in_button_locator).click()
def login(self, email_address):
self.click_sign_in_button()
auth0 = Auth0(self.selenium, self.base_url)
auth0.request_login_link(email_address)
login_link = restmail.get_mail(email_address)
self.selenium.get(login_link)
self.wait.until(lambda s: self.is_user_loggedin)
def login_with_github(self, username, password, secret):
self.click_sign_in_button()
auth0 = Auth0(self.selenium, self.base_url)
github = auth0.click_login_with_github()
github.login_with_github(username, password, secret)
def create_new_user(self, email):
self.login(email)
from pages.register import Register
return Register(self.selenium, self.base_url).wait_for_page_to_load()
@property
def header(self):
return self.Header(self.selenium, self.base_url)
@property
def footer(self):
return self.Footer(self.selenium, self.base_url)
class Header(Page):
_search_box_locator = (By.CSS_SELECTOR, '.search-query')
_search_box_loggedin_locator = (By.CSS_SELECTOR, '.search-right > form > .search-query')
_profile_menu_locator = (By.CSS_SELECTOR, '#nav-main > a.dropdown-toggle i')
# menu items
_dropdown_menu_locator = (By.CSS_SELECTOR, 'ul.dropdown-menu')
_view_profile_menu_item_locator = (By.ID, 'nav-profile')
_groups_menu_item_locator = (By.ID, 'nav-groups')
_invite_menu_item_locator = (By.ID, 'nav-invite')
_settings_menu_item_locator = (By.ID, 'nav-edit-profile')
_logout_menu_item_locator = (By.ID, 'nav-logout')
@property
def is_search_box_present(self):
return self.is_element_present(*self._search_box_locator)
def search_for(self, search_term, loggedin=False):
if loggedin:
search_field = self.find_element(*self._search_box_loggedin_locator)
else:
search_field = self.find_element(*self._search_box_locator)
search_field.send_keys(search_term)
search_field.send_keys(Keys.RETURN)
from pages.search import Search
return Search(self.selenium, self.base_url).wait_for_page_to_load()
def click_options(self):
self.wait.until(expected.visibility_of_element_located(
self._profile_menu_locator)).click()
self.wait.until(expected.visibility_of_element_located(
self._dropdown_menu_locator))
@property
def is_logout_menu_item_present(self):
return self.is_element_present(*self._logout_menu_item_locator)
@property
def is_groups_menu_item_present(self):
return self.is_element_present(*self._groups_menu_item_locator)
# menu items
def click_view_profile_menu_item(self):
self.click_options()
self.find_element(*self._view_profile_menu_item_locator).click()
from pages.profile import Profile
return Profile(self.selenium, self.base_url).wait_for_page_to_load()
def click_invite_menu_item(self):
self.click_options()
self.find_element(*self._invite_menu_item_locator).click()
from pages.invite import Invite
return Invite(self.selenium, self.base_url)
def click_settings_menu_item(self):
self.click_options()
self.find_element(*self._settings_menu_item_locator).click()
from pages.settings import Settings
return Settings(self.selenium, self.base_url)
def click_logout_menu_item(self):
self.click_options()
self.find_element(*self._logout_menu_item_locator).click()
self.wait.until(lambda s: not self.is_logout_menu_item_present)
def click_groups_menu_item(self):
self.click_options()
self.find_element(*self._groups_menu_item_locator).click()
from pages.groups_page import GroupsPage
return GroupsPage(self.selenium, self.base_url)
class Footer(Page):
_about_mozillians_link_locator = (By.CSS_SELECTOR, '.footer-nav.details > li:nth-child(1) > a')
_language_selector_locator = (By.ID, 'language')
_language_selection_ok_button = (By.CSS_SELECTOR, '#language-switcher button')
def click_about_link(self):
self.find_element(*self._about_mozillians_link_locator).click()
from pages.about import About
return About(self.selenium, self.base_url)
def select_language(self, lang_code):
element = self.find_element(*self._language_selector_locator)
select = Select(element)
select.select_by_value(lang_code)