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

Commit

Permalink
Migrate to pytest-selenium
Browse files Browse the repository at this point in the history
  • Loading branch information
davehunt committed Feb 5, 2016
1 parent 4cc0037 commit 5dd5723
Show file tree
Hide file tree
Showing 47 changed files with 299 additions and 285 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
__pycache__
.cache
*.pyc
results/*
.DS_Store
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,25 +97,25 @@ the tests:
To run all of the desktop tests against the default environment:

```bash
$ py.test --driver firefox --variables my_variables.json tests/desktop
$ py.test --driver Firefox --variables my_variables.json tests/desktop
```

To run against a different environment, pass in a value for --baseurl, like so:
To run against a different environment, pass in a value for `--base-url`, like so:

```bash
$ py.test --baseurl https://marketplace.allizom.org --driver firefox --variables my_variables.json tests/desktop
$ py.test --base-url https://marketplace.allizom.org --driver Firefox --variables my_variables.json tests/desktop
```

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-mozwebqa].
[here][pytest-selenium].

[contributors]: https://github.com/mozilla/Addon-Tests/contributors
[git-clone]: https://help.github.com/articles/cloning-a-repository/
[git-fork]: https://help.github.com/articles/fork-a-repo/
[irc]: http://widget01.mibbit.com/?settings=1b10107157e79b08f2bf99a11f521973&server=irc.mozilla.org&channel=%23mozwebqa
[list]: https://mail.mozilla.org/listinfo/mozwebqa
[pytest-mozwebqa]: https://github.com/mozilla/pytest-mozwebqa
[pytest-selenium]: https://github.com/mozilla/pytest-selenium
[running-tests]: https://developer.mozilla.org/en-US/docs/Mozilla/QA/Running_Web_QA_automated_tests
[virtualenv]: https://wiki.mozilla.org/QA/Execution/Web_Testing/Automation/Virtual_Environments
20 changes: 16 additions & 4 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,22 @@
from mocks.mock_application import MockApplication


@pytest.fixture(scope='session')
def capabilities(capabilities):
capabilities.setdefault('tags', []).append('marketplace')
return capabilities


@pytest.fixture
def selenium(selenium):
selenium.implicitly_wait(10)
return selenium


@pytest.fixture
def fxa_test_account(mozwebqa):
def fxa_test_account(base_url):
prod_hosts = ['marketplace.firefox.com', 'marketplace.allizom.org']
api_url = PROD_URL if urlparse(mozwebqa.base_url).hostname in prod_hosts else DEV_URL
api_url = PROD_URL if urlparse(base_url).hostname in prod_hosts else DEV_URL
return FxATestAccount(api_url)


Expand All @@ -36,8 +48,8 @@ def existing_user(stored_users):


@pytest.fixture
def api(existing_user, mozwebqa):
host = urlparse(mozwebqa.base_url).hostname
def api(existing_user, base_url):
host = urlparse(base_url).hostname
key = existing_user['api'][host]['key']
secret = existing_user['api'][host]['secret']
return MarketplaceAPI(key, secret, host)
Expand Down
3 changes: 0 additions & 3 deletions mozwebqa.cfg

This file was deleted.

2 changes: 1 addition & 1 deletion pages/desktop/consumer_pages/account_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def click_expand_button(self):

@property
def apps(self):
return [self.Apps(self.testsetup, web_element)
return [self.Apps(self.base_url, self.selenium, web_element)
for web_element in self.selenium.find_elements(*self._my_apps_list_locator)]

class Apps(PageRegion):
Expand Down
2 changes: 1 addition & 1 deletion pages/desktop/consumer_pages/add_review.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def write_a_review(self, rating, body):
self.selenium.find_element(*self._submit_review_button_locator).click()
self.wait_for_notification('Your review was successfully posted. Thanks!')
from pages.desktop.consumer_pages.details import Details
return Details(self.testsetup)
return Details(self.base_url, self.selenium)

@property
def is_review_box_visible(self):
Expand Down
26 changes: 13 additions & 13 deletions pages/desktop/consumer_pages/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def wait_for_notification(self, message=None):
def go_to_debug_page(self):
self.header.search(':debug')
from pages.desktop.regions.debug import Debug
return Debug(self.testsetup)
return Debug(self.base_url, self.selenium)

def set_region(self, region):
debug_page = self.go_to_debug_page()
Expand All @@ -51,17 +51,17 @@ def set_region(self, region):

def login(self, email, password):
from fxapom.pages.sign_in import SignIn
fxa_login = SignIn(self.testsetup)
fxa_login = SignIn(self.base_url, self.selenium)
fxa_login.sign_in(email, password)
self.wait_for_notification()

@property
def header(self):
return self.HeaderRegion(self.testsetup)
return self.HeaderRegion(self.base_url, self.selenium)

@property
def footer(self):
return self.FooterRegion(self.testsetup)
return self.FooterRegion(self.base_url, self.selenium)

class HeaderRegion(Page):

Expand Down Expand Up @@ -98,7 +98,7 @@ def open_categories_menu(self):
@property
def categories(self):
categories = self.selenium.find_elements(*self._categories_locator)
return [self.Category(self.testsetup, element) for element in categories]
return [self.Category(self.base_url, self.selenium, element) for element in categories]

def open_settings_menu(self):
settings_menu = self.selenium.find_element(*self._settings_menu_locator)
Expand All @@ -120,13 +120,13 @@ def click_edit_account_settings(self):
self.open_settings_menu()
self.selenium.find_element(*self._settings_menu_item_locator).click()
from pages.desktop.consumer_pages.account_settings import BasicInfo
return BasicInfo(self.testsetup)
return BasicInfo(self.base_url, self.selenium)

def click_my_apps(self):
self.open_settings_menu()
self.selenium.find_element(*self._my_apps_menu_locator).click()
from pages.desktop.consumer_pages.account_settings import My_Apps
return My_Apps(self.testsetup)
return My_Apps(self.base_url, self.selenium)

def search(self, search_term):
"""
Expand All @@ -142,7 +142,7 @@ def search(self, search_term):
search_field.send_keys(search_term)
search_field.submit()
from pages.desktop.consumer_pages.search import Search
return Search(self.testsetup, search_term)
return Search(self.base_url, self.selenium, search_term)

def search_and_click_on_app(self, search_term):

Expand All @@ -163,7 +163,7 @@ def type_search_term_in_search_field(self, search_term):

@property
def search_suggestions(self):
return [self.SearchSuggestion(self.testsetup, web_element)
return [self.SearchSuggestion(self.base_url, self.selenium, web_element)
for web_element in self.selenium.find_elements(*self._search_suggestions_list_locator)]

@property
Expand Down Expand Up @@ -195,8 +195,8 @@ class SearchSuggestion(Page):

_app_name_locator = (By.CSS_SELECTOR, 'a > span')

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
Expand All @@ -205,7 +205,7 @@ def app_name(self):

@property
def menu(self):
return self.Menu(self.testsetup)
return self.Menu(self.base_url, self.selenium)

class Category(PageRegion):

Expand All @@ -219,7 +219,7 @@ def click(self):
name = self.name
self.find_element(*self._link_locator).click()
from pages.desktop.consumer_pages.category import Category
return Category(self.testsetup, name)
return Category(self.base_url, self.selenium, name)

class FooterRegion(Page):

Expand Down
6 changes: 3 additions & 3 deletions pages/desktop/consumer_pages/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class Category(Base):
_category_section_title_locator = (By.CSS_SELECTOR, '.subheader > h1')
_category_apps_locator = (By.CSS_SELECTOR, '.item.result.app-list-app')

def __init__(self, testsetup, category_name):
Base.__init__(self, testsetup)
def __init__(self, base_url, selenium, category_name):
Base.__init__(self, base_url, selenium)
self.wait_for_page_to_load()
WebDriverWait(self.selenium, self.timeout).until(lambda s: category_name.title() == self.category_title)
WebDriverWait(self.selenium, self.timeout).until(lambda s: len(self.apps) > 0)
Expand All @@ -45,7 +45,7 @@ def is_new_popular_tabs_visible(self):

@property
def apps(self):
return [self.CategoryApp(self.testsetup, web_element)
return [self.CategoryApp(self.base_url, self.selenium, web_element)
for web_element in self.selenium.find_elements(*self._category_apps_locator)]

class CategoryApp(PageRegion):
Expand Down
20 changes: 10 additions & 10 deletions pages/desktop/consumer_pages/details.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class Details(Base):
_report_abuse_box_locator = (By.CSS_SELECTOR, '.abuse-form')
_app_price_locator = (By.CSS_SELECTOR, '.button.mkt-app-button.install > em')

def __init__(self, testsetup, app_name=None):
Base.__init__(self, testsetup)
def __init__(self, base_url, selenium, app_name=None):
Base.__init__(self, base_url, selenium)
self.wait_for_page_to_load()
self.app_name = app_name

Expand Down Expand Up @@ -102,17 +102,17 @@ def click_install_button(self):
self.selenium.find_element(*self._install_locator).click()
WebDriverWait(self.selenium, self.timeout).until(lambda s: 'purchasing' in self.app_status)
from pages.desktop.payment.payment_popup import Payment
return Payment(self.testsetup)
return Payment(self.base_url, self.selenium)

def click_review_button(self, edit_review=False):
review_button = self.selenium.find_element(*self._review_button_locator)
self.scroll_to_element(review_button)
review_button.click()
if not edit_review:
from pages.desktop.consumer_pages.add_review import AddReview
return AddReview(self.testsetup)
return AddReview(self.base_url, self.selenium)
from pages.desktop.consumer_pages.edit_review import EditReview
return EditReview(self.testsetup)
return EditReview(self.base_url, self.selenium)

def wait_for_app_purchased(self):
WebDriverWait(self.selenium, self.timeout).until(lambda s: 'purchased' in self.app_status)
Expand Down Expand Up @@ -146,7 +146,7 @@ def first_review_body(self):
def click_all_reviews_button(self):
self.selenium.find_element(*self._reviews_button_locator).click()
from pages.desktop.consumer_pages.reviews import Reviews
return Reviews(self.testsetup)
return Reviews(self.base_url, self.selenium)

@property
def is_report_abuse_button_visible(self):
Expand All @@ -161,13 +161,13 @@ def click_report_abuse_button(self):
@property
def report_abuse_box(self):
report_abuse_box = self.find_element(*self._report_abuse_box_locator)
return self.ReportAbuseRegion(self.testsetup, report_abuse_box)
return self.ReportAbuseRegion(self.base_url, self.selenium, report_abuse_box)

def click_content_ratings_button(self):
content_ratings_button = self.selenium.find_element(*self._content_ratings_button_locator)
self.scroll_to_element(content_ratings_button)
content_ratings_button.click()
return GlobalRatings(self.testsetup)
return GlobalRatings(self.base_url, self.selenium)

def wait_for_ratings_image_visible(self):
self.wait_for_element_visible(*self._content_ratings_image_locator)
Expand Down Expand Up @@ -207,8 +207,8 @@ class GlobalRatings(Base):

_content_ratings_table_locator = (By.CSS_SELECTOR, '.ratingsguide')

def __init__(self, testsetup):
Base.__init__(self, testsetup)
def __init__(self, base_url, selenium):
Base.__init__(self, base_url, selenium)

if self.selenium.title != self._page_title:
for handle in self.selenium.window_handles:
Expand Down
2 changes: 1 addition & 1 deletion pages/desktop/consumer_pages/edit_review.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ def write_a_review(self, rating, body):
self.selenium.find_element(*self._submit_review_button_locator).click()
self.wait_for_notification('Your review was successfully edited')
from pages.desktop.consumer_pages.details import Details
return Details(self.testsetup)
return Details(self.base_url, self.selenium)
10 changes: 5 additions & 5 deletions pages/desktop/consumer_pages/reviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class Reviews(Base):

_review_locator = (By.CSS_SELECTOR, '.review')

def __init__(self, testsetup, app_name=None):
Base.__init__(self, testsetup)
def __init__(self, base_url, selenium, app_name=None):
Base.__init__(self, base_url, selenium)
self.wait_for_page_to_load()
self.app_name = app_name

Expand All @@ -28,7 +28,7 @@ def _page_title(self):
@property
def reviews(self):
"""Returns review object with index."""
return [self.Review(self.testsetup, web_element)
return [self.Review(self.base_url, self.selenium, web_element)
for web_element in self.selenium.find_elements(*self._review_locator)]

def get_review_for_user(self, user_name):
Expand All @@ -51,8 +51,8 @@ class Review(Base):
_delete_review_locator = (By.CSS_SELECTOR, '.delete')
_edit_review_locator = (By.CSS_SELECTOR, '.edit')

def __init__(self, testsetup, element):
Base.__init__(self, testsetup)
def __init__(self, base_url, selenium, element):
Base.__init__(self, base_url, selenium)
self._root_element = element

@property
Expand Down
8 changes: 4 additions & 4 deletions pages/desktop/consumer_pages/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class Search(Base, Filter):
_applied_filters_locator = (By.CSS_SELECTOR, '.applied-filters > ol > li > a')
_search_results_section_title_locator = (By.CSS_SELECTOR, '.search-results-header-desktop')

def __init__(self, testsetup, app_name=None):
Base.__init__(self, testsetup)
def __init__(self, base_url, selenium, app_name=None):
Base.__init__(self, base_url, selenium)
self.app_name = app_name

@property
Expand All @@ -42,7 +42,7 @@ def click_expand_button(self):

@property
def results(self):
return [self.SearchResult(self.testsetup, web_element)
return [self.SearchResult(self.base_url, self.selenium, web_element)
for web_element in self.find_elements(*self._results_locator)]

class SearchResult(PageRegion):
Expand Down Expand Up @@ -79,4 +79,4 @@ def click_name(self):
name = self.name
self.find_element(*self._name_locator).click()
from pages.desktop.consumer_pages.details import Details
return Details(self.testsetup, name)
return Details(self.base_url, self.selenium, name)
Loading

0 comments on commit 5dd5723

Please sign in to comment.