From 88beda994dd5fac010c1fcb34432cfe9a31c3a35 Mon Sep 17 00:00:00 2001 From: Dave Hunt Date: Fri, 22 Jan 2016 11:58:31 +0000 Subject: [PATCH] Migrate to pytest-selenium --- README.md | 18 ++++++++------ mozwebqa.cfg | 4 --- pages/desktop/base.py | 12 ++++----- pages/desktop/knowledge_base_article.py | 14 +++++------ pages/desktop/knowledge_base_new_article.py | 2 +- pages/desktop/page_provider.py | 23 +++++++++--------- pages/desktop/questions_page.py | 12 ++++----- pages/desktop/support_home_page.py | 2 +- pages/mobile/article.py | 8 +++--- pages/mobile/base.py | 6 ++--- pages/mobile/home.py | 6 ++--- pages/mobile/page_provider.py | 2 +- pages/mobile/search.py | 12 ++++----- pages/page.py | 11 ++++----- requirements.txt | 2 +- setup.cfg | 6 ++++- tests/conftest.py | 17 +++++++++++++ tests/desktop/test_kb_article.py | 20 +++++++-------- tests/desktop/test_login_logout.py | 20 +++++++-------- tests/desktop/test_new_user_registration.py | 4 +-- tests/desktop/test_questions.py | 20 +++++++-------- tests/desktop/test_rewrites.py | 27 ++++++++++----------- tests/desktop/test_search.py | 18 +++++++------- tests/desktop/test_switch_to_mobile_view.py | 6 ++--- tests/mobile/test_article.py | 4 +-- tests/mobile/test_homepage.py | 8 +++--- tests/mobile/test_search.py | 8 +++--- 27 files changed, 154 insertions(+), 138 deletions(-) delete mode 100644 mozwebqa.cfg create mode 100644 tests/conftest.py diff --git a/README.md b/README.md index 293974e..0f8d0a9 100644 --- a/README.md +++ b/README.md @@ -106,30 +106,30 @@ Before each test run, clean up the repo: To run tests locally it's a simple case of calling the command below from this directory: - py.test --driver=firefox --destructive --variables=/full/path/to/variables.json . + py.test --driver Firefox --variables /full/path/to/variables.json . __Output__ Output of a test run should look like this: ============================= test session starts ============================== platform darwin -- Python 2.6.1 -- pytest-2.2.3 - collected 35 items - + collected 35 items + tests/desktop/test_kb_article.py .X.... tests/desktop/test_new_user_registration.py . tests/desktop/test_questions.py .... tests/desktop/test_rewrites.py ..................... tests/desktop/test_search.py ..X - + ==================== 33 passed, 2 xpassed in 172.03 seconds ==================== __Note__ "~" will not resolve to the home directory when used in the py.test command line. -Some options for py.test are pre-specified by the file sumo_tests/mozwebqa.cfg - -The mozwebqa plugin has advanced command line options for reporting and using browsers. See the documentation on [pytest mozwebqa github][pymozwebqa]: -[pymozwebqa]: https://github.com/mozilla/pytest-mozwebqa +The pytest plugin that we use for running tests has a number of advanced +command line options available. To see the options available, run +`py.test --help`. The full documentation for the plugin can be found +[here][pytest-selenium]. __Troubleshooting__ @@ -159,3 +159,5 @@ This software is licensed under the [MPL] 2.0: file, You can obtain one at http://mozilla.org/MPL/2.0/. [MPL]: http://www.mozilla.org/MPL/2.0/ + +[pytest-selenium]: http://pytest-selenium.readthedocs.org/ diff --git a/mozwebqa.cfg b/mozwebqa.cfg deleted file mode 100644 index a829108..0000000 --- a/mozwebqa.cfg +++ /dev/null @@ -1,4 +0,0 @@ -[DEFAULT] -api = webdriver -baseurl = https://support.allizom.org -tags = sumo diff --git a/pages/desktop/base.py b/pages/desktop/base.py index 29a5665..3b46e47 100755 --- a/pages/desktop/base.py +++ b/pages/desktop/base.py @@ -9,8 +9,8 @@ class Base(Page): - def __init__(self, testsetup): - super(Base, self).__init__(testsetup) + def __init__(self, base_url, selenium): + super(Base, self).__init__(base_url, selenium) self.header.dismiss_staging_site_warning_if_present() def click_card_grid(self, locator): @@ -21,11 +21,11 @@ def click_card_grid(self, locator): @property def footer(self): - return self.FooterRegion(self.testsetup) + return self.FooterRegion(self.base_url, self.selenium) @property def header(self): - return self.HeaderRegion(self.testsetup) + return self.HeaderRegion(self.base_url, self.selenium) def sign_in(self, username, password): login = self.header.click_login() @@ -34,7 +34,7 @@ def sign_in(self, username, password): def sign_out(self): self.header.click_logout() from pages.desktop.register_page import RegisterPage - return RegisterPage(self.testsetup) + return RegisterPage(self.base_url, self.selenium) def switch_to_mobile_view(self): self.footer.click_switch_to_mobile_view() @@ -81,7 +81,7 @@ class HeaderRegion(Page): def click_login(self): self.selenium.find_element(*self._login_locator).click() from pages.desktop.login_page import LoginPage - return LoginPage(self.testsetup) + return LoginPage(self.base_url, self.selenium) def click_logout(self): self.dismiss_staging_site_warning_if_present() diff --git a/pages/desktop/knowledge_base_article.py b/pages/desktop/knowledge_base_article.py index 6ed1d8b..1dfe55b 100644 --- a/pages/desktop/knowledge_base_article.py +++ b/pages/desktop/knowledge_base_article.py @@ -12,7 +12,7 @@ class KnowledgeBase(Base): @property def navigation(self): - return self.Navigation(self.testsetup) + return self.Navigation(self.base_url, self.selenium) @property def is_the_current_page(self): @@ -36,21 +36,21 @@ def show_editing_tools(self): def click_article(self): self.show_editing_tools() self.selenium.find_element(*self._article_locator).click() - return KnowledgeBaseArticle(self.testsetup) + return KnowledgeBaseArticle(self.base_url, self.selenium) def click_edit_article(self): self.selenium.find_element(*self._edit_article_locator).click() - return KnowledgeBaseEditArticle(self.testsetup) + return KnowledgeBaseEditArticle(self.base_url, self.selenium) def click_translate_article(self): self.show_editing_tools() self.selenium.find_element(*self._translate_article_locator).click() - return KnowledgeBaseTranslate(self.testsetup) + return KnowledgeBaseTranslate(self.base_url, self.selenium) def click_show_history(self): self.show_editing_tools() self.selenium.find_element(*self._show_history_locator).click() - return KnowledgeBaseShowHistory(self.testsetup) + return KnowledgeBaseShowHistory(self.base_url, self.selenium) class KnowledgeBaseArticle(KnowledgeBase): @@ -141,7 +141,7 @@ def check_article_product(self, index): def set_article_comment_box(self, comment='default comment'): self.selenium.find_element(*self._comment_box_locator).send_keys(comment) self.selenium.find_element(*self._comment_submit_btn_locator).click() - kb_article_history = KnowledgeBaseShowHistory(self.testsetup) + kb_article_history = KnowledgeBaseShowHistory(self.base_url, self.selenium) kb_article_history.is_the_current_page return kb_article_history @@ -187,7 +187,7 @@ def type_modal_describe_changes(self, text): def click_modal_submit_changes_button(self): self.selenium.find_element(*self._submit_changes_button_locator).click() - return KnowledgeBaseShowHistory(self.testsetup) + return KnowledgeBaseShowHistory(self.base_url, self.selenium) class KnowledgeBaseShowHistory(KnowledgeBase): diff --git a/pages/desktop/knowledge_base_new_article.py b/pages/desktop/knowledge_base_new_article.py index 218a804..5af5339 100644 --- a/pages/desktop/knowledge_base_new_article.py +++ b/pages/desktop/knowledge_base_new_article.py @@ -95,7 +95,7 @@ def set_article_content(self, content): def set_article_comment_box(self, comment='automated test'): self.selenium.find_element(*self._comment_box_locator).send_keys(comment) self.selenium.find_element(*self._comment_submit_btn_locator).click() - kb_article_history = KnowledgeBaseShowHistory(self.testsetup) + kb_article_history = KnowledgeBaseShowHistory(self.base_url, self.selenium) kb_article_history.is_the_current_page return kb_article_history diff --git a/pages/desktop/page_provider.py b/pages/desktop/page_provider.py index 3372b6f..9d88d66 100644 --- a/pages/desktop/page_provider.py +++ b/pages/desktop/page_provider.py @@ -6,10 +6,9 @@ class PageProvider(): ''' internal methods ''' - def __init__(self, testsetup): - self.testsetup = testsetup - self.base_url = testsetup.base_url - self.selenium = testsetup.selenium + def __init__(self, base_url, selenium): + self.base_url = base_url + self.selenium = selenium def _set_window_size(self): # SUMO requires a minimum window width @@ -30,7 +29,7 @@ def _go_to_page_with_login_redirect(self, page_object, username, password): self._set_window_size() from pages.desktop.login_page import LoginPage self.selenium.get(self.base_url + page_object._page_url) - login_page = LoginPage(self.testsetup) + login_page = LoginPage(self.base_url, self.selenium) login_page.log_in(username, password) page_object.is_the_current_page page_object.header.dismiss_staging_site_warning_if_present() @@ -40,32 +39,32 @@ def _go_to_page_with_login_redirect(self, page_object, username, password): def new_user_registration_page(self): from pages.desktop.register_page import RegisterPage - return self._go_to_page(RegisterPage(self.testsetup)) + return self._go_to_page(RegisterPage(self.base_url, self.selenium)) ''' pages for which login is optional ''' def home_page(self, username=None, password=None): from pages.desktop.support_home_page import SupportHomePage - return self._go_to_page(SupportHomePage(self.testsetup), username, password) + return self._go_to_page(SupportHomePage(self.base_url, self.selenium), username, password) def new_question_page(self, username=None, password=None): from pages.desktop.questions_page import AskNewQuestionsPage - return self._go_to_page(AskNewQuestionsPage(self.testsetup), username, password) + return self._go_to_page(AskNewQuestionsPage(self.base_url, self.selenium), username, password) def questions_page(self, username=None, password=None): from pages.desktop.questions_page import QuestionsPage - return self._go_to_page(QuestionsPage(self.testsetup), username, password) + return self._go_to_page(QuestionsPage(self.base_url, self.selenium), username, password) def refine_search_page(self, username=None, password=None): from pages.desktop.refine_search_page import RefineSearchPage - return self._go_to_page(RefineSearchPage(self.testsetup), username, password) + return self._go_to_page(RefineSearchPage(self.base_url, self.selenium), username, password) def search_page(self, username=None, password=None): from pages.desktop.search_page import SearchPage - return self._go_to_page(SearchPage(self.testsetup), username, password) + return self._go_to_page(SearchPage(self.base_url, self.selenium), username, password) ''' pages for which login is required ''' def new_kb_article_page(self, username, password): from pages.desktop.knowledge_base_new_article import KnowledgeBaseNewArticle - return self._go_to_page_with_login_redirect(KnowledgeBaseNewArticle(self.testsetup), username, password) + return self._go_to_page_with_login_redirect(KnowledgeBaseNewArticle(self.base_url, self.selenium), username, password) diff --git a/pages/desktop/questions_page.py b/pages/desktop/questions_page.py index 907bc2b..b10c432 100644 --- a/pages/desktop/questions_page.py +++ b/pages/desktop/questions_page.py @@ -27,7 +27,7 @@ class QuestionsPage(Base): def click_ask_new_questions_link(self): self.selenium.find_element(*self._ask_question_link_locator).click() - return AskNewQuestionsPage(self.testsetup) + return AskNewQuestionsPage(self.base_url, self.selenium) def go_to_thread(self, url): self.open(url) @@ -68,7 +68,7 @@ def questions_count(self): @property def questions(self): - return [self.Question(self.testsetup, web_element) for web_element in self.selenium.find_elements(*self._questions_list_locator)] + return [self.Question(self.base_url, self.selenium, web_element) for web_element in self.selenium.find_elements(*self._questions_list_locator)] class Question(Page): @@ -77,8 +77,8 @@ class Question(Page): _question_link_locator = (By.CSS_SELECTOR, 'a') _product_name_locator = (By.CSS_SELECTOR, '.content ul.tag-list li:nth-child(1)') - def __init__(self, testsetup, element): - Page.__init__(self, testsetup) + def __init__(self, base_url, selenium, element): + Page.__init__(self, base_url, selenium) self._root_element = element @property @@ -101,7 +101,7 @@ def click_question_link(self): element = self._root_element.find_element(*self._question_link_locator) self.selenium.execute_script('arguments[0].scrollIntoView(false);', element) element.click() - view_question_pg = ViewQuestionPage(self.testsetup) + view_question_pg = ViewQuestionPage(self.base_url, self.selenium) view_question_pg.is_the_current_page(question_title, product_name) return view_question_pg @@ -155,7 +155,7 @@ def fill_up_questions_form(self, question_to_ask, q_text='details', q_site='www. self.selenium.find_element(*self._q_post_button_locator).click() WebDriverWait(self.selenium, self.timeout).until( lambda s: not self.is_element_present(*self._q_post_button_locator)) - view_question_pg = ViewQuestionPage(self.testsetup) + view_question_pg = ViewQuestionPage(self.base_url, self.selenium) view_question_pg.is_the_current_page(question_to_ask, selected_product) return view_question_pg diff --git a/pages/desktop/support_home_page.py b/pages/desktop/support_home_page.py index 5354194..78edce5 100644 --- a/pages/desktop/support_home_page.py +++ b/pages/desktop/support_home_page.py @@ -28,7 +28,7 @@ def do_search_on_main_search_box(self, search_query): search_box.type_keys(search_query) self.selenium.find_element(*self._search_button).click() from search_page import SearchPage - return SearchPage(self.testsetup) + return SearchPage(self.base_url, self.selenium) def click_top_common_content_link(self): self.selenium.find_element(*self._top_helpful_content_locator).click() diff --git a/pages/mobile/article.py b/pages/mobile/article.py index c54a4b7..28fc913 100644 --- a/pages/mobile/article.py +++ b/pages/mobile/article.py @@ -14,16 +14,16 @@ class Article(Base): _helpful_header_text_locator = (By.CSS_SELECTOR, 'div.vote-bar header') _vote_message_text_locator = (By.CSS_SELECTOR, 'div.vote-bar p') - def __init__(self, testsetup): - Base.__init__(self, testsetup) + def __init__(self, base_url, selenium): + Base.__init__(self, base_url, selenium) @property def helpful_header_text(self): return self.selenium.find_element(*self._helpful_header_text_locator).text def wait_for_vote_message_text(self, text): - vote_message = self.selenium.find_element(*self._vote_message_text_locator) - WebDriverWait(self.selenium, self.timeout).until(lambda s: vote_message.text == text) + WebDriverWait(self.selenium, self.timeout).until( + lambda s: s.find_element(*self._vote_message_text_locator).text == text) def click_helpful_button(self): self.selenium.find_element(*self._helpful_button_locator).click() diff --git a/pages/mobile/base.py b/pages/mobile/base.py index 0b90442..ce84c90 100644 --- a/pages/mobile/base.py +++ b/pages/mobile/base.py @@ -20,7 +20,7 @@ def is_menu_exposed(self): @property def menu_items(self): - return [self.MenuItem(self.testsetup, element) + return [self.MenuItem(self.base_url, self.selenium, element) for element in self.selenium.find_elements(*self._menu_items_locator)] @property @@ -40,8 +40,8 @@ def open_menu(self): class MenuItem(Page): - def __init__(self, testsetup, element): - Page.__init__(self, testsetup) + def __init__(self, base_url, selenium, element): + Page.__init__(self, base_url, selenium) self._root_element = element @property diff --git a/pages/mobile/home.py b/pages/mobile/home.py index 5873486..5675ebf 100644 --- a/pages/mobile/home.py +++ b/pages/mobile/home.py @@ -15,8 +15,8 @@ class Home(Base): _header_locator = (By.CSS_SELECTOR, 'header h1') _search_box_locator = (By.CSS_SELECTOR, '#search input') - def __init__(self, testsetup): - Base.__init__(self, testsetup) + def __init__(self, base_url, selenium): + Base.__init__(self, base_url, selenium) @property def header_text(self): @@ -29,4 +29,4 @@ def search_for(self, search_term): search_box.submit() from pages.mobile.search import Search - return Search(self.testsetup) + return Search(self.base_url, self.selenium) diff --git a/pages/mobile/page_provider.py b/pages/mobile/page_provider.py index 86bd6e7..338387d 100644 --- a/pages/mobile/page_provider.py +++ b/pages/mobile/page_provider.py @@ -14,4 +14,4 @@ def _go_to_page(self, page_object): def home_page(self): from pages.mobile.home import Home - return self._go_to_page(Home(self.testsetup)) + return self._go_to_page(Home(self.base_url, self.selenium)) diff --git a/pages/mobile/search.py b/pages/mobile/search.py index ff06b31..1f568d6 100644 --- a/pages/mobile/search.py +++ b/pages/mobile/search.py @@ -12,21 +12,21 @@ class Search(Base): _results_locator = (By.CSS_SELECTOR, 'ol.search-results li') - def __init__(self, testsetup): - Base.__init__(self, testsetup) + def __init__(self, base_url, selenium): + Base.__init__(self, base_url, selenium) self._page_title = 'Search | Mozilla Support' @property def results(self): - return [self.SearchResult(self.testsetup, element) + return [self.SearchResult(self.base_url, self.selenium, element) for element in self.selenium.find_elements(*self._results_locator)] class SearchResult(Page): - def __init__(self, testsetup, element): - Page.__init__(self, testsetup) + def __init__(self, base_url, selenium, element): + Page.__init__(self, base_url, selenium) self._root_element = element def click(self): self._root_element.click() from pages.mobile.article import Article - return Article(self.testsetup) + return Article(self.base_url, self.selenium) diff --git a/pages/page.py b/pages/page.py index 8cbcc45..0f8a209 100644 --- a/pages/page.py +++ b/pages/page.py @@ -20,11 +20,10 @@ class Page(object): Base class for all Pages """ - def __init__(self, testsetup): - self.testsetup = testsetup - self.base_url = testsetup.base_url - self.selenium = testsetup.selenium - self.timeout = testsetup.timeout + def __init__(self, base_url, selenium): + self.base_url = base_url + self.selenium = selenium + self.timeout = 10 @property def is_the_current_page(self): @@ -56,7 +55,7 @@ def is_element_present(self, *locator): return False finally: # set back to where you once belonged - self.selenium.implicitly_wait(self.testsetup.default_implicit_wait) + self.selenium.implicitly_wait(10) def is_element_visible(self, *locator): try: diff --git a/requirements.txt b/requirements.txt index 45d148c..c2a3919 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ pytest==2.7.3 -pytest-mozwebqa +pytest-selenium pytest-variables requests==2.9.1 diff --git a/setup.cfg b/setup.cfg index 4da0770..b249b5b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,2 +1,6 @@ [flake8] -ignore=E501 \ No newline at end of file +ignore=E501 + +[pytest] +base_url=https://support.allizom.org +sensitive_url=mozilla\.org diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..326b6b5 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,17 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# 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 pytest + + +@pytest.fixture(scope='session') +def capabilities(capabilities): + capabilities.setdefault('tags', []).append('sumo') + return capabilities + + +@pytest.fixture +def selenium(selenium): + selenium.implicitly_wait(10) + return selenium diff --git a/tests/desktop/test_kb_article.py b/tests/desktop/test_kb_article.py index 5b80dbf..bda3994 100644 --- a/tests/desktop/test_kb_article.py +++ b/tests/desktop/test_kb_article.py @@ -8,14 +8,14 @@ class TestKnowledgeBaseArticle: - def test_that_article_can_be_created(self, mozwebqa, variables): + def test_that_article_can_be_created(self, base_url, selenium, variables): """ Creates a new knowledge base article. Verifies creation. Deletes the article """ user = variables['users']['admin'] - kb_new_article = PageProvider(mozwebqa).new_kb_article_page( + kb_new_article = PageProvider(base_url, selenium).new_kb_article_page( user['username'], user['password']) # create a new article @@ -37,7 +37,7 @@ def test_that_article_can_be_created(self, mozwebqa, variables): kb_article = kb_edit_article.navigation.click_show_history() kb_article.delete_entire_article_document() - def test_that_article_can_be_edited(self, mozwebqa, variables): + def test_that_article_can_be_edited(self, base_url, selenium, variables): """ Creates a new knowledge base article. Verifies creation. @@ -45,7 +45,7 @@ def test_that_article_can_be_edited(self, mozwebqa, variables): Deletes the article """ user = variables['users']['admin'] - kb_new_article = PageProvider(mozwebqa).new_kb_article_page( + kb_new_article = PageProvider(base_url, selenium).new_kb_article_page( user['username'], user['password']) # create a new article @@ -76,14 +76,14 @@ def test_that_article_can_be_edited(self, mozwebqa, variables): kb_article_history = kb_edit_article.navigation.click_show_history() kb_article_history.delete_entire_article_document() - def test_that_article_can_be_deleted(self, mozwebqa, variables): + def test_that_article_can_be_deleted(self, base_url, selenium, variables): """ Creates a new knowledge base article. Deletes the article. Verifies the deletion. """ user = variables['users']['admin'] - kb_new_article = PageProvider(mozwebqa).new_kb_article_page( + kb_new_article = PageProvider(base_url, selenium).new_kb_article_page( user['username'], user['password']) # create a new article @@ -104,14 +104,14 @@ def test_that_article_can_be_deleted(self, mozwebqa, variables): actual_page_title = kb_article_history.page_title assert "Page Not Found" in actual_page_title - def test_that_article_can_be_previewed_before_submitting(self, mozwebqa, variables): + def test_that_article_can_be_previewed_before_submitting(self, base_url, selenium, variables): """ Start a new knowledge base article. Preview. Verify the contents in the preview """ user = variables['users']['default'] - kb_new_article = PageProvider(mozwebqa).new_kb_article_page( + kb_new_article = PageProvider(base_url, selenium).new_kb_article_page( user['username'], user['password']) # create a new article @@ -125,13 +125,13 @@ def test_that_article_can_be_previewed_before_submitting(self, mozwebqa, variabl # Does not need to be deleted as it does not commit the article - def test_that_article_can_be_translated(self, mozwebqa, variables): + def test_that_article_can_be_translated(self, base_url, selenium, variables): """ Creates a new knowledge base article. Translate article """ user = variables['users']['admin'] - kb_new_article = PageProvider(mozwebqa).new_kb_article_page( + kb_new_article = PageProvider(base_url, selenium).new_kb_article_page( user['username'], user['password']) # create a new article diff --git a/tests/desktop/test_login_logout.py b/tests/desktop/test_login_logout.py index ef2b93f..8ac293f 100644 --- a/tests/desktop/test_login_logout.py +++ b/tests/desktop/test_login_logout.py @@ -11,9 +11,9 @@ class TestLoginLogout: @pytest.mark.nondestructive - def test_login(self, mozwebqa, variables): + def test_login(self, base_url, selenium, variables): user = variables['users']['default'] - home_page = PageProvider(mozwebqa).home_page() + home_page = PageProvider(base_url, selenium).home_page() home_page.sign_in(user['username'], user['password']) assert home_page.header.is_user_logged_in, 'User not shown to be logged in' @@ -28,9 +28,9 @@ def test_login(self, mozwebqa, variables): 'search_page', 'refine_search_page', ]) - def test_logout_from_pages(self, mozwebqa, variables, page_method): + def test_logout_from_pages(self, base_url, selenium, variables, page_method): user = variables['users']['default'] - page_under_test = getattr(PageProvider(mozwebqa), page_method)( + page_under_test = getattr(PageProvider(base_url, selenium), page_method)( user['username'], user['password']) assert page_under_test.header.is_user_logged_in, 'User not shown to be logged in' @@ -40,9 +40,9 @@ def test_logout_from_pages(self, mozwebqa, variables, page_method): assert page_under_test.header.is_user_logged_out @pytest.mark.native - def test_logout_from_new_kb_article_page(self, mozwebqa, variables): + def test_logout_from_new_kb_article_page(self, base_url, selenium, variables): user = variables['users']['default'] - new_kb_page = PageProvider(mozwebqa).new_kb_article_page( + new_kb_page = PageProvider(base_url, selenium).new_kb_article_page( user['username'], user['password']) assert new_kb_page.header.is_user_logged_in, 'User not shown to be logged in' @@ -52,9 +52,9 @@ def test_logout_from_new_kb_article_page(self, mozwebqa, variables): assert register_page.header.is_user_logged_out @pytest.mark.native - def test_logout_from_edit_kb_article_page(self, mozwebqa, variables): + def test_logout_from_edit_kb_article_page(self, base_url, selenium, variables): user = variables['users']['default'] - kb_new_article = PageProvider(mozwebqa).new_kb_article_page( + kb_new_article = PageProvider(base_url, selenium).new_kb_article_page( user['username'], user['password']) # create a new article @@ -71,9 +71,9 @@ def test_logout_from_edit_kb_article_page(self, mozwebqa, variables): assert register_page.header.is_user_logged_out @pytest.mark.native - def test_logout_from_translate_kb_article_page(self, mozwebqa, variables): + def test_logout_from_translate_kb_article_page(self, base_url, selenium, variables): user = variables['users']['default'] - kb_new_article = PageProvider(mozwebqa).new_kb_article_page( + kb_new_article = PageProvider(base_url, selenium).new_kb_article_page( user['username'], user['password']) # create a new article diff --git a/tests/desktop/test_new_user_registration.py b/tests/desktop/test_new_user_registration.py index b25d887..edd6673 100644 --- a/tests/desktop/test_new_user_registration.py +++ b/tests/desktop/test_new_user_registration.py @@ -8,12 +8,12 @@ class TestNewUserRegistration: - def test_that_thank_you_page_is_displayed_after_successful_registration(self, mozwebqa): + def test_that_thank_you_page_is_displayed_after_successful_registration(self, base_url, selenium): """ Register a new user using random username. Verify registration by checking the page title """ - register_pg = PageProvider(mozwebqa).new_user_registration_page() + register_pg = PageProvider(base_url, selenium).new_user_registration_page() register_pg.register_new_user() registration_text = register_pg.successful_registration_message diff --git a/tests/desktop/test_questions.py b/tests/desktop/test_questions.py index 993e7e8..7c253c6 100644 --- a/tests/desktop/test_questions.py +++ b/tests/desktop/test_questions.py @@ -11,7 +11,7 @@ class TestQuestions: @pytest.mark.native - def test_that_posting_question_works(self, mozwebqa, variables): + def test_that_posting_question_works(self, base_url, selenium, variables): """Posts a question to /questions""" user = variables['users']['default'] timestamp = datetime.datetime.today() @@ -19,7 +19,7 @@ def test_that_posting_question_works(self, mozwebqa, variables): q_details = "This is a test. %s" % (timestamp) # go to the /questions/new page and log in - ask_new_questions_page = PageProvider(mozwebqa).new_question_page( + ask_new_questions_page = PageProvider(base_url, selenium).new_question_page( user['username'], user['password']) # post a question @@ -34,14 +34,14 @@ def test_that_posting_question_works(self, mozwebqa, variables): assert q_details == view_question_pg.question_detail @pytest.mark.nondestructive - def test_that_questions_sorts_correctly_by_filter_equal_to_solved(self, mozwebqa): + def test_that_questions_sorts_correctly_by_filter_equal_to_solved(self, base_url, selenium): """ Goes to the /questions page, Verifies the sort filter=solved works """ expected_sorted_text = "SOLVED" - questions_page = PageProvider(mozwebqa).questions_page() + questions_page = PageProvider(base_url, selenium).questions_page() questions_page.click_all_products() questions_page.click_questions_done_tab() @@ -55,14 +55,14 @@ def test_that_questions_sorts_correctly_by_filter_equal_to_solved(self, mozwebqa assert 'highlighted' in question.solved_questions_filter @pytest.mark.nondestructive - def test_that_questions_sorts_correctly_by_filter_equal_to_unanswered(self, mozwebqa): + def test_that_questions_sorts_correctly_by_filter_equal_to_unanswered(self, base_url, selenium): """ Goes to the /questions page, Verifies the sort filter=unanswered works """ expected_sorted_text = "Unanswered" - questions_page = PageProvider(mozwebqa).questions_page() + questions_page = PageProvider(base_url, selenium).questions_page() questions_page.click_all_products() questions_page.click_all_questions_tab() @@ -74,11 +74,11 @@ def test_that_questions_sorts_correctly_by_filter_equal_to_unanswered(self, mozw for question in questions_page.questions: assert 0 == question.number_of_replies - def test_that_questions_problem_count_increments(self, mozwebqa): + def test_that_questions_problem_count_increments(self, base_url, selenium): """Checks if the 'I have this problem too' counter increments""" # Can't +1 your own question so will do it logged out - questions_page = PageProvider(mozwebqa).questions_page() + questions_page = PageProvider(base_url, selenium).questions_page() questions_page.click_all_products() view_question_page = questions_page.click_any_question(1) @@ -90,7 +90,7 @@ def test_that_questions_problem_count_increments(self, mozwebqa): assert initial_count + 1 == post_click_count - def test_contributor_flow_to_support_forum_post(self, mozwebqa, variables): + def test_contributor_flow_to_support_forum_post(self, base_url, selenium, variables): """ Shows a contributor can start on the home page and move all the way to answering a question in the forum. @@ -101,7 +101,7 @@ def test_contributor_flow_to_support_forum_post(self, mozwebqa, variables): # The questions page should list 20 posts. # 3.1 go to the question page user = variables['users']['default'] - questions_page = PageProvider(mozwebqa).questions_page( + questions_page = PageProvider(base_url, selenium).questions_page( user['username'], user['password']) questions_page.click_all_products() diff --git a/tests/desktop/test_rewrites.py b/tests/desktop/test_rewrites.py index 083cc68..10baf39 100644 --- a/tests/desktop/test_rewrites.py +++ b/tests/desktop/test_rewrites.py @@ -7,17 +7,16 @@ import urllib -@pytest.mark.skip_selenium @pytest.mark.nondestructive class TestRedirects: _user_agent_firefox = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:13.0) Gecko/20100101 Firefox/13.0.1' - def _check_redirect(self, testsetup, start_url, user_agent=_user_agent_firefox, locale='en-US'): - if 'support.mozilla.org' not in testsetup.base_url: + def _check_redirect(self, base_url, start_url, user_agent=_user_agent_firefox, locale='en-US'): + if 'support.mozilla.org' not in base_url: pytest.skip("Skipped per dev instructions on continuous deployment. To be run only on Prod") - start_url = testsetup.base_url + start_url + start_url = base_url + start_url headers = {'user-agent': user_agent, 'accept-language': locale} @@ -34,9 +33,9 @@ def _check_redirect(self, testsetup, start_url, user_agent=_user_agent_firefox, ('/1/firefox/4.0/Linux/en-US/firefox-f1/', '/en-US/products/firefox?as=u&utm_source=inproduct'), ('/1/firefox/4.0/Linux/en-US/firefox-osxkey/', '/en-US/products/firefox?as=u&utm_source=inproduct'), ]) - def test_browser_redirect_to_sumo(self, mozwebqa, input, expected): - expected_url = mozwebqa.base_url + expected - r = self._check_redirect(mozwebqa, input) + def test_browser_redirect_to_sumo(self, base_url, input, expected): + expected_url = base_url + expected + r = self._check_redirect(base_url, input) assert expected_url == urllib.unquote(r.url) assert requests.codes.ok == r.status_code @@ -48,23 +47,23 @@ def test_browser_redirect_to_sumo(self, mozwebqa, input, expected): ('/1/firefox/4.0/Darwin/en-US/prefs-clear-private-data/'), ('/1/firefox/4.0/Linux/en-US/prefs-clear-private-data/'), ('/1/firefox/4.0/WINNT/en-US/prefs-fonts-and-colors/')]) - def test_kb_redirects_status_ok(self, mozwebqa, input): - r = self._check_redirect(mozwebqa, input) + def test_kb_redirects_status_ok(self, base_url, input): + r = self._check_redirect(base_url, input) assert requests.codes.ok == r.status_code @pytest.mark.parametrize(('input', 'expected'), [ ('/1/mobile/4.0/android/en-US/firefox-help', '/en-US/products/mobile/popular-articles-android?as=u&utm_source=inproduct'), ('/1/mobile/4.0/iphone/en-US/firefox-help', '/en-US/products/mobile/popular-articles-android?as=u&utm_source=inproduct'), ('/1/mobile/4.0/nokia/en-US/firefox-help', '/en-US/products/mobile/popular-articles-android?as=u&utm_source=inproduct')]) - def test_old_mobile_redirects(self, mozwebqa, input, expected): - expected_url = mozwebqa.base_url + expected - r = self._check_redirect(mozwebqa, input) + def test_old_mobile_redirects(self, base_url, input, expected): + expected_url = base_url + expected + r = self._check_redirect(base_url, input) assert expected_url == urllib.unquote(r.url) assert requests.codes.ok == r.status_code @pytest.mark.parametrize(('input'), [ ('/1/firefox-home/4.0/iPhone/en-US'), ('/1/firefox-home/4.0/iPhone/en-US/log-in')]) - def test_iphone_kb_redirects_status_ok(self, mozwebqa, input): - r = self._check_redirect(mozwebqa, input) + def test_iphone_kb_redirects_status_ok(self, base_url, input): + r = self._check_redirect(base_url, input) assert requests.codes.ok == r.status_code diff --git a/tests/desktop/test_search.py b/tests/desktop/test_search.py index ccb653e..b596edd 100644 --- a/tests/desktop/test_search.py +++ b/tests/desktop/test_search.py @@ -11,12 +11,12 @@ class TestSearch: forum_search_term = "Firefox crash" @pytest.mark.nondestructive - def test_no_query_adv_forum_search(self, mozwebqa, variables): - if mozwebqa.base_url in ['https://support-dev.allizom.org', - 'https://support.mozilla.org']: - pytest.skip('Search results are not guaranteed to exist on %s' % mozwebqa.base_url) + def test_no_query_adv_forum_search(self, base_url, selenium, variables): + if base_url in ['https://support-dev.allizom.org', + 'https://support.mozilla.org']: + pytest.skip('Search results are not guaranteed to exist on %s' % base_url) - refine_search_pg = PageProvider(mozwebqa).refine_search_page() + refine_search_pg = PageProvider(base_url, selenium).refine_search_page() # do test refine_search_pg.click_support_questions_tab() @@ -27,17 +27,17 @@ def test_no_query_adv_forum_search(self, mozwebqa, variables): assert refine_search_pg.search_result_count > 0, "No search results not found" @pytest.mark.nondestructive - def test_user_flow_to_forum_post(self, mozwebqa): + def test_user_flow_to_forum_post(self, base_url, selenium): - if mozwebqa.base_url == 'https://support-dev.allizom.org': + if base_url == 'https://support-dev.allizom.org': pytest.skip('Search results are not guaranteed to exist on support-dev.allizom.org') # 1. start on the home page - PageProvider(mozwebqa).home_page() + PageProvider(base_url, selenium).home_page() # 2. type "Firefox crashed" # 3. hit Enter - search_pg = SearchPage(mozwebqa) + search_pg = SearchPage(base_url, selenium) search_pg.do_search_on_search_query(self.forum_search_term + "ed") # 4. In the results list there are two types of results: diff --git a/tests/desktop/test_switch_to_mobile_view.py b/tests/desktop/test_switch_to_mobile_view.py index abd0837..d4fb4e0 100644 --- a/tests/desktop/test_switch_to_mobile_view.py +++ b/tests/desktop/test_switch_to_mobile_view.py @@ -11,9 +11,9 @@ class TestMobileSite: @pytest.mark.nondestructive - def test_switch_to_mobile_view(self, mozwebqa): - home = PageProvider(mozwebqa).home_page() + def test_switch_to_mobile_view(self, base_url, selenium): + home = PageProvider(base_url, selenium).home_page() home.switch_to_mobile_view() - mobile = MobilePageProvider(mozwebqa).home_page() + mobile = MobilePageProvider(base_url, selenium).home_page() assert mobile.is_mobile_view_displayed diff --git a/tests/mobile/test_article.py b/tests/mobile/test_article.py index c8b1b26..f79b64b 100644 --- a/tests/mobile/test_article.py +++ b/tests/mobile/test_article.py @@ -8,8 +8,8 @@ class TestArticle: - def test_that_checks_the_vote_of_an_article(self, mozwebqa): - home = PageProvider(mozwebqa).home_page() + def test_that_checks_the_vote_of_an_article(self, base_url, selenium): + home = PageProvider(base_url, selenium).home_page() article_page = home.search_for('firefox').results[0].click() assert '| Mozilla Support' in article_page.page_title diff --git a/tests/mobile/test_homepage.py b/tests/mobile/test_homepage.py index 5162931..6c3fe1b 100644 --- a/tests/mobile/test_homepage.py +++ b/tests/mobile/test_homepage.py @@ -10,7 +10,7 @@ class TestHome: @pytest.mark.nondestructive - def test_the_expandable_header_menu(self, mozwebqa): + def test_the_expandable_header_menu(self, base_url, selenium): expected_menu_items = [u'Home', u'Ask a question', u'Support Forum', @@ -18,7 +18,7 @@ def test_the_expandable_header_menu(self, mozwebqa): u'Switch to desktop site', u'Sign in', u'Switch language'] - home = PageProvider(mozwebqa).home_page() + home = PageProvider(base_url, selenium).home_page() home.open_menu() assert home.is_menu_exposed, 'Menu is not open' @@ -29,8 +29,8 @@ def test_the_expandable_header_menu(self, mozwebqa): assert not home.is_menu_exposed, 'Menu is not closed' @pytest.mark.nondestructive - def test_the_header_text(self, mozwebqa): - home = PageProvider(mozwebqa).home_page() + def test_the_header_text(self, base_url, selenium): + home = PageProvider(base_url, selenium).home_page() home.is_the_current_page assert 'Products' == home.header_text diff --git a/tests/mobile/test_search.py b/tests/mobile/test_search.py index 73da029..6352756 100644 --- a/tests/mobile/test_search.py +++ b/tests/mobile/test_search.py @@ -10,15 +10,15 @@ class TestSearch: @pytest.mark.nondestructive - def test_that_positive_search_returns_results(self, mozwebqa): - home = PageProvider(mozwebqa).home_page() + def test_that_positive_search_returns_results(self, base_url, selenium): + home = PageProvider(base_url, selenium).home_page() search_page = home.search_for('firefox') assert len(search_page.results) > 0, 'No search results found' @pytest.mark.nondestructive - def test_that_negative_search_does_not_return_results(self, mozwebqa): - home = PageProvider(mozwebqa).home_page() + def test_that_negative_search_does_not_return_results(self, base_url, selenium): + home = PageProvider(base_url, selenium).home_page() search_page = home.search_for('frfx') assert 0 == len(search_page.results), 'Search results found but none expected'