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

Commit

Permalink
Migrate manage_cases, manage_products, manage_profiles pages.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac authored and Zac committed May 2, 2012
1 parent 714007b commit 8b5b04a
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 60 deletions.
38 changes: 20 additions & 18 deletions pages/manage_cases_page.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,42 +4,44 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this # 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/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.


from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from pages.base_page import MozTrapBasePage from pages.base_page import MozTrapBasePage




class MozTrapManageCasesPage(MozTrapBasePage): class MozTrapManageCasesPage(MozTrapBasePage):


_page_title = 'MozTrap' _page_title = 'MozTrap'


_delete_case_locator = u'css=#managecases .itemlist .listitem[data-title="%(case_name)s"] .action-delete' _delete_case_locator = (By.CSS_SELECTOR, '#managecases .itemlist .listitem[data-title="%(case_name)s"] .action-delete')
_case_status_locator = u'css=#managecases .itemlist .listitem[data-title="%(case_name)s"] .status-action' _case_status_locator = (By.CSS_SELECTOR, '#managecases .itemlist .listitem[data-title="%(case_name)s"] .status-action')
_filter_input_locator = 'id=text-filter' _filter_input_locator = (By.ID, 'text-filter')
_filter_suggestion_locator = u'css=#filter .textual .suggest .suggestion[data-type="name"][data-name="%(filter_name)s"]' _filter_suggestion_locator = (By.CSS_SELECTOR, '#filter .textual .suggest .suggestion[data-type="name"][data-name="%(filter_name)s"]')
_filter_locator = u'css=#filterform .filter-group input[data-name="name"][value="%(filter_name)s"]:checked' _filter_locator = (By.CSS_SELECTOR, '#filterform .filter-group input[data-name="name"][value="%(filter_name)s"]:checked')


def go_to_manage_cases_page(self): def go_to_manage_cases_page(self):
self.selenium.open('/manage/cases/') self.selenium.get(self.base_url + '/manage/cases/')
self.is_the_current_page self.is_the_current_page


def delete_case(self, name='Test Case'): def delete_case(self, name='Test Case'):
_delete_locator = self._delete_case_locator % {'case_name': name} _delete_locator = (self._delete_case_locator[0], self._delete_case_locator[1] % {'case_name': name})


self.click(_delete_locator) self.selenium.find_element(*_delete_locator).click()
self.wait_for_ajax() self.wait_for_ajax()


def filter_cases_by_name(self, name): def filter_cases_by_name(self, name):
_filter_locator = self._filter_locator % {'filter_name': name.lower()} '''
_filter_suggestion_locator = self._filter_suggestion_locator % {'filter_name': name} Types the name into the input field and then clicks the item in the search suggestions

'''
self.type(self._filter_input_locator, name) _filter_locator = (self._filter_locator[0], self._filter_locator[1] % {'filter_name': name.lower()})
self.selenium.type_keys(self._filter_input_locator, name) _filter_suggestion_locator = (self._filter_suggestion_locator[0], self._filter_suggestion_locator[1] % {'filter_name': name})
self.wait_for_element_present(_filter_suggestion_locator)
self.click(_filter_suggestion_locator) self.selenium.find_element(*self._filter_input_locator).send_keys(name)
self.wait_for_element_present(_filter_locator) self.selenium.find_element(*_filter_suggestion_locator).click()
self.wait_for_ajax() self.wait_for_ajax()


def activate_case(self, name='Test Case'): def activate_case(self, name='Test Case'):
_case_status_locator = self._case_status_locator % {'case_name': name} _case_status_locator = (self._case_status_locator[0], self._case_status_locator[1] % {'case_name': name})


self.click(_case_status_locator) self.selenium.find_element(*_case_status_locator).click()
self.wait_for_ajax() self.wait_for_ajax()
48 changes: 23 additions & 25 deletions pages/manage_products_page.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,51 +4,49 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this # 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/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.


from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys

from pages.base_page import MozTrapBasePage from pages.base_page import MozTrapBasePage




class MozTrapManageProductsPage(MozTrapBasePage): class MozTrapManageProductsPage(MozTrapBasePage):


_page_title = 'MozTrap' _page_title = 'MozTrap'
_delete_product_locator = u'css=#manageproducts .listitem .controls .action-delete[title="delete %(product_name)s"]' _delete_product_locator = (By.CSS_SELECTOR, '#manageproducts .listitem .controls .action-delete[title="delete %(product_name)s"]')
_filter_input_locator = 'id=text-filter' _filter_input_locator = (By.ID, 'text-filter')
_filter_suggestion_locator = u'css=#filter .textual .suggest .suggestion[data-type="name"][data-name="%(filter_name)s"]' _filter_suggestion_locator = (By.CSS_SELECTOR, '#filter .textual .suggest .suggestion[data-type="name"][data-name="%(filter_name)s"]')
_filter_locator = u'css=#filterform .filter-group input[data-name="name"][value="%(filter_name)s"]:checked' _filter_locator = (By.CSS_SELECTOR, '#filterform .filter-group input[data-name="name"][value="%(filter_name)s"]:checked')


def go_to_manage_products_page(self): def go_to_manage_products_page(self):
self.selenium.open('/manage/products/') self.selenium.get(self.base_url + '/manage/products/')
self.is_the_current_page self.is_the_current_page


def delete_product(self, name='Test Product'): def delete_product(self, name='Test Product'):
_delete_locator = self._delete_product_locator % {'product_name': name} _delete_locator = (self._delete_product_locator[0], self._delete_product_locator[1] % {'product_name': name})


self.click(_delete_locator) self.selenium.find_element(*_delete_locator).click()
self.wait_for_ajax() self.wait_for_ajax()


def filter_products_by_name(self, name): def filter_products_by_name(self, name):
_filter_locator = self._filter_locator % {'filter_name': name.lower()} _filter_locator = (self._filter_locator[0], self._filter_locator[1] % {'filter_name': name.lower()})
_filter_suggestion_locator = self._filter_suggestion_locator % {'filter_name': name} _filter_suggestion_locator = (self._filter_suggestion_locator[0], self._filter_suggestion_locator[1] % {'filter_name': name})


self.type(self._filter_input_locator, name) self.selenium.find_element(*self._filter_input_locator).send_keys(name)
self.selenium.type_keys(self._filter_input_locator, name) self.selenium.find_element(*_filter_suggestion_locator).click()
self.wait_for_element_present(_filter_suggestion_locator)
self.click(_filter_suggestion_locator)
self.wait_for_element_present(_filter_locator)
self.wait_for_ajax() self.wait_for_ajax()


def filter_products_by_name_without_mouse(self, name): def filter_products_by_name_without_mouse(self, name):
_filter_locator = self._filter_locator % {'filter_name': name.lower()} _filter_locator = (self._filter_locator[0], self._filter_locator[1] % {'filter_name': name.lower()})
_filter_suggestion_locator = self._filter_suggestion_locator % {'filter_name': name} _filter_suggestion_locator = (self._filter_suggestion_locator[0], self._filter_suggestion_locator[1] % {'filter_name': name})


self.type(self._filter_input_locator, name) filter_input_locator = self.selenium.find_element(*self._filter_input_locator)
self.selenium.type_keys(self._filter_input_locator, name) filter_input_locator.send_keys(name)
self.wait_for_element_present(_filter_suggestion_locator) filter_input_locator.send_keys(Keys.RETURN)
self.selenium.key_down(self._filter_input_locator, '13')
self.wait_for_element_present(_filter_locator)
self.wait_for_ajax() self.wait_for_ajax()


def remove_name_filter(self, name): def remove_name_filter(self, name):
_filter_locator = self._filter_locator % {'filter_name': name.lower()} _filter_locator = (self._filter_locator[0], self._filter_locator[1] % {'filter_name': name.lower()})


self.click(_filter_locator) self.selenium.find_element(*_filter_locator).click()
self.wait_for_ajax() self.wait_for_ajax()
33 changes: 16 additions & 17 deletions pages/manage_profiles_page.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,41 +4,40 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this # 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/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.


from selenium.webdriver.common.by import By

from pages.base_page import MozTrapBasePage from pages.base_page import MozTrapBasePage




class MozTrapManageProfilesPage(MozTrapBasePage): class MozTrapManageProfilesPage(MozTrapBasePage):


_page_title = 'MozTrap' _page_title = 'MozTrap'


_delete_profile_locator = u'css=#manageprofiles .listitem .action-delete[title="delete %(profile_name)s"]' _delete_profile_locator = (By.CSS_SELECTOR, '#manageprofiles .listitem .action-delete[title="delete %(profile_name)s"]')
_filter_input_locator = 'id=text-filter' _filter_input_locator = (By.ID, 'text-filter')
_filter_suggestion_locator = u'css=#filter .textual .suggest .suggestion[data-type="name"][data-name="%(filter_name)s"]' _filter_suggestion_locator = (By.CSS_SELECTOR, '#filter .textual .suggest .suggestion[data-type="name"][data-name="%(filter_name)s"]')
_filter_locator = u'css=#filterform .filter-group input[data-name="name"][value="%(filter_name)s"]:checked' _filter_locator = (By.CSS_SELECTOR, '#filterform .filter-group input[data-name="name"][value="%(filter_name)s"]:checked')


def go_to_manage_profiles_page(self): def go_to_manage_profiles_page(self):
self.open('/manage/profiles/') self.selenium.get(self.base_url + '/manage/profiles/')
self.is_the_current_page self.is_the_current_page


def delete_profile(self, name='Test Profile'): def delete_profile(self, name='Test Profile'):
_delete_locator = self._delete_profile_locator % {'profile_name': name} _delete_locator = (self._delete_profile_locator[0], self._delete_profile_locator[1] % {'profile_name': name})


self.click(_delete_locator) self.selenium.find_element(*_delete_locator).click()
self.wait_for_ajax() self.wait_for_ajax()


def filter_profiles_by_name(self, name): def filter_profiles_by_name(self, name):
_filter_locator = self._filter_locator % {'filter_name': name.lower()} _filter_locator = (self._filter_locator[0], self._filter_locator[1] % {'filter_name': name.lower()})
_filter_suggestion_locator = self._filter_suggestion_locator % {'filter_name': name} _filter_suggestion_locator = (self._filter_suggestion_locator[0], self._filter_suggestion_locator[1] % {'filter_name': name})


self.type(self._filter_input_locator, name) self.selenium.find_element(*self._filter_input_locator).send_keys(name)
self.selenium.type_keys(self._filter_input_locator, name) self.selenium.find_element(*_filter_suggestion_locator).click()
self.wait_for_element_present(_filter_suggestion_locator)
self.click(_filter_suggestion_locator)
self.wait_for_element_present(_filter_locator)
self.wait_for_ajax() self.wait_for_ajax()


def remove_name_filter(self, name): def remove_name_filter(self, name):
_filter_locator = self._filter_locator % {'filter_name': name.lower()} _filter_locator = (self._filter_locator[0], self._filter_locator[1] % {'filter_name': name.lower()})


self.click(_filter_locator) self.selenium.find_element(*_filter_locator).click()
self.wait_for_ajax() self.wait_for_ajax()
4 changes: 4 additions & 0 deletions pages/page.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -58,3 +58,7 @@ def is_element_visible(self, *locator):
except NoSuchElementException, ElementNotVisibleException: except NoSuchElementException, ElementNotVisibleException:
# this will return a snapshot, which takes time. # this will return a snapshot, which takes time.
return False return False

def wait_for_ajax(self):
WebDriverWait(self.selenium, self.timeout).until(lambda s: s.execute_script("return $.active == 0"),
"Wait for AJAX timed out after %s seconds" % self.timeout)

0 comments on commit 8b5b04a

Please sign in to comment.