Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #52 from bebef1987/test_sort

test for bug 738469
  • Loading branch information...
commit 540a18eb5a7ab6f94af4ee47011796e82160cd4e 2 parents a26a149 + ba5c963
Zac zacc authored
29 pages/regions/paginator.py
... ... @@ -0,0 +1,29 @@
  1 +#!/usr/bin/env python
  2 +
  3 +# This Source Code Form is subject to the terms of the Mozilla Public
  4 +# License, v. 2.0. If a copy of the MPL was not distributed with this
  5 +# file, You can obtain one at http://mozilla.org/MPL/2.0/.
  6 +
  7 +
  8 +from selenium.webdriver.common.by import By
  9 +from page import Page
  10 +from selenium.webdriver.support.ui import WebDriverWait
  11 +
  12 +
  13 +class Paginator(Page):
  14 +
  15 + _next_locator = (By.CSS_SELECTOR, 'ul.UI_Pagination > li.next > a')
  16 + _results_loading_locator = (By.CSS_SELECTOR, '#SearchResults.loading')
  17 +
  18 + @property
  19 + def is_next_visible(self):
  20 + return self.is_element_visible(*self._next_locator)
  21 +
  22 + def next(self):
  23 + self.selenium.find_element(*self._next_locator).click()
  24 + self._wait_for_search_ajax()
  25 + from pages.search_page import SearchPage
  26 + return SearchPage(self.testsetup)
  27 +
  28 + def _wait_for_search_ajax(self):
  29 + WebDriverWait(self.selenium, 10).until(lambda s: not self.is_element_present(*self._results_loading_locator))
38 pages/search_page.py
@@ -9,6 +9,7 @@
9 9 from selenium.webdriver.common.action_chains import ActionChains
10 10 from selenium.webdriver.common.by import By
11 11 from selenium.webdriver.support.ui import WebDriverWait
  12 +from selenium.webdriver.support.select import Select
12 13
13 14
14 15 class SearchPage(FlightDeckBasePage):
@@ -29,6 +30,10 @@ class SearchPage(FlightDeckBasePage):
29 30 _results_message_locator = (By.CSS_SELECTOR, "#SearchResults > p")
30 31 _results_loading_locator = (By.CSS_SELECTOR, '#SearchResults.loading')
31 32
  33 + _see_all_results_addon_locator = (By.CSS_SELECTOR, "#SearchResults > p.see-more > a[href*='type=a']")
  34 +
  35 + _sort_filter_locator = (By.ID, 'SortSelect')
  36 +
32 37 def addon(self, lookup):
33 38 return self.Addon(self.testsetup, lookup)
34 39
@@ -38,6 +43,16 @@ def library(self, lookup):
38 43 def _item_locator_by_name(self, name):
39 44 return (By.LINK_TEXT, name)
40 45
  46 + def sort_addons_by(self, sort_method):
  47 + sort_selector = Select(self.selenium.find_element(*self._sort_filter_locator))
  48 + sort_selector.select_by_visible_text(sort_method)
  49 + self._wait_for_search_ajax()
  50 +
  51 + @property
  52 + def current_sort_method(self):
  53 + sort_selector = Select(self.selenium.find_element(*self._sort_filter_locator))
  54 + return sort_selector.first_selected_option.text
  55 +
41 56 def type_search_term(self, text):
42 57 self.selenium.find_element(*self._search_field_locator).send_keys(text)
43 58
@@ -48,6 +63,10 @@ def click_search(self):
48 63 self.selenium.find_element(*self._search_button_locator).click()
49 64 self._wait_for_search_ajax()
50 65
  66 + def click_see_all_addons(self):
  67 + self.selenium.find_element(*self._see_all_results_addon_locator).click()
  68 + self._wait_for_search_ajax()
  69 +
51 70 def click_filter_addons_link(self):
52 71 self.selenium.find_element(*self._filter_by_addons_locator).click()
53 72 self._wait_for_search_ajax()
@@ -113,6 +132,11 @@ def move_activity_slider(self, notches):
113 132 def _wait_for_search_ajax(self):
114 133 WebDriverWait(self.selenium, 10).until(lambda s: not self.is_element_present(*self._results_loading_locator))
115 134
  135 + @property
  136 + def paginator(self):
  137 + from pages.regions.paginator import Paginator
  138 + return Paginator(self.testsetup)
  139 +
116 140 class SearchResultsRegion(Page):
117 141
118 142 def __init__(self, testsetup, lookup):
@@ -124,6 +148,15 @@ def __init__(self, testsetup, lookup):
124 148
125 149 _name_locator = (By.CSS_SELECTOR, "h3 > a")
126 150 _author_link_locator = (By.CSS_SELECTOR, "ul.search_meta li:nth-child(1) > a")
  151 + _activity_locator = (By.CSS_SELECTOR, 'ul.search_meta > li.activity')
  152 +
  153 + _activity_rating = {'inactive': 0,
  154 + 'stale': 1,
  155 + 'low': 2,
  156 + 'moderate': 3,
  157 + 'high': 4,
  158 + 'rockin\'': 5
  159 + }
127 160
128 161 @property
129 162 def root_element(self):
@@ -150,6 +183,11 @@ def click(self):
150 183 from pages.editor_page import LibraryEditorPage
151 184 return LibraryEditorPage(self.testsetup)
152 185
  186 + @property
  187 + def activity_rating(self):
  188 + activity = self.root_element.find_element(*self._activity_locator).text.strip()
  189 + return self._activity_rating[activity]
  190 +
153 191 def click_author(self):
154 192 self.root_element.find_element(*self._author_link_locator).click()
155 193
24 tests/test_search.py
@@ -262,3 +262,27 @@ def test_activity_slider_filters_results(self, mozwebqa):
262 262
263 263 Assert.true(initial_addon_count > searchpage_obj.addons_count_label)
264 264 Assert.true(initial_library_count > searchpage_obj.library_count_label)
  265 +
  266 + @pytest.mark.nondestructive
  267 + @pytest.mark.xfail(reason="Bug 738469 - Default sort order says 'Activity', but doesn't actually match 'Activity' search-sort order/results")
  268 + def test_default_search_order_is_by_activity(self, mozwebqa):
  269 + homepage_obj = HomePage(mozwebqa)
  270 +
  271 + homepage_obj.go_to_home_page()
  272 + searchpage_obj = homepage_obj.header.click_search()
  273 +
  274 + searchpage_obj.type_search_term('addon')
  275 + searchpage_obj.click_search()
  276 +
  277 + searchpage_obj.click_see_all_addons()
  278 +
  279 + Assert.equal('Activity', searchpage_obj.current_sort_method)
  280 +
  281 + addons_activity_property_list = []
  282 + while searchpage_obj.paginator.is_next_visible:
  283 + for lookup in range(1, searchpage_obj.addons_element_count() + 1):
  284 + addons_activity_property_list.append(
  285 + searchpage_obj.addon(lookup).activity_rating)
  286 +
  287 + Assert.is_sorted_descending(addons_activity_property_list, 'The addons are not sorted by Activity')
  288 + searchpage_obj.paginator.next()

0 comments on commit 540a18e

Please sign in to comment.
Something went wrong with that request. Please try again.