Commit f81b7cef by Ben Patterson

Merge pull request #10582 from edx/saleem-latif/SOL-1384

saleem-latif/SOL-1384: Refactor certificates bok-choy pages to use PageObject
parents 6687aa1a 195178aa
...@@ -78,7 +78,7 @@ class CertificatesPage(CoursePage): ...@@ -78,7 +78,7 @@ class CertificatesPage(CoursePage):
Return list of the certificates for the course. Return list of the certificates for the course.
""" """
css = self.certficate_css + ' .wrapper-collection' css = self.certficate_css + ' .wrapper-collection'
return [Certificate(self, self.certficate_css, index) for index in xrange(len(self.q(css=css)))] return [CertificateSectionPage(self, self.certficate_css, index) for index in xrange(len(self.q(css=css)))]
@property @property
def no_certificates_message_shown(self): def no_certificates_message_shown(self):
...@@ -171,16 +171,42 @@ class CertificatesPage(CoursePage): ...@@ -171,16 +171,42 @@ class CertificatesPage(CoursePage):
self.wait_for_ajax() self.wait_for_ajax()
class Certificate(object): class CertificateSectionPage(CertificatesPage):
""" """
Certificate page object wrapper CertificateSectionPage is the certificate section within Certificates page, There might be multiple certificates
in a Certificates Page so this section object can be used to used to identify unique certificate and apply
operations on it.
""" """
def __init__(self, page, prefix, index): def __init__(self, container, prefix, index):
self.page = page """
Initialize CertificateSection Page
:param container: Container Page Object of the certificate section
:param prefix: css selector of the container element
:param index: index of section in the certificate list on the page
:return:
"""
self.selector = prefix + ' .certificates-list-item-{}'.format(index) self.selector = prefix + ' .certificates-list-item-{}'.format(index)
self.index = index self.index = index
super(CertificateSectionPage, self).__init__(container.browser, **container.course_info)
def is_browser_on_page(self):
"""
Verify that the browser is on the page and it is not still loading.
"""
return self.q(css=".certificates").present
@property
def url(self):
"""
Construct a URL to the page section within the certificate page.
"""
# This is a page section and can not be accessed directly
return None
################ ################
# Helpers # Helpers
################ ################
...@@ -195,7 +221,7 @@ class Certificate(object): ...@@ -195,7 +221,7 @@ class Certificate(object):
""" """
Find elements as defined by css locator. Find elements as defined by css locator.
""" """
return self.page.q(css=self.get_selector(css=css_selector)) return self.q(css=self.get_selector(css=css_selector))
def get_text(self, css): def get_text(self, css):
""" """
...@@ -280,7 +306,7 @@ class Certificate(object): ...@@ -280,7 +306,7 @@ class Certificate(object):
Return list of the signatories for the certificate. Return list of the signatories for the certificate.
""" """
css = self.selector + ' .signatory-' + self.mode css = self.selector + ' .signatory-' + self.mode
return [Signatory(self, self.selector, self.mode, index) for index in xrange(len(self.page.q(css=css)))] return [SignatorySectionPage(self, self.selector, self.mode, index) for index in xrange(len(self.q(css=css)))]
################ ################
# Wait Actions # Wait Actions
...@@ -312,16 +338,16 @@ class Certificate(object): ...@@ -312,16 +338,16 @@ class Certificate(object):
""" """
Create a new certificate. Create a new certificate.
""" """
disable_animations(self.page) disable_animations(self)
self.find_css('.action-primary').first.click() self.find_css('.action-primary').first.click()
self.page.wait_for_ajax() self.wait_for_ajax()
def click_save_certificate_button(self): def click_save_certificate_button(self):
""" """
Save certificate. Save certificate.
""" """
self.find_css('.action-primary').first.click() self.find_css('.action-primary').first.click()
self.page.wait_for_ajax() self.wait_for_ajax()
def click_add_signatory_button(self): def click_add_signatory_button(self):
""" """
...@@ -355,16 +381,43 @@ class Certificate(object): ...@@ -355,16 +381,43 @@ class Certificate(object):
self.find_css('.actions .delete.action-icon').first.click() self.find_css('.actions .delete.action-icon').first.click()
class Signatory(object): class SignatorySectionPage(CertificatesPage):
""" """
Signatory page object wrapper SignatorySectionPage is the signatory section within CertificatesSection, There might be multiple signatories
in a certificate section so this section object can be used to used to identify unique section and apply
operations on it.
""" """
def __init__(self, certificate, prefix, mode, index): def __init__(self, container, prefix, mode, index):
self.certificate = certificate """
Initialize SignatorySection Page
:param container: Container Section Page Object of the Signatory section
:param prefix: css selector of the container element
:param index: index of section in the signatory list on the page
:param mode: 'details' or 'edit', showing whether signatory is being displayed or edited
:return:
"""
self.prefix = prefix self.prefix = prefix
self.index = index self.index = index
self.mode = mode self.mode = mode
super(SignatorySectionPage, self).__init__(container.browser, **container.course_info)
def is_browser_on_page(self):
"""
Verify that the browser is on the page and it is not still loading.
"""
return self.q(css=self.prefix + " .signatory-details-list, .signatory-edit-list").present
@property
def url(self):
"""
Construct a URL to the page section within the certificate section page.
"""
# This is a page section and can not be accessed directly
return None
################ ################
# Helpers # Helpers
################ ################
...@@ -392,7 +445,7 @@ class Signatory(object): ...@@ -392,7 +445,7 @@ class Signatory(object):
""" """
Find elements as defined by css locator. Find elements as defined by css locator.
""" """
return self.certificate.page.q(css=self.get_selector(css=css_selector)) return self.q(css=self.get_selector(css=css_selector))
################ ################
# Properties # Properties
...@@ -461,24 +514,24 @@ class Signatory(object): ...@@ -461,24 +514,24 @@ class Signatory(object):
self.click_signatory_delete_icon() self.click_signatory_delete_icon()
self.wait_for_signatory_delete_prompt() self.wait_for_signatory_delete_prompt()
self.certificate.page.q(css='#prompt-warning a.button.action-primary').first.click() self.q(css='#prompt-warning a.button.action-primary').first.click()
self.certificate.page.wait_for_ajax() self.wait_for_ajax()
def save(self): def save(self):
""" """
Save signatory. Save signatory.
""" """
# Click on the save button. # Click on the save button.
self.certificate.page.q(css='button.signatory-panel-save').click() self.q(css='button.signatory-panel-save').click()
self.mode = 'details' self.mode = 'details'
self.certificate.page.wait_for_ajax() self.wait_for_ajax()
self.wait_for_signatory_detail_view() self.wait_for_signatory_detail_view()
def close(self): def close(self):
""" """
Cancel signatory editing. Cancel signatory editing.
""" """
self.certificate.page.q(css='button.signatory-panel-close').click() self.q(css='button.signatory-panel-close').click()
self.mode = 'details' self.mode = 'details'
self.wait_for_signatory_detail_view() self.wait_for_signatory_detail_view()
...@@ -491,20 +544,20 @@ class Signatory(object): ...@@ -491,20 +544,20 @@ class Signatory(object):
self.wait_for_signature_image_upload_prompt() self.wait_for_signature_image_upload_prompt()
asset_file_path = self.file_path(image_filename) asset_file_path = self.file_path(image_filename)
self.certificate.page.q( self.q(
css='.assetupload-modal .upload-dialog input[type="file"]' css='.assetupload-modal .upload-dialog input[type="file"]'
)[0].send_keys(asset_file_path) )[0].send_keys(asset_file_path)
EmptyPromise( EmptyPromise(
lambda: not self.certificate.page.q( lambda: not self.q(
css='.assetupload-modal a.action-upload.disabled' css='.assetupload-modal a.action-upload.disabled'
).present, ).present,
'Upload button is not disabled anymore' 'Upload button is not disabled anymore'
).fulfill() ).fulfill()
self.certificate.page.q(css='.assetupload-modal a.action-upload').first.click() self.q(css='.assetupload-modal a.action-upload').first.click()
EmptyPromise( EmptyPromise(
lambda: not self.certificate.page.q(css='.assetupload-modal .upload-dialog').visible, lambda: not self.q(css='.assetupload-modal .upload-dialog').visible,
'Upload dialog is removed after uploading image' 'Upload dialog is removed after uploading image'
).fulfill() ).fulfill()
...@@ -518,7 +571,7 @@ class Signatory(object): ...@@ -518,7 +571,7 @@ class Signatory(object):
Returns whether or not the delete icon is present. Returns whether or not the delete icon is present.
""" """
EmptyPromise( EmptyPromise(
lambda: self.certificate.page.q(css='.signatory-panel-delete').present, lambda: self.q(css='.signatory-panel-delete').present,
'Delete icon is displayed' 'Delete icon is displayed'
).fulfill() ).fulfill()
...@@ -527,7 +580,7 @@ class Signatory(object): ...@@ -527,7 +580,7 @@ class Signatory(object):
Promise to wait until signatory delete prompt is visible Promise to wait until signatory delete prompt is visible
""" """
EmptyPromise( EmptyPromise(
lambda: self.certificate.page.q(css='a.button.action-primary').present, lambda: self.q(css='a.button.action-primary').present,
'Delete prompt is displayed' 'Delete prompt is displayed'
).fulfill() ).fulfill()
...@@ -554,7 +607,7 @@ class Signatory(object): ...@@ -554,7 +607,7 @@ class Signatory(object):
Promise to wait until signatory image upload prompt is visible Promise to wait until signatory image upload prompt is visible
""" """
EmptyPromise( EmptyPromise(
lambda: self.certificate.page.q(css='.assetupload-modal .action-upload').present, lambda: self.q(css='.assetupload-modal .action-upload').present,
'Signature image upload dialog opened' 'Signature image upload dialog opened'
).fulfill() ).fulfill()
...@@ -563,7 +616,7 @@ class Signatory(object): ...@@ -563,7 +616,7 @@ class Signatory(object):
Promise to wait until signatory image upload button is visible Promise to wait until signatory image upload button is visible
""" """
EmptyPromise( EmptyPromise(
lambda: self.certificate.page.q(css=".action-upload-signature").first.present, lambda: self.q(css=".action-upload-signature").first.present,
'Signature image upload button available' 'Signature image upload button available'
).fulfill() ).fulfill()
...@@ -573,7 +626,7 @@ class Signatory(object): ...@@ -573,7 +626,7 @@ class Signatory(object):
Promise for the signature image to be displayed Promise for the signature image to be displayed
""" """
EmptyPromise( EmptyPromise(
lambda: self.certificate.page.q(css=".current-signature-image .signature-image").present, lambda: self.q(css=".current-signature-image .signature-image").present,
'Signature image available' 'Signature image available'
).fulfill() ).fulfill()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment