Skip to content

Commit

Permalink
issue #22 - DRY out some of the modal testing
Browse files Browse the repository at this point in the history
  • Loading branch information
jantman committed Mar 28, 2017
1 parent 23a266d commit cd095b4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 29 deletions.
20 changes: 4 additions & 16 deletions biweeklybudget/tests/acceptance/flaskapp/views/test_budgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,7 @@ def get_page(self, base_url, selenium, testflask, testdb): # noqa
def test_1_populate_modal(self, selenium):
link = selenium.find_element_by_xpath('//a[text()="Periodic1 (1)"]')
link.click()
self.wait_for_modal_shown(selenium, 'modalLabel')
modal = selenium.find_element_by_id('modalDiv')
title = selenium.find_element_by_id('modalLabel')
body = selenium.find_element_by_id('modalBody')
modal, title, body = self.get_modal_parts(selenium)
self.assert_modal_displayed(modal, title, body)
assert title.text == 'Edit Budget 1'
assert selenium.find_element_by_id('budget_frm_name').get_attribute(
Expand Down Expand Up @@ -141,10 +138,7 @@ def get_page(self, base_url, selenium, testflask, testdb): # noqa
def test_1_populate_modal(self, selenium):
link = selenium.find_element_by_xpath('//a[text()="Periodic2 (2)"]')
link.click()
self.wait_for_modal_shown(selenium, 'modalLabel')
modal = selenium.find_element_by_id('modalDiv')
title = selenium.find_element_by_id('modalLabel')
body = selenium.find_element_by_id('modalBody')
modal, title, body = self.get_modal_parts(selenium)
self.assert_modal_displayed(modal, title, body)
assert title.text == 'Edit Budget 2'
assert selenium.find_element_by_id('budget_frm_name').get_attribute(
Expand Down Expand Up @@ -180,10 +174,7 @@ def get_page(self, base_url, selenium, testflask, testdb): # noqa
def test_1_populate_modal(self, selenium):
link = selenium.find_element_by_xpath('//a[text()="Standing1 (4)"]')
link.click()
self.wait_for_modal_shown(selenium, 'modalLabel')
modal = selenium.find_element_by_id('modalDiv')
title = selenium.find_element_by_id('modalLabel')
body = selenium.find_element_by_id('modalBody')
modal, title, body = self.get_modal_parts(selenium)
self.assert_modal_displayed(modal, title, body)
assert title.text == 'Edit Budget 4'
assert selenium.find_element_by_id('budget_frm_name').get_attribute(
Expand Down Expand Up @@ -219,10 +210,7 @@ def get_page(self, base_url, selenium, testflask, testdb): # noqa
def test_1_populate_modal(self, selenium):
link = selenium.find_element_by_xpath('//a[text()="Standing2 (5)"]')
link.click()
self.wait_for_modal_shown(selenium, 'modalLabel')
modal = selenium.find_element_by_id('modalDiv')
title = selenium.find_element_by_id('modalLabel')
body = selenium.find_element_by_id('modalBody')
modal, title, body = self.get_modal_parts(selenium)
self.assert_modal_displayed(modal, title, body)
assert title.text == 'Edit Budget 5'
assert selenium.find_element_by_id('budget_frm_name').get_attribute(
Expand Down
10 changes: 2 additions & 8 deletions biweeklybudget/tests/acceptance/flaskapp/views/test_ofx.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,7 @@ def get_page(self, base_url, selenium, testflask, testdb): # noqa
def test_modal_on_click(self, selenium):
link = selenium.find_element_by_xpath('//a[text()="T1"]')
link.click()
self.wait_for_modal_shown(selenium, 'modalLabel')
modal = selenium.find_element_by_id('modalDiv')
title = selenium.find_element_by_id('modalLabel')
body = selenium.find_element_by_id('modalBody')
modal, title, body = self.get_modal_parts(selenium)
self.assert_modal_displayed(modal, title, body)
assert title.text == 'OFXTransaction Account=3 FITID=T1'
texts = self.tbody2textlist(body)
Expand Down Expand Up @@ -286,10 +283,7 @@ def get_page(self, base_url, selenium, testflask, testdb): # noqa
selenium.get(base_url + '/ofx/3/T1')

def test_modal_auto_displayed(self, selenium):
self.wait_for_modal_shown(selenium, 'modalLabel')
modal = selenium.find_element_by_id('modalDiv')
title = selenium.find_element_by_id('modalLabel')
body = selenium.find_element_by_id('modalBody')
modal, title, body = self.get_modal_parts(selenium)
self.assert_modal_displayed(modal, title, body)
assert title.text == 'OFXTransaction Account=3 FITID=T1'
texts = self.tbody2textlist(body)
Expand Down
27 changes: 22 additions & 5 deletions biweeklybudget/tests/acceptance_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,35 @@ def retry_stale(self, func, *args, **kwargs):
sleep(1)
raise e

def wait_for_modal_shown(self, driver, modal_id):
def wait_for_modal_shown(self, driver):
"""
Wait for the modal with the given ID to be shown.
Wait for the modal to be shown.
:param driver: Selenium driver instance
:param modal_id: the id of the modal div
:type modal_id: str
"""
WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.ID, modal_id))
EC.element_to_be_clickable((By.ID, 'modalLabel'))
)

def get_modal_parts(self, selenium, wait=True):
"""
Return a 3-tuple of the WebElements representing the modalDiv,
modalLabel h4 and modalBody div.
:param selenium: Selenium driver instance
:param wait: whether or not to wait for presence of modalLabel
:type wait: bool
:return: 3-tuple of (modalDiv WebElement, modalLabel WebElement,
modalBody WebElement)
:rtype: tuple
"""
if wait:
self.wait_for_modal_shown(selenium)
modal = selenium.find_element_by_id('modalDiv')
title = selenium.find_element_by_id('modalLabel')
body = selenium.find_element_by_id('modalBody')
return modal, title, body

def assert_modal_displayed(self, modal, title, body):
"""
Assert that the modal is displayed.
Expand Down

0 comments on commit cd095b4

Please sign in to comment.