Skip to content

Commit

Permalink
Merge pull request mozilla#6 from tobbi/newTimeoutParameter
Browse files Browse the repository at this point in the history
New timeout parameter
  • Loading branch information
m8ttyB committed Aug 11, 2011
2 parents c0c7451 + 24eaea9 commit c1a45c3
Show file tree
Hide file tree
Showing 9 changed files with 234 additions and 231 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.swp
*.pyc
*.tmproj
*.komodoproject
60 changes: 51 additions & 9 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,41 @@
#!/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 Firefox Input.
#
# The Initial Developer of the Original Code is
# Mozilla Corp.
# Portions created by the Initial Developer are Copyright (C) 2011
# the Initial Developer. All Rights Reserved.
#
# Contributor(s): David Burns
# Dave Hunt <dhunt@mozilla.com>
# Matt Brandt <mbrandt@mozilla.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
# 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 *****
import pytest
import py
from selenium import selenium
Expand All @@ -6,20 +44,22 @@ def pytest_runtest_setup(item):
item.host = item.config.option.hub
item.browser = item.config.option.browser
item.port = item.config.option.port
SeleniumSetup.base_url = item.config.option.site
TestSetup.base_url = item.config.option.site
TestSetup.timeout = item.config.option.timeout

if not 'skip_selenium' in item.keywords:
SeleniumSetup.selenium = selenium(item.host, item.port,
item.browser, SeleniumSetup.base_url)
TestSetup.selenium = selenium(item.host, item.port,
item.browser, TestSetup.base_url)

SeleniumSetup.selenium.start()
TestSetup.selenium.start()
TestSetup.selenium.set_timeout(TestSetup.timeout)

def pytest_runtest_teardown(item):
if not 'skip_selenium' in item.keywords:
SeleniumSetup.selenium.stop()
TestSetup.selenium.stop()

def pytest_funcarg__seleniumsetup(request):
return SeleniumSetup(request)
def pytest_funcarg__testsetup(request):
return TestSetup(request)


def pytest_addoption(parser):
Expand All @@ -29,10 +69,12 @@ def pytest_addoption(parser):
help="specify where to run")
parser.addoption("--browser", action="store", default="*firefox",
help="specify the browser")
parser.addoption("--site", action="store", default=None,
parser.addoption("--site", action="store", default="https://crash-stats.allizom.org",
help="specify the AUT")
parser.addoption("--timeout", action="store", type="int", default=120000,
help="specify the timeout")

class SeleniumSetup:
class TestSetup:
def __init__(self, request):
self.request = request

76 changes: 38 additions & 38 deletions crash_stats_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@
import time
import base64
from page import Page
from vars import ConnectionParameters


class CrashStatsBasePage(Page):

_page_heading = 'css=div.page-heading > h2'

def __init__(self, selenium):
self.sel = selenium
def __init__(self, testsetup):
Page.__init__(self, testsetup)
self.sel = self.selenium

@property
def page_title(self):
Expand All @@ -70,41 +70,41 @@ def select_product(self, application):
Select the Mozilla Product you want to report on
'''
self.sel.select(self._product_select, application)
self.sel.wait_for_page_to_load(ConnectionParameters.page_load_timeout)
self.sel.wait_for_page_to_load(self.timeout)

def select_version(self, version):
'''
Select the version of the application you want to report on
'''
self.sel.select(self._product_version_select, version)
self.sel.wait_for_page_to_load(ConnectionParameters.page_load_timeout)
self.sel.wait_for_page_to_load(self.timeout)

def select_report(self, report_name):
'''
Select the report type from the drop down
and wait for the page to reload
'''
self.sel.select(self._report_select, report_name)
self.sel.wait_for_page_to_load(ConnectionParameters.page_load_timeout)
self.sel.wait_for_page_to_load(self.timeout)
if 'Top Crashers' == report_name:
return CrashStatsTopCrashers(self.sel)
return CrashStatsTopCrashers(self.testsetup)
elif 'Top Crashers by Domain' == report_name:
return CrashStatsTopCrashersByDomain(self.sel)
return CrashStatsTopCrashersByDomain(self.testsetup)
elif 'Top Crashers by URL' == report_name:
return CrashStatsTopCrashersByUrl(self.sel)
return CrashStatsTopCrashersByUrl(self.testsetup)
elif 'Top Crashers by TopSite' == report_name:
return CrashStatsTopCrashersBySite(self.sel)
return CrashStatsTopCrashersBySite(self.testsetup)
elif 'Crashes per User' == report_name:
return CrashStatsPerActiveDailyUser(self.sel)
return CrashStatsPerActiveDailyUser(self.testsetup)

def click_server_status(self):
self.sel.click('link=Server Status')
self.sel.wait_for_page_to_load(ConnectionParameters.page_load_timeout)
return CrashStatsStatus(self.sel)
self.sel.wait_for_page_to_load(self.timeout)
return CrashStatsStatus(self.testsetup)

def click_advanced_search(self):
self.sel.click('link=Advanced Search')
return CrashStatsAdvancedSearch(self.sel)
return CrashStatsAdvancedSearch(self.testsetup)

def can_find_text(self, text_to_search):
'''
Expand Down Expand Up @@ -178,11 +178,11 @@ class CrashStatsHomePage(CrashStatsBasePage):
_top_changers_selected = _top_changers + '.selected'


def __init__(self, selenium):
def __init__(self, testsetup):
'''
Creates a new instance of the class and gets the page ready for testing
'''
self.sel = selenium
CrashStatsBasePage.__init__(self, testsetup)
self.sel.open('/')
count = 0
while not re.search(r'http?\w://.*/products/.*', self.sel.get_location(), re.U):
Expand All @@ -194,15 +194,15 @@ def __init__(self, selenium):

if not self.sel.get_title() == 'Crash Data for Firefox':
self.sel.select(self.product_select, 'Firefox')
self.sel.wait_for_page_to_load(ConnectionParameters.page_load_timeout)
self.sel.wait_for_page_to_load(self.timeout)
self.sel.window_maximize()

def report_length(self, days):
'''
Click on the link with the amount of days you want the report to be
'''
self.sel.click('link=' + days + ' days')
self.sel.wait_for_page_to_load(ConnectionParameters.page_load_timeout)
self.sel.wait_for_page_to_load(self.timeout)
self.wait_for_element_present('xpath=//a[text()="'
+ days + ' days" and @class="selected"]')

Expand All @@ -213,8 +213,8 @@ def search_for_crash(self, crash_id_or_signature):
self.sel.type(self._find_crash_id_or_signature, crash_id_or_signature)
self.sel.key_press(self._find_crash_id_or_signature, "\\13")
#self.sel.submit('//form')
self.sel.wait_for_page_to_load(ConnectionParameters.page_load_timeout)
return CrashStatsSearchResults(self.sel)
self.sel.wait_for_page_to_load(self.timeout)
return CrashStatsSearchResults(self.testsetup)

def click_on_top_(self, element):
topElement = 'link=Top ' + element
Expand Down Expand Up @@ -256,24 +256,24 @@ class CrashStatsAdvancedSearch(CrashStatsBasePage):
_data_table = 'id=signatureList'
_data_table_first_signature = 'css=table#signatureList > tbody > tr > td > a'

def __init__(self, selenium):
def __init__(self, testsetup):
'''
Creates a new instance of the class and gets the page ready for testing
'''
self.sel = selenium
CrashStatsBasePage.__init__(self, testsetup)
count = 0
self.wait_for_element_present(self._product_multiple_select)

def filter_reports(self):
self.sel.click(self._filter_crash_reports_button)
self.sel.wait_for_page_to_load(ConnectionParameters.page_load_timeout)
self.sel.wait_for_page_to_load(self.timeout)
# self.wait_for_element_present('css=div.page-heading > h2')

def click_first_signature(self):
self.wait_for_element_present(self._data_table_first_signature)
signature = self.sel.get_text(self._data_table_first_signature)
self.sel.click(self._data_table_first_signature)
self.sel.wait_for_page_to_load(ConnectionParameters.page_load_timeout)
self.sel.wait_for_page_to_load(self.timeout)
return signature

@property
Expand All @@ -292,20 +292,20 @@ class CrashStatsSearchResults(CrashStatsBasePage):
_os_select = 'id=platform'
_filter_crash_reports_button = 'id=query_submit'

def __init__(self, selenium):
self.sel = selenium
def __init__(self, testsetup):
self.sel = testsetup.selenium
self.wait_for_element_present(self._product_select)


class CrashStatsPerActiveDailyUser(CrashStatsBasePage):

_product_select = 'id=daily_search_version_form_products'

def __init__(self, selenium):
def __init__(self, testsetup):
'''
Creates a new instance of the class and gets the page ready for testing
'''
self.sel = selenium
self.sel = testsetup.selenium

@property
def product_select(self):
Expand All @@ -317,8 +317,8 @@ class CrashStatsTopCrashers(CrashStatsBasePage):
_product_header = 'css=h2 > span.current-product'
_product_version_header = 'css=h2 > span.current-version'

def __init__(self, selenium):
self.sel = selenium
def __init__(self, testsetup):
self.sel = testsetup.selenium

@property
def product_header(self):
Expand All @@ -334,8 +334,8 @@ class CrashStatsTopCrashersByUrl(CrashStatsBasePage):
_product_header = 'id=tcburl-product'
_product_version_header = 'id=tcburl-version'

def __init__(self, selenium):
self.sel = selenium
def __init__(self, testsetup):
self.sel = testsetup.selenium

@property
def product_header(self):
Expand All @@ -351,8 +351,8 @@ class CrashStatsTopCrashersByDomain(CrashStatsBasePage):
_product_header = 'id=tcburl-product'
_product_version_header = 'id=tcburl-version'

def __init__(self, selenium):
self.sel = selenium
def __init__(self, testsetup):
self.sel = testsetup.selenium

@property
def product_header(self):
Expand All @@ -368,8 +368,8 @@ class CrashStatsTopCrashersBySite(CrashStatsBasePage):
_product_header = 'id=tcburl-product'
_product_version_header = 'id=tcburl-version'

def __init__(self, selenium):
self.sel = selenium
def __init__(self, testsetup):
self.sel = testsetup.selenium

@property
def product_header(self):
Expand All @@ -387,8 +387,8 @@ class CrashStatsStatus(CrashStatsBasePage):
_graphs_locator = 'css=div.title:contains("Graphs")'
_latest_raw_stats = 'css=div.title:contains("Latest Raw Stats")'

def __init__(self, selenium):
self.sel = selenium
def __init__(self, testsetup):
self.sel = testsetup.selenium
self.wait_for_element_present(self._page_header)

def at_a_glance(self):
Expand Down
Loading

0 comments on commit c1a45c3

Please sign in to comment.