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 #85 from klrmn/methods_return_pages
Browse files Browse the repository at this point in the history
Methods return pages - questions pages/tests
  • Loading branch information
stephendonner committed Mar 22, 2012
2 parents 750413d + e215a91 commit f940c51
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
20 changes: 18 additions & 2 deletions pages/desktop/questions_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from pages.desktop.base import Base
from selenium.webdriver.common.by import By
from unittestzero import Assert

class QuestionsPage(Base):
"""
Expand Down Expand Up @@ -33,7 +34,10 @@ def go_to_thread(self, url):
self.open(url)

def click_any_question(self, question_number):
return self.selenium.find_elements(*self._questions_list_locator)[question_number - 1].find_element(*self._question_list_link_locator).click()
self.selenium.find_elements(*self._questions_list_locator)[question_number - 1].find_element(*self._question_list_link_locator).click()
view_question_pg = ViewQuestionPage(self.testsetup)
view_question_pg.is_the_current_page
return view_question_pg

def click_sort_by_solved_questions(self):
self.selenium.find_element(*self._sort_solved_link_locator).click()
Expand Down Expand Up @@ -96,11 +100,14 @@ def type_question(self, question_to_ask):
def click_provide_details_button(self):
self.selenium.find_element(*self._provide_details_button_locator).click()

def fill_up_questions_form(self, q_text='details', q_site='www.example.com', q_trouble='no addons'):
def fill_up_questions_form(self, question_to_ask, q_text='details', q_site='www.example.com', q_trouble='no addons'):
self.selenium.find_element(*self._q_content_box_locator).send_keys(q_text)
self.selenium.find_element(*self._q_site_box_locator).send_keys(q_site)
self.selenium.find_element(*self._q_trouble_box_locator).send_keys(q_trouble)
self.selenium.find_element(*self._q_post_button_locator).click()
view_question_pg = ViewQuestionPage(self.testsetup)
view_question_pg.is_the_current_page(question_to_ask)
return view_question_pg

@property
def sorted_list_filter_text(self, question_number):
Expand All @@ -114,7 +121,16 @@ class ViewQuestionPage(Base):
_problem_too_button_locator = (By.CSS_SELECTOR, 'input[value*="problem"]')
_problem_count_text_locator = (By.CSS_SELECTOR, 'div[class^="have-problem"] > mark')
_no_thanks_link_locator = (By.LINK_TEXT, 'No Thanks')
_page_title = ' | Firefox Support Forum | Firefox Help'

def is_the_current_page(self, question_name):
if self._page_title:
page_title = self.page_title
Assert.equal(page_title, question_name + self._page_title,
"Expected page title: %s. Actual page title: %s" % \
(question_name + self._page_title, page_title))


@property
def question(self):
return self.selenium.find_element(*self._question_locator).text
Expand Down
9 changes: 5 additions & 4 deletions pages/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,18 @@ def __init__(self, testsetup):
@property
def is_the_current_page(self):
if self._page_title:
WebDriverWait(self.selenium, self.timeout).until(lambda s: s.title)

Assert.equal(self.selenium.title, self._page_title,
"Expected page title: %s. Actual page title: %s" % (self._page_title, self.selenium.title))
page_title = self.page_title
Assert.equal(page_title, self._page_title,
"Expected page title: %s. Actual page title: %s" % \
(self._page_title, page_title))

@property
def url_current_page(self):
return(self.selenium.current_url)

@property
def page_title(self):
WebDriverWait(self.selenium, self.timeout).until(lambda s: s.title)
return self.selenium.title

def refresh(self):
Expand Down
6 changes: 2 additions & 4 deletions tests/desktop/test_questions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class TestQuestions:
def test_that_posting_question_works(self, mozwebqa):
"""Posts a question to /questions"""
ask_new_questions_pg = AskNewQuestionsPage(mozwebqa)
view_question_pg = ViewQuestionPage(mozwebqa)
timestamp = datetime.datetime.today()
q_to_ask = "automation test question %s" % (timestamp)
q_details = "This is a test. %s" % (timestamp)
Expand All @@ -29,7 +28,7 @@ def test_that_posting_question_works(self, mozwebqa):
ask_new_questions_pg.click_category_problem_link()
ask_new_questions_pg.type_question(q_to_ask)
ask_new_questions_pg.click_provide_details_button()
ask_new_questions_pg.fill_up_questions_form(q_details)
view_question_pg = ask_new_questions_pg.fill_up_questions_form(q_to_ask, q_details)

Assert.equal(view_question_pg.question, q_to_ask)
Assert.equal(view_question_pg.question_detail, q_details)
Expand Down Expand Up @@ -82,11 +81,10 @@ def test_that_questions_problem_count_increments(self, mozwebqa):
"""Checks if the 'I have this problem too' counter increments"""

questions_pg = QuestionsPage(mozwebqa)
view_question_pg = ViewQuestionPage(mozwebqa)

# Can't +1 your own question so will do it logged out
questions_pg.go_to_forum_questions_page()
questions_pg.click_any_question(1)
view_question_pg = questions_pg.click_any_question(1)

initial_count = view_question_pg.problem_count
view_question_pg.click_problem_too_button()
Expand Down

0 comments on commit f940c51

Please sign in to comment.