Skip to content
This repository has been archived by the owner on Sep 30, 2020. It is now read-only.

Commit

Permalink
new paginator region
Browse files Browse the repository at this point in the history
pep8 review
  • Loading branch information
bebef1987 committed Jan 17, 2012
1 parent 7555b55 commit d83da82
Show file tree
Hide file tree
Showing 17 changed files with 190 additions and 148 deletions.
5 changes: 4 additions & 1 deletion conftest.py
Expand Up @@ -39,9 +39,11 @@

import mozwebqa


def pytest_runtest_setup(item):
mozwebqa.TestSetup.api_base_url = item.config.option.api_base_url


def pytest_addoption(parser):
parser.addoption("--apibaseurl",
action="store",
Expand All @@ -50,5 +52,6 @@ def pytest_addoption(parser):
default="https://addons-dev.allizom.org",
help="specify the api url")


def pytest_funcarg__mozwebqa(request):
return mozwebqa.TestSetup(request)
return mozwebqa.TestSetup(request)
2 changes: 1 addition & 1 deletion pages/__init__.py
Expand Up @@ -35,4 +35,4 @@
# 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 *****
# ***** END LICENSE BLOCK *****
12 changes: 6 additions & 6 deletions pages/base.py
Expand Up @@ -51,9 +51,8 @@

class Base(Page):

_current_page_locator = (By.CSS_SELECTOR, ".paginator .num > a:nth-child(1)")

_amo_logo_locator = ((By.CSS_SELECTOR, ".site-title"))
_amo_logo_locator = (By.CSS_SELECTOR, ".site-title")
_amo_logo_link_locator = (By.CSS_SELECTOR, ".site-title a")
_amo_logo_image_locator = (By.CSS_SELECTOR, ".site-title img")

Expand Down Expand Up @@ -105,10 +104,6 @@ def is_mozilla_logo_visible(self):
def click_mozilla_logo(self):
self.selenium.find_element(*self._mozilla_logo_link_locator).click()

@property
def current_page(self):
return int(self.selenium.find_element(*self._current_page_locator).text)

def credentials_of_user(self, user):
return self.parse_yaml_file(self.credentials)[user]

Expand All @@ -121,6 +116,11 @@ def breadcrumbs(self):
return [self.BreadcrumbsRegion(self.testsetup, element)
for element in self.selenium.find_elements(*self._breadcrumbs_locator)]

@property
def paginator(self):
from pages.regions.paginator import Paginator
return Paginator(self.testsetup)

def _extract_iso_dates(self, date_format, *locator):
"""
Returns a list of iso formatted date strings extracted from
Expand Down
1 change: 1 addition & 0 deletions pages/browser_id.py
Expand Up @@ -42,6 +42,7 @@
from pages.page import Page
from selenium.webdriver.common.by import By


class BrowserID(Page):

_email_locator = (By.ID, 'email')
Expand Down
33 changes: 0 additions & 33 deletions pages/details.py
Expand Up @@ -121,10 +121,6 @@ class Details(Base):
_development_channel_content_locator = (By.CSS_SELECTOR, "#beta-channel > div.content")
_development_version_locator = (By.CSS_SELECTOR, '.beta-version')

_next_link_locator = (By.CSS_SELECTOR, ".paginator .rel > a:nth-child(3)")
_previous_link_locator = (By.CSS_SELECTOR, ".paginator .rel > a:nth-child(2)")
_last_page_link_locator = (By.CSS_SELECTOR, ".paginator .rel > a:nth-child(4)")
_first_page_link_locator = (By.CSS_SELECTOR, ".paginator .rel > a:nth-child(1)")

def __init__(self, testsetup, addon_name=None):
#formats name for url
Expand Down Expand Up @@ -325,35 +321,6 @@ def part_of_collections(self):
return [self.PartOfCollectionsSnippet(self.testsetup, element)
for element in self.selenium.find_elements(*self._part_of_collections_list_locator)]

def page_forward(self):
self.selenium.find_element(*self._next_link_locator).click()

def page_back(self):
self.selenium.find_element(*self._previous_link_locator).click()

def go_to_last_page(self):
self.selenium.find_element(*self._last_page_link_locator).click()

def go_to_first_page(self):
self.selenium.find_element(*self._first_page_link_locator).click()

@property
def is_prev_link_enabled(self):
button = self.selenium.find_element(*self._previous_link_locator).get_attribute('class')
return not ("disabled" in button)

@property
def is_prev_link_visible(self):
return self.is_element_visible(*self._previous_link_locator)

@property
def is_next_link_enabled(self):
button = self.selenium.find_element(*self._next_link_locator).get_attribute('class')
return not("disabled" in button)

@property
def is_next_link_visible(self):
return self.is_element_visible(*self._next_link_locator)

class PartOfCollectionsSnippet(Page):

Expand Down
14 changes: 0 additions & 14 deletions pages/extensions.py
Expand Up @@ -49,9 +49,6 @@ class ExtensionsHome(Base):

_page_title = 'Featured Extensions :: Add-ons for Firefox'
_extensions_locator = (By.CSS_SELECTOR, "div.items div.item")
_next_page_locator = (By.CSS_SELECTOR, ".paginator .rel > a:nth-child(3)")
_last_page_link_locator = (By.CSS_SELECTOR, ".paginator .rel > a:nth-child(4)")
_first_page_link_locator = (By.CSS_SELECTOR, ".paginator .rel > a:nth-child(1)")
_default_selected_tab_locator = (By.CSS_SELECTOR, "#sorter li.selected")

_sort_by_most_users_locator = (By.CSS_SELECTOR, "div#sorter > ul > li:nth-child(2) > a")
Expand All @@ -63,17 +60,6 @@ def extensions(self):
return [Extension(self.testsetup, element)
for element in self.selenium.find_elements(*self._extensions_locator)]

@property
def is_next_button_disabled(self):
next_button = self.selenium.find_element(*self._next_page_locator)
return 'disabled' in next_button.get_attribute('class')

def go_to_last_page(self):
self.selenium.find_element(*self._last_page_link_locator).click()

def go_to_first_page(self):
self.selenium.find_element(*self._first_page_link_locator).click()

@property
def default_selected_tab(self):
return self.selenium.find_element(*self._default_selected_tab_locator).text
Expand Down
2 changes: 1 addition & 1 deletion pages/regions/__init__.py
Expand Up @@ -35,4 +35,4 @@
# 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 *****
# ***** END LICENSE BLOCK *****
126 changes: 126 additions & 0 deletions pages/regions/paginator.py
@@ -0,0 +1,126 @@
#!/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) 2012
# the Initial Developer. All Rights Reserved.
#
# Contributor(s): Bebe <florin.strugariu@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 pages.page import Page


class Paginator(Page):

#Numbering
_numbering_text_loactor = (By.CSS_SELECTOR, 'nav.paginator .num')
_page_number_locator = (By.CSS_SELECTOR, 'nav.paginator .num >a:nth-child(1)')
_total_number_of_pages_locator = (By.CSS_SELECTOR, 'nav.paginator .num >a:nth-child(2)')

#Navigation
_first_page_locator = (By.CSS_SELECTOR, 'nav.paginator .rel a:nth-child(1)')
_prev_locator = (By.CSS_SELECTOR, 'nav.paginator .rel a.prev')
_next_loactor = (By.CSS_SELECTOR, 'nav.paginator .rel a.next')
_last_page_loactor = (By.CSS_SELECTOR, 'nav.paginator .rel a:nth-child(4)')

#Position
_position_text_locator = (By.CSS_SELECTOR, 'nav.paginator .pos')
_start_item_number_locator = (By.CSS_SELECTOR, 'nav.paginator .pos b:nth-child(1)')
_end_item_number_locator = (By.CSS_SELECTOR, 'nav.paginator .pos b:nth-child(2)')
_toatal_item_number = (By.CSS_SELECTOR, 'nav.paginator .pos b:nth-child(3)')

@property
def numbering_text(self):
return self.selenium.find_element(*self._numbering_text_loactor).text

@property
def page_number(self):
return int(self.selenium.find_element(*self._page_number_locator).text)

@property
def total_number_of_pages(self):
return int(self.selenium.find_element(*self._total_number_of_pages_locator))

def go_to_first_page(self):
self.selenium.find_element(*self._first_page_locator).click()

@property
def go_to_first_page_title(self):
return self.selenium.find_element(*self._first_page_locator).get_attribute('title')

@property
def is_go_to_first_page_disabled(self):
return 'disabled' in self.selenium.find_element(*self._first_page_locator).get_attribute('class')

def prev_page(self):
self.selenium.find_element(*self._prev_locator).click()

@property
def is_prev_page_disabled(self):
return 'disabled' in self.selenium.find_element(*self._prev_locator).get_attribute('class')

def next_page(self):
self.selenium.find_element(*self._next_loactor).click()

@property
def is_next_page_disabled(self):
return 'disabled' in self.selenium.find_element(*self._next_loactor).get_attribute('class')

def go_to_last_page(self):
self.selenium.find_element(*self._last_page_loactor).click()

@property
def go_to_last_page_title(self):
return self.selenium.find_element(*self._last_page_loactor).get_attribute('title')

@property
def is_go_to_last_page_disabled(self):
return 'disabled' in self.selenium.find_element(*self._last_page_loactor).get_attribute('class')

@property
def position_text(self):
return self.selenium.find_element(*self._position_text_locator).text

@property
def start_item(self):
return int(self.selenium.find_element(*self._start_item_number_locator).text)

@property
def end_item(self):
return int(self.selenium.find_element(*self._end_item_number_locator).text)

@property
def total_items(self):
return long(self.selenium.find_element(*self._toatal_item_number).text)
24 changes: 2 additions & 22 deletions pages/search.py
Expand Up @@ -69,12 +69,9 @@ class SearchHome(Base):

_hover_more_locator = (By.CSS_SELECTOR, "li.extras > a")

_next_link_locator = (By.CSS_SELECTOR, ".paginator .rel > a:nth-child(3)")
_previous_link_locator = (By.CSS_SELECTOR, ".paginator .rel > a:nth-child(2)")
_updating_locator = (By.CSS_SELECTOR, "div.updating")
_results_displayed_text_locator = (By.CSS_SELECTOR, ".paginator .pos")

def _wait_for_results_refresh(self):
def wait_for_results_refresh(self):
WebDriverWait(self.selenium, 10).until(lambda s: not self.is_element_present(*self._updating_locator))

@property
Expand Down Expand Up @@ -107,7 +104,7 @@ def sort_by(self, type):
ActionChains(self.selenium).move_to_element(hover_element).\
move_to_element(click_element).\
click().perform()
self._wait_for_results_refresh()
self.wait_for_results_refresh()
return SearchHome(self.testsetup)

def result(self, lookup):
Expand All @@ -118,23 +115,6 @@ def results(self):
return [self.SearchResult(self.testsetup, element)
for element in self.selenium.find_elements(*self._results_locator)]

def page_forward(self):
self.selenium.find_element(*self._next_link_locator).click()
self._wait_for_results_refresh()

def page_back(self):
self.selenium.find_element(*self._previous_link_locator).click()
self._wait_for_results_refresh()

@property
def is_next_link_enabled(self):
button = self.selenium.find_element(*self._next_link_locator).get_attribute('class')
return not("disabled" in button)

@property
def results_displayed(self):
return self.selenium.find_element(*self._results_displayed_text_locator).text

class SearchResult(Page):
_name_locator = (By.CSS_SELECTOR, 'div.info > h3 > a')
_created_date = (By.CSS_SELECTOR, 'div.info > div.vitals > div.updated')
Expand Down
1 change: 0 additions & 1 deletion pages/statistics.py
Expand Up @@ -36,7 +36,6 @@
#
# ***** END LICENSE BLOCK *****

import re

from selenium.webdriver.common.by import By

Expand Down
18 changes: 0 additions & 18 deletions pages/themes.py
Expand Up @@ -67,8 +67,6 @@ class Themes(Base):
_category_locator = (By.CSS_SELECTOR, '#c-30 > a')
_categories_locator = (By.CSS_SELECTOR, '#side-categories li')
_category_link_locator = (By.CSS_SELECTOR, _categories_locator[1] + ':nth-of-type(%s) a')
_next_link_locator = (By.CSS_SELECTOR, '.paginator .rel > a:nth-child(3)')
_previous_link_locator = (By.CSS_SELECTOR, '.paginator .rel > a:nth-child(2)')

@property
def _addons_root_element(self):
Expand Down Expand Up @@ -144,22 +142,6 @@ def addon_rating(self):
ratings = self._extract_integers(pattern, *self._addons_rating_locator)
return ratings

def page_forward(self):
footer = self.selenium.find_element(*self._footer_locator)
forward = self.selenium.find_element(*self._next_link_locator)

ActionChains(self.selenium).move_to_element(footer).\
move_to_element(forward).\
click().perform()

def page_back(self):
footer = self.selenium.find_element(*self._footer_locator)
back = self.selenium.find_element(*self._previous_link_locator)

ActionChains(self.selenium).move_to_element(footer).\
move_to_element(back).\
click().perform()


class Theme(Base):

Expand Down
2 changes: 1 addition & 1 deletion tests/__init__.py
Expand Up @@ -35,4 +35,4 @@
# 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 *****
# ***** END LICENSE BLOCK *****
1 change: 0 additions & 1 deletion tests/test_details_page_against_xml.py
Expand Up @@ -45,7 +45,6 @@
from urllib2 import urlparse

from pages.details import Details
from pages.statistics import Statistics
from pages.addons_api import AddOnsAPI

xfail = pytest.mark.xfail
Expand Down
4 changes: 2 additions & 2 deletions tests/test_extensions.py
Expand Up @@ -65,6 +65,6 @@ def test_next_button_is_disabled_on_the_last_page(self, mozwebqa):
home_page = Home(mozwebqa)
featured_extensions_page = home_page.click_extensions()
featured_extensions_page.sort_by('most_users')
featured_extensions_page.go_to_last_page()
featured_extensions_page.paginator.go_to_last_page()

Assert.true(featured_extensions_page.is_next_button_disabled, 'Next button is available')
Assert.true(featured_extensions_page.paginator.is_next_page_disabled, 'Next button is available')

0 comments on commit d83da82

Please sign in to comment.