class HubUCourseLogin(BasePageWidget): def __init__(self, owner, locatordict={}): super(HubUCourseLogin,self).__init__(owner,locatordict) # load hub's classes HubUCourseLogin_Locators = self.load_class('HubUCourseLogin_Locators') # update this object's locator self.locators.update(HubUCourseLogin_Locators.locators) # update the locators with those from the owner self.update_locators_from_owner() # setup page object's components self.username = Text(self,{'base':'username'}) self.password = Text(self,{'base':'password'}) self.remember = Checkbox(self,{'base':'remember'}) self.submit = Button(self,{'base':'submit'}) # update the component's locators with this objects overrides self._updateLocators() def login_as(self,username,password,remember=False): """login to the website as the specified user""" self.username.value = username self.password.value = password self.remember.value = remember self.submit.click()
class TimeNewRecordForm(BasePageWidget): def __init__(self, owner, locatordict={}): super(TimeNewRecordForm,self).__init__(owner,locatordict) # load hub's classes TimeNewRecordForm_Locators = self.load_class('TimeNewRecordForm_Locators') # update this object's locator self.locators.update(TimeNewRecordForm_Locators.locators) # update the locators with those from the owner self.update_locators_from_owner() # setup page object's components self.name = TextReadOnly(self,{'base':'name'}) self.hours = Select(self,{'base':'hours'}) self.minutes = Select(self,{'base':'minutes'}) self.date = Text(self,{'base':'date'}) self.hub = Select(self,{'base':'hub'}) self.task = Select(self,{'base':'task'}) self.description = TextArea(self,{'base':'description'}) self.submit = Button(self,{'base':'submit'}) self.cancel = Link(self,{'base':'cancel'}) self.fields = ['hours','minutes','date','hub','task','description'] # update the component's locators with this objects overrides self._updateLocators() def submit_form(self,data): self.populate_form(data) self.submit.click() def cancel_form(self): self.cancel.click() def populate_form(self,data): # data is either a dictionary or string if isinstance(data,dict): for k,v in data.items(): if v is None: # no value to set continue if not k in self.fields: # bail, the key is not a field raise ValueError("invalid form field: %s" % (k)) # find the widget in the object's dictionary and set its value widget = getattr(self,k) widget.value = v else: self.problem.value = data def get_name(self): return re.sub('User: '******'',self.name.value)
class TextSearchBox(BasePageWidget): def __init__(self, owner, locatordict={}): super(TextSearchBox,self).__init__(owner,locatordict) # load hub's classes TextSearchBox_Locators = self.load_class('TextSearchBox_Locators') # update this object's locator self.locators.update(TextSearchBox_Locators.locators) # update the locators with those from the owner self.update_locators_from_owner() # setup page object's components self.text = Text(self,{'base':'text'}) self.submit = Button(self,{'base':'submit'}) # update the component's locators with this objects overrides self._updateLocators() def search_for(self,keyword): """search for a resource by keyword""" self.text.value = keyword self.submit.click()
class TicketListFilterOptions2(BasePageWidget): def __init__(self, owner, locatordict={}): super(TicketListFilterOptions2,self).__init__(owner,locatordict) # load hub's classes TicketListFilterOptions_Locators = self.load_class('TicketListFilterOptions_Locators') # update this object's locator self.locators.update(TicketListFilterOptions_Locators.locators) # update the locators with those from the owner self.update_locators_from_owner() # setup page object's components self.find = Text(self,{'base':'find'}) self.submit = Button(self,{'base':'submit'}) # update the component's locators with this objects overrides self._updateLocators() def _checkLocatorsAdmin(self, widgets=None, cltype='Admin'): self._checkLocators(widgets,cltype) def filter_by_keyword(self,value): self.find.value = value self.submit.click()
class AdminDatabaseTableManageBatchUpdate1(BasePageWidget): def __init__(self, owner, locatordict={}): super(AdminDatabaseTableManageBatchUpdate1,self).__init__(owner,locatordict) # load hub's classes AdminDatabaseTableManageBatchUpdate_Locators = \ self.load_class('AdminDatabaseTableManageBatchUpdate_Locators') # update this object's locator defaults self.locators.update(AdminDatabaseTableManageBatchUpdate_Locators.locators) # update the locators with those from the owner self.update_locators_from_owner() # setup page object's components self.download = Link(self,{'base':'download'}) self.browse = Text(self,{'base':'browse'},click_focus=False) self.upload = Button(self,{'base':'upload'}) # update the component's locators with this objects overrides self._updateLocators() def download_data(self): self.download.click() def upload_data(self,filename): self.browse.value = filename self.upload.click() self.upload.wait_until_invisible()
class TagSearchBox(BasePageWidget): def __init__(self, owner, locatordict={}): super(TagSearchBox,self).__init__(owner,locatordict) # load hub's classes TagSearchBox_Locators = self.load_class('TagSearchBox_Locators') # update this object's locator self.locators.update(TagSearchBox_Locators.locators) # update the locators with those from the owner self.update_locators_from_owner() # setup page object's components self.tags = TextAC(self,{'base':'tags', 'aclocatorid':'tagsac', 'choicelocatorid':'tagsacchoices', 'tokenlocatorid':'tagsactoken', 'deletelocatorid':'tagsacdelete'}) self.submit = Button(self,{'base':'submit'}) # update the component's locators with this objects overrides self._updateLocators() def search_for(self,terms): """perform a search for resources tagged with terms""" self.tags.remove_all() for t in terms: self.tags.send_keys(t+'\n',timeout=-1) self.submit.click()
class AdminDatabaseBackup1(BasePageWidget): def __init__(self, owner, locatordict={}): super(AdminDatabaseBackup1, self).__init__(owner, locatordict) # load hub's classes AdminDatabaseBackup_Locators = self.load_class("AdminDatabaseBackup_Locators") # ItemList = self.load_class('ItemList') # update this object's locator defaults self.locators.update(AdminDatabaseBackup_Locators.locators) # update the locators with those from the owner self.update_locators_from_owner() # setup page object's components self.backup = Button(self, {"base": "backup"}) self.backup_log = TextArea(self, {"base": "backup_log"}) # self.download_list = ItemList(self, # { # 'base' : 'listbase', # 'row' : 'item', # }, Link, # {'base':'download_link'}) # update the component's locators with this objects overrides self._updateLocators() def do_backup(self): """perform a database backup""" oldlog = self.backup_log.value self.backup.click() # wait for the alert to show up self.logger.debug("waiting for database backup confirmation") WebDriverWait(self._browser, 10).until( EC.alert_is_present(), "while waiting for the database backup confirmation" ) self.logger.debug("found confirmation") alert = self._browser.switch_to_alert() alert.accept() self.logger.debug("accepted confirmation") self._browser.switch_to_default_content() def has_new_log_info(driver): driver.refresh() newlog = self.backup_log.value logdiff = newlog[0 : -len(oldlog)] if len(logdiff) > 0: return logdiff else: return False logdiff = WebDriverWait(self._browser, 10).until(has_new_log_info, "while waiting for new backup log info") # return the new log text return logdiff
class TimeNewTaskForm(BasePageWidget): def __init__(self, owner, locatordict={}): super(TimeNewTaskForm,self).__init__(owner,locatordict) # load hub's classes TimeNewTaskForm_Locators = self.load_class('TimeNewTaskForm_Locators') # update this object's locator self.locators.update(TimeNewTaskForm_Locators.locators) # setup page object's components self.name = Text(self,{'base':'name'}) self.active = Radio(self,{'Yes':'active_yes','No':'active_no'}) self.hub = Select(self,{'base':'hub'}) self.start_date = Text(self,{'base':'start_date'}) self.end_date = Text(self,{'base':'end_date'}) self.priority = Select(self,{'base':'priority'}) self.assignee = Select(self,{'base':'assignee'}) self.liaison = Select(self,{'base':'liaison'}) self.description = TextArea(self,{'base':'description'}) self.submit = Button(self,{'base':'submit'}) self.cancel = Link(self,{'base':'cancel'}) self.fields = ['name','active','hub','start_date','end_date', 'priority','assignee','liaison','description'] # update the component's locators with this objects overrides self._updateLocators() def submit_form(self,data): self.populate_form(data) self.submit.click() def cancel_form(self,data): self.cancel.click() def populate_form(self,data): # data is either a dictionary or string if isinstance(data,dict): for k,v in data.items(): if v is None: # no value to set continue if not k in self.fields: # bail, the key is not a field raise ValueError("invalid form field: %s" % (k)) # find the widget in the object's dictionary and set its value widget = getattr(self,k) widget.value = v else: self.problem.value = data
class HubUCourseManageEmailForm(BasePageWidget): """hub u course manager email""" def __init__(self,owner,locatordict={}): super(HubUCourseManageEmailForm,self).__init__(owner,locatordict) # load hub's classes HubUCourseManageEmailForm_Locators = self.load_class('HubUCourseManageEmailForm_Locators') # update this object's locator self.locators.update(HubUCourseManageEmailForm_Locators.locators) # update the locators with those from the owner self.update_locators_from_owner() # setup page object's components self.discard = Link(self,{'base':'discard'}) self.toaddr = TextAC(self,{'base':'to', 'aclocatorid':'toac', 'choicelocatorid':'toacchoices', 'tokenlocatorid':'toactoken', 'deletelocatorid':'toacdelete'}) self.fromaddr = TextReadOnly(self,{'base':'from'}) self.replyto = TextReadOnly(self,{'base':'replyto'}) self.template = Select(self,{'base':'template'}) self.subject = TextReadOnly(self,{'base':'subject'}) self.body = TextReadOnly(self,{'base':'body'}) self.submit = Button(self,{'base':'submit'}) # update the component's locators with this objects overrides self._updateLocators() def _checkLocators(self,widgets=None,cltype=''): # to see all of the widgets, you need to choose a template first options = self.template.options() self.template.choose(options[0]) super(HubUCourseManageEmailForm,self)._checkLocators(widgets,cltype) def send_email(self,tolist,templateName): """send an email to the addresses in tolist using the template templateName""" if tolist != None: self.toaddr.value = tolist if templateName != None: self.template.value = templateName self.submit.click()
class PreviewFormBase(FormBase): def __init__(self, owner, locatordict={}): super(PreviewFormBase,self).__init__(owner,locatordict) # load hub's classes PreviewFormBase_Locators = self.load_class('PreviewFormBase_Locators') # update this object's locator self.locators.update(PreviewFormBase_Locators.locators) # update the locators with those from the owner self.update_locators_from_owner() # setup page object's components self.preview = Button(self,{'base':'preview'}) self.submit = Button(self,{'base':'submit'}) self.fields = [] # update the component's locators with this objects overrides self._updateLocators() def preview_page(self): """preview the page before submitting""" return self.preview.click()
class FilexferImportfilePage(BasePageObject): """ Filexfer upload page """ def __init__(self, owner, locatordict={}): super(FilexferImportfilePage,self).__init__(owner,locatordict) # load hub's classes FilexferImportfilePage_Locators = \ self.load_class('FilexferImportfilePage_Locators') # update this object's locator self.locators = FilexferImportfilePage_Locators.locators # setup page object's components self.upload_type = Radio(self,{'File' : 'upload_type_file', 'Text' : 'upload_type_text'}) self.browse = Text(self,{'base':'browse'},click_focus=False) self.filetext = TextArea(self,{'base':'filetext'}) self.upload = Button(self,{'base':'upload'}) def upload_file(self,filename,timeout=60): """choose a file to upload into the workspace""" self.upload_type.value = 'File' self.browse.value = filename self.upload.click() WebDriverWait(self._browser,timeout)\ .until(EC.title_is('Upload Complete')) def upload_text(self,text,timeout=60): """upload text to a file in the workspace""" self.upload_type.value = 'Text' self.filetext.value = text self.upload.click() WebDriverWait(self._browser,timeout)\ .until(EC.title_is('Upload Complete'))
class ResourcesNewAttachForm(BasePageWidget): def __init__(self, owner, locatordict=None): super(ResourcesNewAttachForm,self).__init__(owner,locatordict) # load hub's classes ResourcesNewAttachForm_Locators = self.load_class('ResourcesNewAttachForm_Locators') UploadList1 = self.load_class('UploadList1') # update this object's locator self.locators.update(ResourcesNewAttachForm_Locators.locators) # update the locators with those from the owner self.update_locators_from_owner() # setup page object's components self.upload = IframeWrap( Upload(self,{'browselocatorid':'browse', 'uploadlocatorid':'upload',}), ['uploadframe']) self.uploadlist = UploadList1(self,{'base':'iframe'}) self.submit = Button(self,{'base':'submit'}) # update the component's locators with this objects overrides self._updateLocators() def upload_files(self,flist): """upload the files in the list flist""" for fname in flist: self.upload.value = fname def get_uploaded_files(self): """return the list of uploaded files""" return self.uploadlist.get_uploaded_files() def delete_file(self,filename): """delete an uploaded file""" return self.uploadlist.delete_file(filename) def submit_form(self,flist): """upload and attach the list of files in flist""" self.upload_files(flist) return self.submit.click()
class ToolsStatusApproveToolInfoForm(BasePageWidget): def __init__(self, owner, locatordict={}): super(ToolsStatusApproveToolInfoForm,self).__init__(owner,locatordict) # load hub's classes ToolsStatusApproveToolInfoForm_Locators = \ self.load_class('ToolsStatusApproveToolInfoForm_Locators') # update this object's locator self.locators.update(ToolsStatusApproveToolInfoForm_Locators.locators) # update the locators with those from the owner self.update_locators_from_owner() # setup page object's components self.tool_info = Link(self,{'base':'tool_info'}) self.title = TextReadOnly(self,{'base':'title'}) self.version = TextReadOnly(self,{'base':'version'}) self.version_edit = Link(self,{'base':'version_edit'}) self.description = TextReadOnly(self,{'base':'description'}) self.tool_access = TextReadOnly(self,{'base':'tool_access'}) self.code_access = TextReadOnly(self,{'base':'code_access'}) self.project_access = TextReadOnly(self,{'base':'project_access'}) self.screen_size = TextReadOnly(self,{'base':'screen_size'}) self.developers = TextReadOnly(self,{'base':'developers'}) self.authors = TextReadOnly(self,{'base':'authors'}) self.resource_preview = Link(self,{'base':'resource_preview'}) self.license_edit = Link(self,{'base':'license_edit'}) self.license = TextReadOnly(self,{'base':'license'}) self.approve = Button(self,{'base':'approve'}) # update the component's locators with this objects overrides self._updateLocators() def edit_tool_info(self): """ edit the tool's information """ self.tool_info.click() def edit_version(self): """ edit the tool's version """ self.version.click() def preview_resource_page(self): """ navigate to the resource page preview """ self.resource_preview.click() def edit_license(self): """ edit the tool license """ self.license_edit.click() def value(self): """ return a summary of the widget """ v = {'title' : self.title.value, 'version' : self.version.value, 'description' : self.description.value, 'tool_access' : self.tool_access.value, 'source_access' : self.source_access.value, 'project_access' : self.project_access.value, 'screen_size' : self.screen_size.value, 'developers' : self.developers.value, 'authors' : self.authors.value, 'license' : self.license.value, } return v def approve_tool(self): """ approve the tool's version, license, and info. """ self.approve.click()
class ResourcesNewAuthorsForm(BasePageWidget): def __init__(self, owner, locatordict={}): super(ResourcesNewAuthorsForm,self).__init__(owner,locatordict) # load hub's classes ResourcesNewAuthorsForm_Locators = self.load_class('ResourcesNewAuthorsForm_Locators') ResourcesNewAuthorsAuthorsForm = self.load_class('ResourcesNewAuthorsAuthorsForm') ResourcesNewAuthorsAuthorsList = self.load_class('ResourcesNewAuthorsAuthorsList') # update this object's locator self.locators.update(ResourcesNewAuthorsForm_Locators.locators) # update the locators with those from the owner self.update_locators_from_owner() # setup page object's components self.group = Select(self,{'base':'group'}) self.access = Select(self,{'base':'access'}) self.authorform = IframeWrap( ResourcesNewAuthorsAuthorsForm( self,{'base':'authorsform'}), ['authorsframe']) self.authorlist = IframeWrap( ResourcesNewAuthorsAuthorsList( self,{'base':'authorslist'}), ['authorsframe']) self.submit = Button(self,{'base':'submit'}) self.fields = ['group','access'] # update the component's locators with this objects overrides self._updateLocators() def get_groups(self): return self.group.options() def get_access_levels(self): return self.access.options() def populate_form(self, data): for k,v in data.items(): if v is None: continue if not k in self.fields: # bail, the key is not a field raise ValueError("invalid form field: %s" % (k)) # find the widget in the object's dictionary and set its value widget = getattr(self,k) widget.value = v def submit_form(self,data): self.populate_form(data) return self.submit.click() def populate_authors_form(self,data): return self.authorform.populate_form(data) def submit_authors_form(self,data): return self.authorform.submit_form(data) def get_authors(self): """return a list of authors""" return self.authorlist.get_authors() def author_role(self,author,role=None): """adjust an author's role""" return self.authorlist.author_role(author,role) def move_author_up(self,author): """increase an author's position""" return self.authorlist.move_author_up(author) def move_author_down(self,author): """decrease an author's position""" return self.authorlist.move_author_down(author) def delete_author(self,author): """remove an author from the list""" return self.authorlist.delete_author(author) def author_organization(self,author,org=None): """set an author's organization""" return self.authorlist.author_organization(author,org)
class TimeNewHubForm(BasePageWidget): def __init__(self, owner, locatordict={}): super(TimeNewHubForm,self).__init__(owner,locatordict) # load hub's classes TimeNewHubForm_Locators = self.load_class('TimeNewHubForm_Locators') WikiTextArea = self.load_class('WikiTextArea') # update this object's locator self.locators.update(TimeNewHubForm_Locators.locators) # update the locators with those from the owner self.update_locators_from_owner() # setup page object's components self.hubname = Text(self,{'base':'hubname'}) self.contact_name = Text(self,{'base':'contact_name'}) self.contact_phone = Text(self,{'base':'contact_phone'}) self.contact_email = Text(self,{'base':'contact_email'}) self.contact_role = Text(self,{'base':'contact_role'}) self.liaison = Text(self,{'base':'liaison'}) self.anniversary = Text(self,{'base':'anniversary'}) self.support = Select(self,{'base':'support'}) self.notes = WikiTextArea(self,{'base':'notes'}) self.submit = Button(self,{'base':'submit'}) self.cancel = Link(self,{'base':'cancel'}) self.fields = ['hubname','contact_name','contact_phone', 'contact_email','contact_role','liaison', 'anniversary','support','notes'] # update the component's locators with this objects overrides self._updateLocators() def submit_form(self,data): self.populate_form(data) self.submit.click() def cancel_form(self): self.cancel.click() def populate_form(self,data): # data is either a dictionary or string if isinstance(data,dict): for k,v in data.items(): if v is None: # no value to set continue if not k in self.fields: # bail, the key is not a field raise ValueError("invalid form field: %s" % (k)) # find the widget in the object's dictionary and set its value widget = getattr(self,k) widget.value = v else: self.problem.value = data
class Resources(BasePageWidget): def __init__(self, owner, locatordict={}): super(Resources, self).__init__(owner, locatordict) # load hub's classes Resources_Locators = self.load_class("Resources_Locators") ResourcesCategoryBrowser = self.load_class("ResourcesCategoryBrowser") # update this object's locator self.locators.update(Resources_Locators.locators) # update the locators with those from the owner self.update_locators_from_owner() # setup page object's components self.create = Link(self, {"base": "create"}) self.faq = Link(self, {"base": "faq"}) self.search = Text(self, {"base": "searchi"}) self.submit = Button(self, {"base": "searchb"}) self.browse = Link(self, {"base": "browse"}) self.catbrowser = ResourcesCategoryBrowser(self, {"base": "catbrowser"}) # update the component's locators with this objects overrides self._updateLocators() def goto_create(self): """click the resource create link""" self.create.click() def goto_faq(self): """click the resource faq link""" self.faq.click() def search_resources(self, searchtext): """perform a search on resources""" self.search.value = searchtext self.submit.click() def goto_browse_list(self): """click the browse resources link""" self.browse.click() def goto_category_by_browse(self, category): """click a category""" return self.catbrowser.goto_category_by_browse(category) def goto_category_by_title(self, category): """click a category title""" return self.catbrowser.goto_category_by_title(category) def get_category_titles(self): """return a list of category titles""" return self.catbrowser.get_category_titles() def get_category_classes(self): """return a list of category classes""" return self.catbrowser.get_category_classes()
class TroubleReportForm(BasePageWidget): def __init__(self, owner, locatordict={}, refreshCaptchaCB=None): super(TroubleReportForm,self).__init__(owner,locatordict) # load hub's classes TroubleReportForm_Locators = self.load_class('TroubleReportForm_Locators') Captcha2 = self.load_class('Captcha2') # update this object's locator self.locators.update(TroubleReportForm_Locators.locators) # update the locators with those from the owner self.update_locators_from_owner() # setup page object's components self.username = Text(self,{'base':'username'}) self.name = Text(self,{'base':'name'}) self.email = Text(self,{'base':'email'}) self.problem = TextArea(self,{'base':'problem'}) self.upload = Upload(self,{'base':'upload','browselocatorid':'upload'}) self.submit = Button(self,{'base':'submit'},self._onClick) self.ticketlink = Link(self,{'base':'ticket_link'}) self.captcha = Captcha2(self,{'base':'captcha'},refreshCaptchaCB) self.fields = ['username','name','email','problem','upload','captcha'] # update the component's locators with this objects overrides self._updateLocators() def _checkLocatorsLoggedIn(self,widgets=None,cltype='LoggedIn'): widgets = [self.username, self.name, self.email, self.problem, self.upload, self.submit] self._checkLocators(widgets,cltype) def _checkLocatorsLoggedOut(self,widgets=None,cltype='LoggedOut'): widgets = [self.username, self.name, self.email, self.problem, self.upload, self.submit, self.captcha] self._checkLocators(widgets,cltype) def _checkLocatorsSubmitted(self,widgets=None,cltype=''): widgets = [self.ticketlink] self._checkLocators(widgets,cltype) def submit_ticket(self, data): self.populate_form(data) # submit the ticket ticket_number = self.submit.click() self.logger.debug('ticket_number = %s' % (ticket_number)) return ticket_number def populate_form(self, data): # data is either a dictionary or string if isinstance(data,dict): for k,v in data.items(): if v is None: # no value to set continue if not k in self.fields: # bail, the key is not a field raise ValueError("invalid form field: %s" % (k)) # find the widget in the object's dictionary and set its value widget = getattr(self,k) widget.value = v else: self.problem.value = data def _onClick(self): # FIXME: change the webdriverwait to an ec # that returns the element # wait for the page to refresh message = "while waiting for ticket to be submitted" wait = WebDriverWait(self._browser, 60) wait.until(lambda browser : browser.find_element_by_id("trSuccess").is_displayed(), message=message) ticket_number = self.ticketlink.text() return ticket_number def goto_ticket(self): e = self.find_element(self.locators['ticket_link']) e.click()
class FormBase(BasePageWidget): def __init__(self, owner, locatordict={}): super(FormBase,self).__init__(owner,locatordict) # load hub's classes FormBase_Locators = self.load_class('FormBase_Locators') # update this object's locator self.locators.update(FormBase_Locators.locators) # update the locators with those from the owner self.update_locators_from_owner() # setup page object's components self.submit = Button(self,{'base':'submit'}) self.fields = [] # update the component's locators with this objects overrides self._updateLocators() def populate_form(self, data): """populate the form with data from the data parameter""" if hasattr(data,'items'): # convert dictionaries to lists # so we can support filling out forms in order data = data.items() self._po.wait_for_page_element_displayed( loc=self.locators['base']) self.logger.debug('form data = %s' % (pprint.pformat(data))) for (k,v) in data: if v is None: continue if not k in self.fields: # bail, the key is not a field raise ValueError("invalid form field: %s" % (k)) # find the widget in the object's dictionary and set its value widget = getattr(self,k) widget.value = v def submit_form(self,data={}): """submit the form, fill in data if it is provided""" self.populate_form(data) # we use a page marker to tell when the form has been submitted. some # websites lead back to the original page, which makes it hard to tell # that the form submission has completed by using elements available on # the page. we use a page load marker to help us with that task. self._po.set_page_load_marker() result = self.submit.click() self._po.wait_for_page_load_marker() return result
class HubUCourseMembershipListing(BasePageWidget): def __init__(self, owner, locatordict={}): super(HubUCourseMembershipListing,self).__init__(owner,locatordict) # load hub's classes HubUCourseMembershipListing_Locators = self.load_class('HubUCourseMembershipListing_Locators') HubUCourseMembershipListingMemberRow = self.load_class('HubUCourseMembershipListingMemberRow') HubUCourseMembershipListingDetailRow = self.load_class('HubUCourseMembershipListingDetailRow') # update this object's locator self.locators.update(HubUCourseMembershipListing_Locators.locators) # update the locators with those from the owner self.update_locators_from_owner() # setup page object's components self.member_row = HubUCourseMembershipListingMemberRow(self,{'base':'enrollee_row'}) self.detail_row = HubUCourseMembershipListingDetailRow(self,{'base':'detail_row'}) self.action = Select(self,{'base':'action'}) self.action_submit = Button(self,{'base':'action_submit'}) self.get_enroll = Link(self,{'base':'get_enroll'},self._onClick) self.export_enroll = Link(self,{'base':'export_enroll'}) self.members = TextReadOnly(self,{'base':'members'}) self.total = TextReadOnly(self,{'base':'total'}) self.member_data = {} # update the component's locators with this objects overrides self._updateLocators() def update_enrollment(self): """click the update enrollment link""" self.get_enroll.click() def select_imported(self): """check the checkboxes of all imported course members""" count = 0 imported_cbs = self.find_elements(self.locators['imported_cb']) for cb in imported_cbs: cb.click() count += 1 return count def select_invited(self): """check the checkboxes of all invited course members""" count = 0 invited_cbs = self.find_elements(self.locators['invited_cb']) for cb in invited_cbs: cb.click() count += 1 return count def select_members(self): """check the checkboxes of all member course members""" count = 0 member_cbs = self.find_elements(self.locators['member_cb']) for cb in member_cbs: cb.click() count += 1 return count def get_footer_members_count(self): """retrieve the number of members in the group from the footer""" return self.members.value def get_footer_total_count(self): """retrieve the total number of people in the group from the footer""" return self.total.value def count_imported_rows(self): """retrieve the number of imported rows in the table""" return len(self.find_elements(self.locators['imported_row'])) def count_invited_rows(self): """retrieve the number of invited rows in the table""" return len(self.find_elements(self.locators['invited_row'])) def count_member_rows(self): """retrieve the number of member rows in the table""" return len(self.find_elements(self.locators['member_row'])) def count_total_rows(self): """retrieve the number of total rows in the table""" return len(self.find_elements(self.locators['enrollee_row'])) def prepare_to_send_email(self): """select the 'Send Email' action and goto the email page""" self.action.choose('Send Email') self.action_submit.click() def retrieve_members(self,save_cb=None, continue_cb=None, reverse=False): """return a list of member data from the table that match the specified criteria""" self.member_data = {} total = int(self.total.value) if reverse == False: start = 1 end = total + 1 step = 1 else: start = total end = 1 - 1 step = -1 for index in xrange(start,end,step): didx = index*2 midx = didx-1 # FIXME: move the css code into locator file mlocator = self.locators['traversal_row'] % midx dlocator = self.locators['traversal_row'] % didx self.member_row.locator = mlocator name = self.member_row.name.text() # open the hidden detail row self.member_row.name.click() self.detail_row.locator = dlocator enroll_id = self.detail_row.enroll_id.value enroll_date = self.detail_row.enroll_date.value import_date = self.detail_row.import_date.value invite_sent = self.detail_row.invite_sent.value invite_accept = self.detail_row.invite_accept.value # close the detail row self.member_row.name.click() save = True cont = True mdata = { 'name' : name, 'enroll_id' : enroll_id, 'enroll_date' : enroll_date, 'import_date' : import_date, 'invite_sent' : invite_sent, 'invite_accept' : invite_accept, } if continue_cb: cont = continue_cb(mdata) if not cont: break if save_cb: save = save_cb(mdata) if save: self.member_data[midx] = { 'name' : name, 'enroll_id' : enroll_id, 'enroll_date' : enroll_date, 'import_date' : import_date, 'invite_sent' : invite_sent, 'invite_accept' : invite_accept, '__mlocator__' : mlocator, '__dlocator__' : dlocator, } return self.member_data def find_by_import_date(self,dtobj): """retrieve table data that matches the specified datetime object""" # date_object = datetime.strptime('Jun 1 2005 1:33PM', '%b %d %Y %I:%M%p') def callback(name, enroll_id, enroll_date, import_date, invite_sent, invite_accept): import_date_dt = datetime.strptime(import_date, '%b %d, %Y') return import_date_dt == dtobj return self.retrieve_members(callback) def select_retrieved_members(self): """check the 'select' box of members retrieved from the 'retrieve_members' method""" for [k,v] in self.member_data.items(): self.member_row.locator = v['__mlocator__'] self.member_row.cb_email.value = True def _onClick(self): """callback function for updating enrollments""" try: # wait for the page to refresh wait = WebDriverWait(self._browser, 30) wait.until(lambda browser : browser.find_element_by_id("course-notice").is_displayed()) except TimeoutException: # browser.save_screenshot_as_base64 # self._browser.save_screenshot_as_file("need_help.submitted-1.png") raise TimeoutException("Timeout while waiting to retrieve new enrollments") # FIXME: check if the notice text is # "Enrollment Updates\n\nThere are no new enrollments or enrollment changes at this time." #e = self.find_element(self.locators['notice']) #ticket_number = e.text #return ticket_number return True
class WishlistNewWishForm(BasePageWidget): def __init__(self, owner, locatordict={}, refreshCaptchaCB=None): super(WishlistNewWishForm,self).__init__(owner,locatordict) # load hub's classes WishlistNewWishForm_Locators = self.load_class('WishlistNewWishForm_Locators') # update this object's locator self.locators.update(WishlistNewWishForm_Locators.locators) # update the locators with those from the owner self.update_locators_from_owner() # setup page object's components self.anonymous = Checkbox(self,{'base':'anonymous'}) self.private = Checkbox(self,{'base':'private'}) self.subject = Text(self,{'base':'subject'}) self.problem = TextArea(self,{'base':'problem'}) self.tags = TextAC(self,{'base':'tags', 'aclocatorid':'tagsac', 'choicelocatorid':'tagsacchoices', 'tokenlocatorid':'tagsactoken', 'deletelocatorid':'tagsacdelete'}) self.submit = Button(self,{'base':'submit'}) self.fields = ['anonymous','private','subject','problem','tags'] # update the component's locators with this objects overrides self._updateLocators() def _checkLocatorsNonAdmin(self,widgets=None,cltype='NonAdmin'): widgets = [self.anonymous, self.subject, self.problem, self.tags, self.submit] self._checkLocators(widgets,cltype) def _checkLocatorsAdmin(self,widgets=None,cltype='Admin'): widgets = [self.anonymous, self.private, self.subject, self.problem, self.tags, self.submit] self._checkLocators(widgets,cltype) def submit_wish(self,data): # data is either a dictionary or string if isinstance(data,dict): for k,v in data.items(): if v is None: # no value to set continue if not k in self.fields: # bail, the key is not a field raise ValueError("invalid form field: %s" % (k)) # find the widget in the object's dictionary and set its value widget = getattr(self,k) widget.value = v else: self.subject.value = data # submit the wish self.submit.click()
class ResourcesNewAuthorsAuthorsList(BasePageWidget): def __init__(self, owner, locatordict={}): super(ResourcesNewAuthorsAuthorsList,self).__init__(owner,locatordict) # load hub's classes ResourcesNewAuthorsAuthorsList_Locators = \ self.load_class('ResourcesNewAuthorsAuthorsList_Locators') # update this object's locator self.locators.update(ResourcesNewAuthorsAuthorsList_Locators.locators) # update the locators with those from the owner self.update_locators_from_owner() # setup page object's components self.submit = Button(self,{'base':'submit'}) # update the component's locators with this objects overrides self._updateLocators() def _get_author(self,rowEle): column = self.find_element(self.locators['nameorg'],rowEle) org = self.find_element(self.locators['organization'],rowEle) authorname = re.sub(org.text,'',column.text) return authorname def _get_author_row(self,author): rows = [] try: rows = self.find_elements_in_owner(self.locators['author_row']) except NoSuchElementException: # there are no authors rows = [] for rowEle in rows: authorname = self._get_author(rowEle) if authorname == author: return rowEle raise NoSuchUserException("could not find author: '%s'" % (author)) def get_authors(self): """return the list of authors""" names = [] rows = [] try: rows = self.find_elements_in_owner(self.locators['author_row']) except NoSuchElementException: # there are no authors rows = [] for rowEle in rows: authorname = self._get_author(rowEle) names.append(authorname) return names def author_role(self,author,role=None): """adjust the role for an author, returning the old role""" rowEle = self._get_author_row(author) roleEle = self.find_element(self.locators['role'],rowEle) #FIXME: shenanigans begin roleid = roleEle.get_attribute('id') key = "roleid-%s" % (roleid) self.locators[key] = "css=#%s" % (roleid) obj = Select(self,{'base':key}) obj.detach_from_owner() #FIXME: shenanigans end oldrole = obj.selected() if role: obj.value = role # click the "save changes" button self.submit.click() del obj del self.locators[key] return oldrole def move_author_up(self,author): """increase the author's position""" rowEle = self._get_author_row(author) b = self.find_element(self.locators['up'],rowEle) b.click() def move_author_down(self,author): """decrease the author's position""" rowEle = self._get_author_row(author) b = self.find_element(self.locators['down'],rowEle) b.click() def delete_author(self,author): """remove an author from the list""" rowEle = self._get_author_row(author) b = self.find_element(self.locators['trash'],rowEle) b.click() def author_organization(self,author,org=None): """set an author's organization""" rowEle = self._get_author_row(author) orgEle = self.find_element(self.locators['organization'],rowEle) #FIXME: shenanigans begin orgName = orgEle.get_attribute('name') key = "orgName-%s" % (orgName) self.locators[key] = "css=[name='%s']" % (orgName) obj = Text(self,key) obj.detach_from_owner() #FIXME: shenanigans end oldorg = obj.value if org: obj.value = org # click the "save changes" button self.submit.click() del obj del self.locators[key] return oldorg
class ToolSessionShare(BasePageWidget): def __init__(self, owner, locatordict={}): super(ToolSessionShare, self).__init__(owner, locatordict) # load hub's classes ToolSessionShare_Locators = self.load_class("ToolSessionShare_Locators") ToolSessionSharedWithItem = self.load_class("ToolSessionSharedWithItem") ItemList = self.load_class("ItemList") # update this object's locator self.locators.update(ToolSessionShare_Locators.locators) # update the locators with those from the owner self.update_locators_from_owner() # setup page object's components self.name = TextAC( self, { "base": "name", "aclocatorid": "nameac", "choicelocatorid": "nameacchoices", "tokenlocatorid": "nameactoken", "deletelocatorid": "nameacdelete", }, ) self.group = Select(self, {"base": "group"}) self.read_only = Checkbox(self, {"base": "readonly"}) self.share = Button(self, {"base": "share"}) self.share_list = ItemList(self, {"base": "listbase", "row": "item"}, ToolSessionSharedWithItem, {}) # update the component's locators with this objects overrides self._updateLocators() def share_session_with(self, sharelist=None, group=None, readonly=False): # we don't handle cases where no sharelist or group is provided if sharelist is None and group is None: return if sharelist is not None: self.name.value = sharelist if group is not None: self.group.value = group self.read_only.value = readonly self.share.click() self.wait_for_overlay("waiting for session to be shared") def get_shared_with(self): shared_with = [] try: for item in self.share_list: shared_with.append(item.name.text()) except TimeoutException: pass return shared_with def disconnect(self, user): if self.share_list.num_rows() == 0: msg = "Could not find matching connected user: {0}".format(user) raise NoSuchUserException(msg) item = self.share_list.get_row_by_property("name", user) if item is None: # try a little harder to find the row # see if any row's name property contain user compare = lambda x, y: y in x item = self.share_list.get_row_by_property("name", user, compare) if item is None: msg = "Could not find matching connected user: {0}".format(user) raise NoSuchUserException(msg) item.disconnect.click() self.wait_for_overlay("waiting for session to be disconnected") def disconnect_all(self): # deleteing rows messes up the internal count of the share_list # as we disconnect, we grab the next item at the top. for count in xrange(self.share_list.num_rows()): item = self.share_list.get_row_by_position(0) item.disconnect.click() self.wait_for_overlay("waiting for session to be disconnected") def wait_for_overlay(self, message=None): """let the share overlay flash on the screen """ loctype, loctext = self._po._split_locator(self.locators["shareoverlay"]) WebDriverWait(self._browser, 10).until(EC.visibility_of_element_located((loctype, loctext)), message=message) WebDriverWait(self._browser, 10).until_not( EC.visibility_of_element_located((loctype, loctext)), message=message )
class ResourcesToolAttachmentsForm(BasePageWidget): def __init__(self, owner, locatordict=None): super(ResourcesToolAttachmentsForm,self).__init__(owner,locatordict) # load hub's classes ResourcesToolAttachmentsForm_Locators = \ self.load_class('ResourcesToolAttachmentsForm_Locators') ResourcesToolFileUploadRow = \ self.load_class('ResourcesToolFileUploadRow') ResourcesToolScreenshotUploadRow = \ self.load_class('ResourcesToolScreenshotUploadRow') Upload3 = self.load_class('Upload3') # update this object's locator self.locators.update(ResourcesToolAttachmentsForm_Locators.locators) # update the locators with those from the owner self.update_locators_from_owner() # setup page object's components # self.documents_upload = IframeWrap( # Upload(self, # {'browselocatorid':'doc_browse', # 'uploadlocatorid':'doc_upload',}), # ['doc_upload_frame']) # # self.documents_list = IframeWrap(['doc_upload_frame'] # ItemList, {'base':'doc_list', # 'row':'doc_list_row'}, # IframeWrap, {'base':'doc_upload_frame'}, # ResourcesToolFileUploadRow, {}) self.documents = Upload3(self,{'uploadframe':'doc_upload_frame', 'browse':'doc_browse', 'upload':'doc_upload', 'fileframe':'doc_list_frame', 'uploadlist':'doc_list', 'uploadlistrow':'doc_list_row'}, ResourcesToolFileUploadRow,{}) self.screenshots = Upload3(self,{'uploadframe':'screenshot_upload_frame', 'browse':'screenshot_browse', 'upload':'screenshot_upload', 'fileframe':'screenshot_list_frame', 'uploadlist':'screenshot_list', 'uploadlistrow':'screenshot_list_row'}, ResourcesToolScreenshotUploadRow,{}) # self.screenshot_upload = IframeWrap(self, # {'base':'screenshot_upload_frame'}, # Upload, # {'browselocatorid':'screenshot_browse', # 'uploadlocatorid':'screenshot_upload',}) # # self.screenshot_list = IframeWrap(self, # {'base':'screenshot_upload_frame'}, # ItemList, # {'base':'screenshot_list', # 'row':'screenshot_list_row'}, # IframeWrap, # {'base':'screenshot_upload_frame'}, # ResourcesToolScreenshotUploadRow, {}) self.top_previous = Button(self,{'base':'top_previous'}) self.top_submit = Button(self,{'base':'top_submit'}) self.previous = Button(self,{'base':'previous'}) self.submit = Button(self,{'base':'submit'}) # update the component's locators with this objects overrides self._updateLocators() def upload_files(self,flist): """upload the files in the list flist""" for fname in flist: self.documents_upload.value = fname def get_uploaded_files(self): """return the list of uploaded files""" fnames = [] for row in self.documents_list: fnames.append(row.value['name']) return fnames def delete_file(self,filename): """delete an uploaded file""" for row in self.documents_list: if row.value['name'] == filename: row.delete.click() def submit_form(self,flist): """upload and attach the list of files in flist""" self.upload_files(flist) return self.submit.click()