This commit is contained in:
sashakruglov 2013-01-13 18:10:25 +04:00
Родитель 510ac0d2ac
Коммит fa51c0c5ff
10 изменённых файлов: 297 добавлений и 10 удалений

Просмотреть файл

@ -18,6 +18,7 @@ from pages.create_product_page import MozTrapCreateProductPage
from pages.manage_products_page import MozTrapManageProductsPage
from pages.create_profile_page import MozTrapCreateProfilePage
from pages.manage_profiles_page import MozTrapManageProfilesPage
from pages.create_bulk_cases_page import MozTrapCreateBulkCasesPage
class BaseTest(object):
@ -96,14 +97,14 @@ class BaseTest(object):
if delete_version:
self.delete_version(mozwebqa, version=run['version'], delete_product=delete_product)
def create_suite(self, mozwebqa, status='active', product=None, case_name_list=None):
def create_suite(self, mozwebqa, status='active', product=None, case_name_list=None, **kwargs):
create_suite_pg = MozTrapCreateSuitePage(mozwebqa)
if product is None:
product = self.create_product(mozwebqa)
create_suite_pg.go_to_create_suite_page()
suite = create_suite_pg.create_suite(product=product['name'], status=status, case_list=case_name_list)
suite = create_suite_pg.create_suite(product=product['name'], status=status, case_list=case_name_list, **kwargs)
suite['product'] = product
return suite
@ -175,7 +176,28 @@ class BaseTest(object):
case['profile'] = profile
run = self.create_run(mozwebqa, activate=True, product=product, version=product['version'], suite_name_list=[suite['name']])
home_pg.go_to_homepage_page()
home_pg.go_to_home_page()
home_pg.go_to_run_test(product_name=product['name'], version_name=product['version']['name'], run_name=run['name'], env_category=profile['category'], env_element=profile['element'])
return case
def create_bulk_cases(self, mozwebqa, cases_amount=2, status='active', product=None, version=None, suite_name=None, **kwargs):
create_bulk_cases_pg = MozTrapCreateBulkCasesPage(mozwebqa)
if product is None:
product = self.create_product(mozwebqa)
version = product['version']
elif version is None:
version = product['version']
create_bulk_cases_pg.go_to_create_bulk_cases_page()
cases = create_bulk_cases_pg.create_bulk_cases(
product=product['name'], version=version['name'], status=status,
suite=suite_name, cases_amount=cases_amount, **kwargs)
#add product to dictionary to ensure that output of this method
#is similar to create_case method
for case in cases:
case['product'] = product
return cases

Просмотреть файл

@ -0,0 +1,68 @@
#!/usr/bin/env python
# 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/.
from datetime import datetime
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
from pages.base_page import MozTrapBasePage
class MozTrapCreateBulkCasesPage(MozTrapBasePage):
_page_title = 'Create Bulk Case'
_product_select_locator = (By.ID, 'id_product')
_version_select_locator = (By.ID, 'id_productversion')
_suite_select_locator = (By.ID, 'id_suite')
_cases_description_locator = (By.ID, 'id_cases')
_status_select_locator = (By.ID, 'id_status')
_submit_locator = (By.CSS_SELECTOR, '#bulk-case-add button[name="save"]')
_case_locator = (By.CSS_SELECTOR, '#managecases .itemlist .listitem .title[title="%(case_name)s"]')
def go_to_create_bulk_cases_page(self):
self.selenium.get(self.base_url + '/manage/case/add/bulk/')
self.is_the_current_page
def create_bulk_cases(
self, name='Test Case', product='Test Product', version='Test Version',
suite=None, desc='This is a test case', status='active',
step1_instruction='Test Case step 1 instruction',
step1_result='Test Case step 1 expected result', cases_amount=2):
cases = []
for case in xrange(cases_amount):
dt_string = datetime.utcnow().isoformat()
case = {}
case['name'] = u'Test that %(name)s %(dt_string)s' % {'name': name, 'dt_string': dt_string}
case['desc'] = u'%(desc)s created on %(dt_string)s' % {'desc': desc, 'dt_string': dt_string}
case['locator'] = (self._case_locator[0], self._case_locator[1] % {'case_name': case['name']})
cases.append(case)
desc_str = []
for case in cases:
desc_str.append('%s \n %s \n When %s \n Then %s \n' % (case['name'], case['desc'], step1_instruction, step1_result))
cases_desc = '\n'.join(desc_str)
product_select = Select(self.selenium.find_element(*self._product_select_locator))
product_select.select_by_visible_text(product)
version_select = Select(self.selenium.find_element(*self._version_select_locator))
version_select.select_by_visible_text(version)
if suite:
suite_select = Select(self.selenium.find_element(*self._suite_select_locator))
suite_select.select_by_visible_text(suite)
self.selenium.find_element(*self._cases_description_locator).send_keys(cases_desc)
status_select = Select(self.selenium.find_element(*self._status_select_locator))
status_select.select_by_visible_text(status)
self.selenium.find_element(*self._submit_locator).click()
return cases

Просмотреть файл

@ -64,11 +64,10 @@ class MozTrapCreateRunPage(MozTrapBasePage):
self.selenium.find_element(*self._end_date_locator).send_keys(end_date)
if suite_list:
for suite in suite_list:
suite_input_element = self.selenium.find_element(By.XPATH, "//article[@data-title='%s']//label" % suite)
suite_input_element.click()
self.selenium.find_element(*self._include_selected_suites_locator).click()
self.selenium.find_element(*self._include_selected_suites_locator).click()
self.selenium.find_element(*self._submit_locator).click()
return run

Просмотреть файл

@ -49,7 +49,7 @@ class MozTrapCreateSuitePage(MozTrapBasePage):
for case in case_list:
case_element = self.selenium.find_element(By.XPATH, "//article[@data-title='%s']/div/label" % case)
case_element.click()
self.selenium.find_element(*self._include_selected_cases_locator).click()
self.selenium.find_element(*self._include_selected_cases_locator).click()
self.selenium.find_element(*self._submit_locator).click()
return suite

68
pages/edit_run_page.py Normal file
Просмотреть файл

@ -0,0 +1,68 @@
#!/usr/bin/env python
# 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/.
from datetime import datetime
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
from pages.base_page import MozTrapBasePage
class MozTrapEditRunPage(MozTrapBasePage):
_page_title = 'Edit Run'
_name_locator = (By.ID, 'id_name')
_product_version_select_locator = (By.ID, 'id_productversion')
_description_locator = (By.ID, 'id_description')
_start_date_locator = (By.ID, 'id_start')
_end_date_locator = (By.ID, 'id_end')
_series_run_locator = (By.ID, 'id_is_series')
_include_selected_suites_locator = (By.CSS_SELECTOR, '#run-edit-form .multiselect .include-exclude .action-include')
_sort_included_suites_by_name_locator = (By.CSS_SELECTOR, '#run-edit-form .multiselected .byname .sortlink')
_submit_locator = (By.CSS_SELECTOR, '#run-edit-form .form-actions > button')
def edit_run(self, run, name=None, product_version=None, desc=None,
start_date=None, end_date=None, reorder_suites=False, series_run=False):
if name:
name_field = self.selenium.find_element(*self._name_locator)
name_field.send_keys(name)
run['name'] = name
if product_version:
product_version_select = Select(self.selenium.find_element(*self._product_version_select_locator))
product_version_select.select_by_visible_text(product_version)
if desc:
self.selenium.find_element(*self._description_locator).send_keys(desc)
run['desc'] = desc
if start_date:
self.type_in_element(self._start_date_locator, start_date)
if end_date:
self.type_in_element(self._end_date_locator, end_date)
if series_run:
series_element = self.selenium.find_element(*self._series_run_locator)
if series_element.is_selected():
if not series_run:
series_element.click()
else:
if series_run:
series_element.click()
run['series'] = series_run
if reorder_suites:
sorter = self.selenium.find_element(*self._sort_included_suites_by_name_locator)
sorter.click()
sorter.click()
self.selenium.find_element(*self._submit_locator).click()
return run

Просмотреть файл

@ -20,7 +20,7 @@ class MozTrapHomePage(MozTrapBasePage):
_os_locator = (By.CSS_SELECTOR, '#runtests-environment-form .operating-system-field select')
_submit_locator = (By.CSS_SELECTOR, '#runtests-environment-form .form-actions button[type="submit"]')
def go_to_homepage_page(self):
def go_to_home_page(self):
self.selenium.get(self.base_url + '/')
self.is_the_current_page

Просмотреть файл

@ -15,7 +15,9 @@ class MozTrapManageRunsPage(MozTrapBasePage):
_delete_run_locator = (By.CSS_SELECTOR, '#manageruns .itemlist .listitem[data-title="%(run_name)s"] .action-delete')
_run_activate_locator = (By.CSS_SELECTOR, '#manageruns .itemlist .listitem[data-title="%(run_name)s"] .status-action.active')
_run_draft_locator = (By.CSS_SELECTOR, '#manageruns .itemlist .listitem[data-title="%(run_name)s"] .status-action.draft')
_run_status_locator = (By.CSS_SELECTOR, '#manageruns .itemlist .listitem[data-title="%(run_name)s"] .status-title')
_edit_run_locator = (By.CSS_SELECTOR, '#manageruns .itemlist .listitem[data-title="%(run_name)s"] .edit-link')
_filter_input_locator = (By.ID, 'text-filter')
_filter_suggestion_locator = (By.CSS_SELECTOR, '#filter .textual .suggest .suggestion[data-type="name"][data-name="%(filter_name)s"]')
_filter_locator = (By.CSS_SELECTOR, '#filterform .filter-group input[data-name="name"][value="%(filter_name)s"]:checked')
@ -51,3 +53,19 @@ class MozTrapManageRunsPage(MozTrapBasePage):
self.selenium.find_element(*_run_activate_locator).click()
self.wait_for_ajax()
def make_run_draft(self, name='Test Run'):
_run_status_locator = (self._run_status_locator[0], self._run_status_locator[1] % {'run_name': name})
_run_draft_locator = (self._run_draft_locator[0], self._run_draft_locator[1] % {'run_name': name})
self.selenium.find_element(*_run_status_locator).click()
self.selenium.find_element(*_run_draft_locator).click()
self.wait_for_ajax()
def go_to_edit_run_page(self, name='Test Run'):
_edit_run_locator= (self._edit_run_locator[0], self._edit_run_locator[1] % {'run_name' : name})
self.selenium.find_element(*_edit_run_locator).click()
from pages.edit_run_page import MozTrapEditRunPage
return MozTrapEditRunPage(self.testsetup)

Просмотреть файл

@ -6,6 +6,7 @@
from selenium.webdriver.common.by import By
from pages.page import Page
from pages.base_page import MozTrapBasePage
@ -25,6 +26,8 @@ class MozTrapRunTestsPage(MozTrapBasePage):
_test_invalid_desc_locator = (By.CSS_SELECTOR, '#runtests .itemlist .listitem[data-title="%(case_name)s"] .itembody .testinvalid .invalid-form .invalid-input')
_test_invalid_submit_locator = (By.CSS_SELECTOR, '#runtests .itemlist .listitem[data-title="%(case_name)s"] .itembody .testinvalid .invalid-form .form-actions .invalid')
_test_item_locator = (By.CSS_SELECTOR, '.listitem')
def open_test_summary(self, case_name):
_open_test = (self._test_summary_locator[0], self._test_summary_locator[1] % {'case_name': case_name})
self.selenium.find_element(*_open_test).click()
@ -74,3 +77,36 @@ class MozTrapRunTestsPage(MozTrapBasePage):
_test_is_invalid_locator = (self._test_is_invalid_locator[0], self._test_is_invalid_locator[1] % {'case_name': case_name})
return self.is_element_present(*_test_is_invalid_locator)
@property
def test_items(self):
return [self.TestItem(self.testsetup, web_el) for web_el
in self.selenium.find_elements(*self._test_item_locator)]
class TestItem(Page):
_case_result_locator = (By.CSS_SELECTOR, '.result')
_case_name_locator = (By.CSS_SELECTOR, '.title')
_suite_name_locator = (By.CSS_SELECTOR, 'a[data-type="suite"]')
_case_position_number_locator = (By.CSS_SELECTOR, '.order')
def __init__(self, testsetup, base_el):
Page.__init__(self, testsetup)
self.selenium = base_el
@property
def result(self):
return self.selenium.find_element(*self._case_result_locator).text
@property
def name(self):
return self.selenium.find_element(*self._case_name_locator).text
@property
def suite_name(self):
return self.selenium.find_element(*self._suite_name_locator).text
@property
def position_number(self):
return self.selenium.find_element(*self._case_position_number_locator).text

Просмотреть файл

@ -45,7 +45,7 @@ class TestHomepage(BaseTest):
product = self.create_product(mozwebqa_logged_in)
home_pg.go_to_homepage_page()
home_pg.go_to_home_page()
Assert.false(home_pg.is_element_visible(*product['version']['homepage_locator']))
@ -61,7 +61,7 @@ class TestHomepage(BaseTest):
run = self.create_run(mozwebqa_logged_in, activate=True)
home_pg.go_to_homepage_page()
home_pg.go_to_home_page()
home_pg.select_item(run['version']['product']['name'])
Assert.false(home_pg.is_element_visible(*run['homepage_locator']))
@ -78,7 +78,7 @@ class TestHomepage(BaseTest):
run = self.create_run(mozwebqa_logged_in, activate=True)
home_pg.go_to_homepage_page()
home_pg.go_to_home_page()
home_pg.select_item(run['version']['product']['name'])
home_pg.select_item(run['version']['name'])

Просмотреть файл

@ -8,7 +8,9 @@ import pytest
from unittestzero import Assert
from pages.base_test import BaseTest
from pages.home_page import MozTrapHomePage
from pages.run_tests_page import MozTrapRunTestsPage
from pages.manage_runs_page import MozTrapManageRunsPage
class TestRunTestsPage(BaseTest):
@ -57,3 +59,77 @@ class TestRunTestsPage(BaseTest):
self.delete_product(mozwebqa_logged_in, product=case['product'])
self.delete_profile(mozwebqa_logged_in, profile=case['profile'])
@pytest.mark.moztrap(2744)
def test_that_test_run_saves_right_order_of_test_cases(self, mozwebqa_logged_in):
#get profile, product and version
profile = self.create_profile(mozwebqa_logged_in)
product = self.create_product(mozwebqa_logged_in, profile['name'])
version = product['version']
#create several test case via bulk create
cases = self.create_bulk_cases(mozwebqa_logged_in, cases_amount=5, product=product, name='is')
#create first test suite
suite_a_cases = (cases[3]['name'], cases[1]['name'])
suite_a = self.create_suite(
mozwebqa_logged_in, product=product, name='suite A', case_name_list=reversed(suite_a_cases))
#create second test suite
suite_b_cases = (cases[2]['name'], cases[0]['name'], cases[4]['name'])
suite_b = self.create_suite(
mozwebqa_logged_in, product=product, name='suite B', case_name_list=reversed(suite_b_cases))
#create first test run (suite a, suite b)
first_suite_order = (suite_a['name'], suite_b['name'])
first_run = self.create_run(
mozwebqa_logged_in, activate=True, product=product,
version=version, suite_name_list=reversed(first_suite_order))
#execute first test run
home_page = MozTrapHomePage(mozwebqa_logged_in)
home_page.go_to_home_page()
home_page.go_to_run_test(
product_name=product['name'], version_name=version['name'], run_name=first_run['name'],
env_category=profile['category'], env_element=profile['element'])
run_tests_pg = MozTrapRunTestsPage(mozwebqa_logged_in)
actual_order = [(item.name, item.suite_name) for item in run_tests_pg.test_items]
expected_order = [(case, suite) for case in suite_a_cases for suite in (suite_a['name'],)] + \
[(case, suite) for case in suite_b_cases for suite in (suite_b['name'],)]
#assert that right order saved
Assert.equal(actual_order, expected_order)
#edit run to reorder suites
manage_runs_pg = MozTrapManageRunsPage(mozwebqa_logged_in)
manage_runs_pg.go_to_manage_runs_page()
#push run into draft mode
manage_runs_pg.filter_runs_by_name(first_run['name'])
manage_runs_pg.make_run_draft(first_run['name'])
#go to edit run page and reorder suites by name (suite b, suite a)
edit_run_pg = manage_runs_pg.go_to_edit_run_page(first_run['name'])
second_run = edit_run_pg.edit_run(first_run, reorder_suites=True)
#make run active again
manage_runs_pg.filter_runs_by_name(first_run['name'])
manage_runs_pg.activate_run(first_run['name'])
#execute run again
home_page.go_to_home_page()
home_page.go_to_run_test(
product_name=product['name'], version_name=version['name'], run_name=first_run['name'],
env_category=profile['category'], env_element=profile['element'])
#check actual order of items on run tests page
actual_order = [(item.name, item.suite_name) for item in run_tests_pg.test_items]
expected_order = [(case, suite) for case in suite_b_cases for suite in (suite_b['name'],)] + \
[(case, suite) for case in suite_a_cases for suite in (suite_a['name'],)]
#assert that right order saved
Assert.equal(actual_order, expected_order)