Skip to content
This repository has been archived by the owner on Sep 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' of https://bebef1987@github.com/mozilla/Addon-T…
Browse files Browse the repository at this point in the history
…ests.git into tests_7857_4859
  • Loading branch information
bebef1987 committed Jul 14, 2011
2 parents 66dbc11 + ea1d874 commit 9d88b22
Show file tree
Hide file tree
Showing 8 changed files with 338 additions and 23 deletions.
51 changes: 50 additions & 1 deletion addons_search_home_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# the Initial Developer. All Rights Reserved.
#
# Contributor(s): Bebe <florin.strugariu@softvision.ro>
# Alex Rodionov <p0deje@gmail.com>
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
Expand All @@ -35,10 +36,12 @@
#
# ***** END LICENSE BLOCK *****

from time import strptime, mktime

from addons_base_page import AddonsBasePage
from page import Page
import addons_site
import refine_results_region
import refine_results_region

class AddonsSearchHomePage(AddonsBasePage):

Expand All @@ -50,6 +53,13 @@ class AddonsSearchHomePage(AddonsBasePage):
_previous_link_locator = "link=Prev"

_breadcrumbs_locator = "css=ol.breadcrumbs"

_sort_by_keyword_match_locator = "css=div.listing-header a:contains('Keyword Match')"
_sort_by_created_locator = "css=div.listing-header a:contains('Created')"
_sort_by_updated_locator = "css=div.listing-header a:contains('Updated')"
_sort_by_rating_locator = "css=div.listing-header a:contains('Rating')"
_sort_by_downloads_locator = "css=div.listing-header a:contains('Downloads')"
_sort_by_users_locator = "css=div.listing-header a:contains('Users')"

def page_forward(self):
self.selenium.click(self._next_link_locator)
Expand Down Expand Up @@ -87,6 +97,11 @@ def click_addon(self, addon_name):
self.selenium.click("link=" + addon_name)
return addons_site.AddonsDetailsPage(self.testsetup, addon_name)

def sort_by(self, type):
self.selenium.click(getattr(self, '_sort_by_%s_locator' % type))
self.selenium.wait_for_page_to_load(self.timeout)
return self

def result(self, lookup):
return self.Result(self.testsetup, lookup)

Expand All @@ -111,6 +126,7 @@ def root_locator(self):
return "css=div.results-inner div.item:nth(%s)" % self.lookup
else:
# lookup by name

return "css=div.results-inner div.item:contains(%s)" % self.lookup

@property
Expand All @@ -120,3 +136,36 @@ def name(self):
def click(self):
self.selenium.click(self.absolute_locator(self._name_locator))
self.selenium.wait_for_page_to_load(self.timeout)

@property
def downloads(self):
locator = self.root_locator + ' div.item-info p.downloads strong'
return int(self.selenium.get_text(locator).replace(',', ''))

@property
def users(self):
""" Alias for self.downloads """
return self.downloads

@property
def rating(self):
locator = self.root_locator + ' div.item-info p.addon-rating span span'
return int(self.selenium.get_text(locator))

@property
def created_date(self):
""" Returns created date of result in POSIX format """
locator = self.root_locator + ' div.item-info p.updated'
date = self.selenium.get_text(locator).strip().replace('Added ', '')
# convert to POSIX format
date = strptime(date, '%B %d, %Y')
return mktime(date)

@property
def updated_date(self):
""" Returns updated date of result in POSIX format """
locator = self.root_locator + ' div.item-info p.updated'
date = self.selenium.get_text(locator).strip().replace('Updated ', '')
# convert to POSIX format
date = strptime(date, '%B %d, %Y')
return mktime(date)
27 changes: 24 additions & 3 deletions addons_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

from addons_base_page import AddonsBasePage
import addons_search_home_page
import image_viewer_region


class AddonsHomePage(AddonsBasePage):
Expand Down Expand Up @@ -220,6 +221,10 @@ class AddonsDetailsPage(AddonsHomePage):
_addon_rating_locator = "css=span[itemprop='rating']"
_whats_this_license_locator = "css=h5 > span > a"
_description_locator = "css=div[class='article userinput'] > p"
_featured_image_locator = "css=#addon .featured .screenshot"

#more about this addon
_additional_images_locator = "css=#addon .article .screenshot"
_website_locator = "css=div#addon-summary tr:contains('Website') a"

_other_addons_by_authors_locator = "css=div.other-author-addons"
Expand Down Expand Up @@ -265,14 +270,14 @@ def click_whats_this_license(self):
@property
def description(self):
return self.selenium.get_text(self._description_locator)

@property
def website(self):
return self.selenium.get_text(self._website_locator)

def click_website_link(self):
self.selenium.open(self.website)

@property
def other_addons_by_authors_text(self):
return self.selenium.get_text("%s > h4" % self._other_addons_by_authors_locator)
Expand Down Expand Up @@ -301,6 +306,22 @@ def click_other_addon_by_this_author(self, value):
self.selenium.click('%s:contains(%s) a' % (self._other_addons_link_list_locator, value))
self.selenium.wait_for_page_to_load(self.timeout)

def click_addon_image(self):
self.selenium.click(self._featured_image_locator)
image_viewer = image_viewer_region.ImageViewer(self.testsetup)
image_viewer.wait_for_viewer_to_finish_animating()
return image_viewer

@property
def additional_images_count(self):
return self.selenium.get_css_count(self._additional_images_locator)

def click_additional_image(self, index):
self.selenium.click("%s:nth(%s)" % (self._additional_images_locator, index - 1))
image_viewer = image_viewer_region.ImageViewer(self.testsetup)
image_viewer.wait_for_viewer_to_finish_animating()
return image_viewer


class AddonsThemesPage(AddonsHomePage):

Expand Down
80 changes: 63 additions & 17 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,41 @@
#
# ***** END LICENSE BLOCK *****

import json

import pytest
import py
from selenium import selenium


def pytest_runtest_setup(item):
item.host = item.config.option.hub
item.browser = item.config.option.browser
item.host = item.config.option.host
item.port = item.config.option.port
TestSetup.base_url = item.config.option.site
item.browser_name = item.config.option.browser_name
item.browser_version = item.config.option.browser_version
item.platform = item.config.option.platform
TestSetup.base_url = item.config.option.base_url
TestSetup.timeout = item.config.option.timeout
TestSetup.credentials = item.config.option.credentialsfile
item.sauce_labs_username = item.config.option.sauce_labs_username
item.sauce_labs_api = item.config.option.sauce_labs_api

if not 'skip_selenium' in item.keywords:
TestSetup.skip_selenium = False
TestSetup.selenium = selenium(item.host, item.port,
item.browser, TestSetup.base_url)
if item.sauce_labs_username:
TestSetup.selenium = selenium('ondemand.saucelabs.com', '80',
json.dumps({
'username': item.sauce_labs_username,
'access-key': item.sauce_labs_api,
'os': item.platform,
'browser': item.browser_name,
'browser-version': item.browser_version,
'name': item.keywords.keys()[0],
'public': True,
'tags': ['amo']}),
TestSetup.base_url)
else:
TestSetup.selenium = selenium(item.host, item.port, item.browser_name, TestSetup.base_url)

if item.config.option.capturenetwork:
TestSetup.selenium.start("captureNetworkTraffic=true")
Expand Down Expand Up @@ -82,18 +100,46 @@ def pytest_funcarg__testsetup(request):


def pytest_addoption(parser):
parser.addoption("--hub", action="store", default="localhost",
help="specify where to run")
parser.addoption("--port", action="store", default="4444",
help="specify where to run")
parser.addoption("--browser", action="store", default="*firefox",
help="specify the browser")
parser.addoption("--site", action="store", default="http://addons.allizom.org",
help="specify the AUT")
parser.addoption("--timeout", action="store", default=120000,
help="specify the timeout")
parser.addoption("--capturenetwork", action="store_true", default=False,
help="tells the Selenium server to capture the network traffic. this will store the results in test_method_name.json")
parser.addoption("--host",
action="store",
default="localhost",
help="host that Selenium server is listening on")
parser.addoption("--port",
action="store",
default="4444",
help="port that Selenium server is listening on")
parser.addoption("--browser-name",
action="store",
dest="browser_name",
help="target browser")
parser.addoption("--browser-version",
action="store",
dest="browser_version",
help="target browser version")
parser.addoption("--platform",
action="store",
help="target platform")
parser.addoption("--base-url",
action="store",
dest="base_url",
default="http://addons.allizom.org",
help="base URL for the application under test")
parser.addoption("--timeout",
action="store",
default=120000,
help="timeout for page loads, etc")
parser.addoption("--capturenetwork",
action="store_true",
default=False,
help="tells the Selenium server to capture the network traffic. this will store the results in test_method_name.json")
parser.addoption("--sauce-labs-username",
action="store",
dest="sauce_labs_username",
help="sauce labs username")
parser.addoption("--sauce-labs-api",
action="store",
dest="sauce_labs_api",
help="sauce labs api key")
parser.addoption("--credentialsfile", action="store", default="credentials.yaml",
help="provide the credentials filename")

Expand Down
111 changes: 111 additions & 0 deletions image_viewer_region.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#!/usr/bin/env python

# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is Mozilla WebQA Selenium Tests.
#
# The Initial Developer of the Original Code is
# Mozilla.
# Portions created by the Initial Developer are Copyright (C) 2011
# the Initial Developer. All Rights Reserved.
#
# Contributor(s): Bebe <florin.strugariu@softvision.ro>
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
from page import Page


class ImageViewer(Page):

_overlay_locator = "id=jquery-overlay"
_viewer_locator = "id=jquery-lightbox"
_image_locator = "id=lightbox-image"
_image_data_locator = "id=lightbox-container-image-data"
_loading_locator = "id=lightbox-loading"

#information
_caption_locator = "id=lightbox-image-details-caption"
_current_number_locator = "id=lightbox-image-details-currentNumber"

#navigation
_next_locator = "id=lightbox-nav-btnNext"
_previous_locator = "id=lightbox-nav-btnPrev"
_close_locator = "id=lightbox-secNav-btnClose"

@property
def is_visible(self):
try:
return self.selenium.is_visible(self._viewer_locator)
except:
pass
return False

def wait_for_viewer_to_finish_animating(self):
self.wait_for_element_not_visible(self._image_data_locator)
self.wait_for_element_visible(self._image_data_locator)

#information
@property
def caption(self):
return self.get_text(self._caption_locator)

@property
def current_number(self):
return self.selenium.get_text(self._current_number_locator)

@property
def current_image(self):
return int(self.current_number.split(' ')[1])

@property
def total_images_count(self):
return int(self.current_number.split(' ')[3])

#navigation
def close(self):
self.selenium.click(self._close_locator)
self.wait_for_element_not_present(self._viewer_locator)

@property
def is_close_visible(self):
return self.selenium.is_visible(self._close_locator)

def click_next(self):
self.selenium.click(self._next_locator)
self.wait_for_viewer_to_finish_animating()

@property
def is_next_link_visible(self):
return self.selenium.is_visible(self._next_locator)

def click_previous(self):
self.selenium.click(self._previous_locator)
self.wait_for_viewer_to_finish_animating()


@property
def is_previous_link_visible(self):
return self.selenium.is_visible(self._previous_locator)
9 changes: 9 additions & 0 deletions page.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ def wait_for_element_present(self, element):
self.record_error()
raise Exception(element + ' has not loaded')

def wait_for_element_not_present(self, element):
count = 0
while self.selenium.is_element_present(element):
time.sleep(1)
count += 1
if count == self.timeout / 1000:
self.record_error()
raise Exception(element + ' is still loaded')

def wait_for_element_visible(self, element):
self.wait_for_element_present(element)
count = 0
Expand Down
Loading

0 comments on commit 9d88b22

Please sign in to comment.