Skip to content
This repository has been archived by the owner on Aug 20, 2018. It is now read-only.

Commit

Permalink
Merge pull request mozilla#164 from willkg/update-test-pagination
Browse files Browse the repository at this point in the history
Update test pagination
  • Loading branch information
willkg committed May 28, 2014
2 parents 68e8148 + 23f2087 commit ae7bf15
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
18 changes: 18 additions & 0 deletions pages/base.py
Expand Up @@ -7,6 +7,10 @@
import urllib
from urlparse import urlparse

from selenium.common.exceptions import (
ElementNotVisibleException,
NoSuchElementException
)
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from unittestzero import Assert
Expand Down Expand Up @@ -35,6 +39,16 @@ def is_element_visible(self, locator):
except:
return False

def is_element_not_visible(self, *locator):
self.selenium.implicitly_wait(0)
try:
return not self.selenium.find_element(*locator).is_displayed()
except (NoSuchElementException, ElementNotVisibleException):
return True
finally:
# set back to where you once belonged
self.selenium.implicitly_wait(self.testsetup.default_implicit_wait)

@property
def current_page_url(self):
return(self.selenium.current_url)
Expand Down Expand Up @@ -85,6 +99,10 @@ def is_older_messages_link_visible(self):
def is_newer_messages_link_visible(self):
return self.is_element_visible(self._newer_messages_link_locator)

@property
def is_newer_messages_link_not_visible(self):
return self.is_element_not_visible(self._newer_messages_link_locator)

def _value_from_url(self, param):
"""Returns the value for the specified parameter in the URL."""
url = urlparse(self.selenium.current_url)
Expand Down
18 changes: 18 additions & 0 deletions pages/desktop/feedback.py
Expand Up @@ -4,6 +4,8 @@
# 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/.

import datetime

from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys

Expand All @@ -22,6 +24,9 @@ class FeedbackPage(BasePage):
_total_message_count_heading_locator = (By.CSS_SELECTOR, '#big-count h3')
_messages_column_heading_locator = (By.CSS_SELECTOR, '#messages h2')
_messages_locator = (By.CSS_SELECTOR, '.opinion')
_date_start = (By.CSS_SELECTOR, 'div#whentext input[name=date_start]')
_date_end = (By.CSS_SELECTOR, 'div#whentext input[name=date_end]')
_date_set = (By.ID, 'whensubmit')

def go_to_feedback_page(self):
self.selenium.get(self.base_url + '/')
Expand Down Expand Up @@ -65,6 +70,19 @@ def date_filter(self):
from pages.desktop.regions.date_filter import DateFilter
return DateFilter(self.testsetup)

def set_date_range(self, date_start, date_end=None):
if date_end is None:
date_end = datetime.date.today().strftime('%Y-%m-%d')

date_start_box = self.selenium.find_element(*self._date_start)
date_start_box.clear()
date_start_box.send_keys(date_start)
date_end_box = self.selenium.find_element(*self._date_end)
date_end_box.clear()
date_end_box.send_keys(date_end)

self.selenium.find_element(*self._date_set).click()

def search_for(self, search_string):
search_box = self.selenium.find_element(*self._search_box)
search_box.send_keys(search_string)
Expand Down
20 changes: 15 additions & 5 deletions tests/desktop/test_pagination.py
Expand Up @@ -11,20 +11,30 @@


class TestPagination:
SEARCH_TERM = u'firefox'

@pytest.mark.nondestructive
def test_search_pagination(self, mozwebqa):
"""Litmus 13636 - Input: Verify Search results have pagination."""
feedback_pg = FeedbackPage(mozwebqa)
feedback_pg.go_to_feedback_page()
feedback_pg.search_for("facebook")
# Set the date range to 2013-01-01 -> today so that we're more
# likely to have so many messages in the results that it
# paginates. Otherwise it might not paginate on stage or local
# environments.
feedback_pg.set_date_range('2013-01-01')
feedback_pg.search_for(self.SEARCH_TERM)

# Check the total message count. If it's less than 50 (two
# pages worth), then we will fail with a helpful message.
Assert.greater(feedback_pg.total_message_count, 50, "Search term didn't kick up enough messages. Please prime the server with more data!")

Assert.true(feedback_pg.is_older_messages_link_visible)
Assert.false(feedback_pg.is_newer_messages_link_visible)
Assert.true(feedback_pg.is_newer_messages_link_not_visible)
Assert.equal(feedback_pg.older_messages_link, 'Older Messages')

feedback_pg.click_older_messages()
Assert.equal(feedback_pg.search_term_from_url, "facebook")
Assert.equal(feedback_pg.search_term_from_url, self.SEARCH_TERM)

Assert.true(feedback_pg.is_older_messages_link_visible)
Assert.true(feedback_pg.is_newer_messages_link_visible)
Expand All @@ -33,9 +43,9 @@ def test_search_pagination(self, mozwebqa):
Assert.equal(feedback_pg.page_from_url, 2)

feedback_pg.click_newer_messages()
Assert.equal(feedback_pg.search_term_from_url, "facebook")
Assert.equal(feedback_pg.search_term_from_url, self.SEARCH_TERM)

Assert.true(feedback_pg.is_older_messages_link_visible)
Assert.false(feedback_pg.is_newer_messages_link_visible)
Assert.true(feedback_pg.is_newer_messages_link_not_visible)
Assert.equal(feedback_pg.older_messages_link, 'Older Messages')
Assert.equal(feedback_pg.page_from_url, 1)

0 comments on commit ae7bf15

Please sign in to comment.