forked from mozilla/Addon-Tests
/
home.py
226 lines (182 loc) · 9.11 KB
/
home.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#!/usr/bin/env python
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is Mozilla WebQA Selenium Tests.
#
# The Initial Developer of the Original Code is
# Mozilla.
# Portions created by the Initial Developer are Copyright (C) 2011
# the Initial Developer. All Rights Reserved.
#
# Contributor(s): Bebe <florin.strugariu@softvision.ro>
# David Burns
# Marc George
# Dave Hunt <dhunt@mozilla.com>
# Alex Rodionov <p0deje@gmail.com>
# Joel Andersson <janderssn@gmail.com>
# Marlena Compton <mcompton@mozilla.com>
# Teodosia Pop <teodosia.pop@softvision.ro>
# Alex Lakatos <alex@greensqr.com>
# Alin Trif <alin.trif@softvision.ro>
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from pages.page import Page
from pages.base import Base
class Home(Base):
_page_title = "Add-ons for Firefox"
_themes_link_locator = (By.CSS_SELECTOR, "#themes > a")
_personas_link_locator = (By.CSS_SELECTOR, "#personas > a")
_collections_link_locator = (By.CSS_SELECTOR, "#collections > a")
_first_addon_locator = (By.CSS_SELECTOR, "div.summary > a > h3")
_other_applications_link_locator = (By.ID, "other-apps")
#Most Popular List
_most_popular_item_locator = (By.CSS_SELECTOR, "ol.toplist li")
_most_popular_list_heading_locator = (By.CSS_SELECTOR, "#homepage > .secondary h2")
_explore_featured_link_locator = (By.CSS_SELECTOR, "#side-nav .s-featured a")
_explore_popular_link_locator = (By.CSS_SELECTOR, "#side-nav .s-users a")
_explore_top_rated_link_locator = (By.CSS_SELECTOR, "#side-nav .s-rating a")
_featured_personas_see_all_link = (By.CSS_SELECTOR, "#featured-personas h2 a")
_featured_personas_title_locator = (By.CSS_SELECTOR, "#featured-personas h2")
_featured_personas_items_locator = (By.CSS_SELECTOR, "#featured-personas li")
_featured_collections_locator = (By.CSS_SELECTOR, "#featured-collections h2")
_featured_collections_elements_locator = (By.CSS_SELECTOR, "#featured-collections section:nth-child(1) li")
_featured_extensions_title_locator = (By.CSS_SELECTOR, '#featured-extensions > h2')
_featured_extensions_see_all_locator = (By.CSS_SELECTOR, '#featured-extensions > h2 > a')
_featured_extensions_elements_locator = (By.CSS_SELECTOR, '#featured-extensions section:nth-child(1) li')
_category_list_locator = (By.CSS_SELECTOR, "ul#side-categories li")
_extensions_menu_link = (By.CSS_SELECTOR, "#extensions > a")
def __init__(self, testsetup, open_url=True):
''' Creates a new instance of the class and gets the page ready for testing '''
Base.__init__(self, testsetup)
if open_url:
self.selenium.get(self.base_url)
def hover_over_addons_home_title(self):
home_item = self.selenium.find_element(*self._amo_logo_link_locator)
ActionChains(self.selenium).\
move_to_element(home_item).\
perform()
def click_featured_personas_see_all_link(self):
self.selenium.find_element(*self._featured_personas_see_all_link).click()
from pages.personas import Personas
return Personas(self.testsetup)
def click_personas(self):
self.selenium.find_element(*self._personas_link_locator).click()
from pages.personas import Personas
return Personas(self.testsetup)
def click_themes(self):
self.selenium.find_element(*self._themes_link_locator).click()
from pages.themes import Themes
return Themes(self.testsetup)
def click_collections(self):
self.selenium.find_element(*self._collections_link_locator).click()
from pages.collection import Collections
return Collections(self.testsetup)
def click_extensions(self):
self.selenium.find_element(*self._extensions_menu_link).click()
from pages.extensions import ExtensionsHome
return ExtensionsHome(self.testsetup)
def click_featured_collections_see_all_link(self):
self.selenium.find_element(*self._featured_collections_locator).find_element(By.CSS_SELECTOR, " a").click()
from pages.collection import Collections
return Collections(self.testsetup)
def click_to_explore(self, what):
what = what.replace(' ', '_').lower()
self.selenium.find_element(*getattr(self, "_explore_%s_link_locator" % what)).click()
from pages.extensions import ExtensionsHome
return ExtensionsHome(self.testsetup)
@property
def most_popular_count(self):
return len(self.selenium.find_elements(*self._most_popular_item_locator))
@property
def most_popular_list_heading(self):
return self.selenium.find_element(*self._most_popular_list_heading_locator).text
@property
def featured_personas_count(self):
return len(self.selenium.find_elements(*self._featured_personas_items_locator))
@property
def featured_personas_title(self):
return self.selenium.find_element(*self._featured_personas_title_locator).text
@property
def featured_collections_title(self):
return self.selenium.find_element(*self._featured_collections_locator).text
@property
def featured_collections_count(self):
return len(self.selenium.find_elements(*self._featured_collections_elements_locator))
@property
def featured_extensions_see_all(self):
return self.selenium.find_element(*self._featured_extensions_see_all_locator).text
@property
def featured_extensions_title(self):
title = self.selenium.find_element(*self._featured_extensions_title_locator).text
return title.replace(self.featured_extensions_see_all, '').strip()
@property
def featured_extensions_count(self):
return len(self.selenium.find_elements(*self._featured_extensions_elements_locator))
def click_on_first_addon(self):
self.selenium.find_element(*self._first_addon_locator).click()
from pages.details import Details
return Details(self.testsetup)
def get_title_of_link(self, name):
name = name.lower().replace(" ", "_")
locator = getattr(self, "_%s_link_locator" % name)
return self.selenium.find_element(*locator).get_attribute('title')
@property
def categories(self):
return [self.Categories(self.testsetup, element)
for element in self.selenium.find_elements(*self._category_list_locator)]
def category(self, element):
return self.Categories(self.testsetup, element)
@property
def most_popular_items(self):
return [self.MostPopularRegion(self.testsetup, element)
for element in self.selenium.find_elements(*self._most_popular_item_locator)]
class Categories(Page):
_link_locator = (By.CSS_SELECTOR, 'a')
def __init__(self, testsetup, element):
Page.__init__(self, testsetup)
self._root_element = element
@property
def name(self):
return self._root_element.text
def click_link(self):
self._root_element.find_element(*self._link_locator).click()
from pages.category import Category
return Category(self.testsetup)
class MostPopularRegion(Page):
_name_locator = (By.TAG_NAME, "span")
_users_locator = (By.CSS_SELECTOR, "small")
def __init__(self, testsetup, element):
Page.__init__(self, testsetup)
self._root_element = element
@property
def name(self):
self._root_element.find_element(*self._name_locator).text
@property
def users_number(self):
users_text = self._root_element.find_element(*self._users_locator).text
return int(users_text.split(' ')[0].replace(',', ''))