class ToolSessionSharedWithItem(ItemListItem): def __init__(self, owner, locatordict={},row_number=0): super(ToolSessionSharedWithItem,self)\ .__init__(owner,locatordict,row_number) # load hub's classes ToolSessionSharedWithItem_Locators = \ self.load_class('ToolSessionSharedWithItem_Locators') # update this object's locator self.locators.update(ToolSessionSharedWithItem_Locators.locators) # update the locators with those from the owner self.update_locators_from_owner() # setup page object's components self.name = Link(self,{'base':'name'}) self.disconnect = Link(self,{'base':'disconnect'}) # update the component's locators with this objects overrides self._updateLocators() def value(self): """return a dictionary of properties for this item""" properties = { 'name' : self.name.text(), } return properties
class GroupsTitle2(BasePageWidget): def __init__(self, owner, locatordict={}): super(GroupsTitle2,self).__init__(owner,locatordict) # load hub's classes GroupsTitle_Locators = self.load_class('GroupsTitle_Locators') # update this object's locator self.locators.update(GroupsTitle_Locators.locators) # update the locators with those from the owner self.update_locators_from_owner() # setup page object's components self.title = Link(self,{'base':'title'}) # update the component's locators with this objects overrides self._updateLocators() def get_title(self): """return the title of the group""" return self.title.text() def goto_title(self): """click the group title link""" return self.title.click()
class TagsViewResultsRow(ItemListItem): def __init__(self, owner, locatordict={}, row_number=0): super(TagsViewResultsRow, self).__init__(owner, locatordict, row_number) # load hub's classes TagsViewResultsRow_Locators = self.load_class("TagsViewResultsRow_Locators") # update this object's locator self.locators.update(TagsViewResultsRow_Locators.locators) # update the locators with those from the owner self.update_locators_from_owner() # setup page object's components self.title = Link(self, {"base": "title"}) self.text = TextReadOnly(self, {"base": "text"}) self.href = TextReadOnly(self, {"base": "href"}) # update the component's locators with this objects overrides self._updateLocators() def value(self): """return a dictionary with the title, text, and href properties of the tag""" return {"title": self.title.text(), "text": self.text.value, "href": self.href.value} def goto_resource(self): """click the resource link""" self.title.click()
class TagsBrowseResultsRow1(ItemListItem): def __init__(self, owner, locatordict={}, row_number=0): super(TagsBrowseResultsRow1,self).__init__(owner,locatordict,row_number) # load hub's classes TagsBrowseResultsRow_Locators = self.load_class('TagsBrowseResultsRow_Locators') # update this object's locator self.locators.update(TagsBrowseResultsRow_Locators.locators) # update the locators with those from the owner self.update_locators_from_owner() # setup page object's components self.name = Link(self,{'base':'name'}) self.count = TextReadOnly(self,{'base':'count'}) # update the component's locators with this objects overrides self._updateLocators() def value(self): """return a dictionary with the name and count properties of the tag""" return({'name':self.name.text(), 'count':int(self.count.value)}) def goto_tag(self): """click the tag""" self.name.click()
class PopularItem(BasePageWidget): def __init__(self, owner, locatordict={}, item_number=0): # initialize variables self.__item_number = item_number super(PopularItem,self).__init__(owner,locatordict) # load hub's classes object_locators = self.load_class('PopularItem_Locators') # update this object's locator self.locators.update(object_locators.locators) # update the locators with those from the owner self.update_locators_from_owner() # setup page object's components self.title = Link(self,{'base':'title'}) self.description = TextReadOnly(self,{'base':'description'}) # update the component's locators with this objects overrides self._updateLocators() def _updateLocators(self): super(PopularItem,self)._updateLocators() for k,v in self.locators.items(): self.locators[k] = v % self.__item_number self.update_locators_in_widgets() def value(self): """return a dictionary with the properties of the group""" return({'title':self.title.text(),'description':self.description.value}) def goto_group(self): """click the group title""" self.title.click()
class ToolsPipelineSearchResultRow(ItemListItem): def __init__(self, owner, locatordict={},row_number=0): super(ToolsPipelineSearchResultRow,self)\ .__init__(owner,locatordict,row_number) # load hub's classes ToolsPipelineSearchResultRow_Locators = \ self.load_class('ToolsPipelineSearchResultRow_Locators') # update this object's locator self.locators.update(ToolsPipelineSearchResultRow_Locators.locators) # update the locators with those from the owner self.update_locators_from_owner() # setup page object's components self.title = Link(self,{'base':'title'}) self.details = TextReadOnly(self,{'base':'details'}) self.alias = Link(self,{'base':'alias'}) self.status = Link(self,{'base':'status'}) self.time = TextReadOnly(self,{'base':'time'}) self.resource = Link(self,{'base':'resource'}) self.history = Link(self,{'base':'history'}) self.wiki = Link(self,{'base':'wiki'}) # update the component's locators with this objects overrides self._updateLocators() def _checkLocators(self,widgets=None,cltype=''): widgets = [self.title,self.details,self.alias,self.status, self.time,self.resource,self.history,self.wiki] super(ToolsPipelineSearchResultRow,self)._checkLocators(widgets,cltype) def value(self): """return a dictionary of properties for this row""" properties = { 'title' : self.title.text(), 'details' : self.details.value, 'alias' : self.alias.text(), 'status' : self.status.text(), 'time' : self.time.value, } return properties def goto_title(self): self.title.click() def get_details(self): return self.details.value def goto_alias(self): self.alias.click() def goto_status(self): self.status.click() def get_time(self): return self.time.value def goto_resource(self): self.resource.click() def goto_history(self): self.history.click() def goto_wiki(self): self.wiki.click()
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 TicketCommentBase(ItemListItem): def __init__(self, owner, locatordict={}, row_number=0): super(TicketCommentBase,self).__init__(owner,locatordict,row_number) # load hub's classes TicketCommentBase_Locators = self.load_class('TicketCommentBase_Locators') # update this object's locator self.locators.update(TicketCommentBase_Locators.locators) # update the locators with those from the owner self.update_locators_from_owner() # setup page object's components self.commenter = Link(self,{'base':'commenter'}) self.body = TextReadOnly(self,{'base':'body'}) # update the component's locators with this objects overrides self._updateLocators() def get_commenter(self): """return the commenter""" return self.commenter.text() def get_body(self): """return the body of the comment""" return self.body.value def download_attachment(self,attachment): """download a file attachment in the comment""" links = [] try: # ticket content widgets (and old style comments?) # store downloadable content in the body bodytext = self.find_element_in_owner(self.locators['body']) links.extend(self.find_elements('css=a',bodytext)) except NoSuchElementException as e: self.logger.exception(e) pass try: # ticket comments store downloadable content in the # attachments section attext = self.find_element_in_owner(self.locators['attachments']) links.extend(self.find_elements('css=a',attext)) except NoSuchElementException as e: self.logger.exception(e) pass download_element = None href = None for link in links: href = link.get_attribute('href') self.logger.debug('found link: %s' % (href)) if re.search(attachment,href): download_element = link break if download_element is None: raise NoSuchFileAttachmentError(attachment) download_element.click() return href def download_image(self,imageName): """ download an image file attachment in the comment """ # click the link to download the image self.download_attachment(imageName) # clicking the download link takes user to another # webpage with just an image return the src # attribute of the image e = self.find_element(self.locators['image']) return e.get_attribute('src')
class ResourcesToolFileUploadRow(ItemListItem): def __init__(self, owner, locatordict={}, row_number=0): super(ResourcesToolFileUploadRow,self).__init__(owner,locatordict,row_number) # load hub's classes ResourcesToolFileUploadRow_Locators = self.load_class('ResourcesToolFileUploadRow_Locators') # update this object's locator self.locators.update(ResourcesToolFileUploadRow_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.show = Link(self,{'base':'show'},self._onClickShow) self.delete = Link(self,{'base':'delete'},self._onClickDelete) # update the component's locators with this objects overrides self._updateLocators() def _onClickShow(self): self.show.wait_until_invisible() def _onClickDelete(self): self.delete.wait_until_invisible() def rename(self,name): """rename the uploaded document""" # use action chains to double click on the name, # and fill in a new value # the documentation above the widget says the user # needs to double click, but it appears a single # click will work. it also says tab or enter # save, but i don't think these keys do anything e = self.name.wait_until_visible() ActionChains(self._browser)\ .double_click(e)\ .perform() t = Text(self,{'base':'rename_text'}) s = Button(self,{'base':'rename_save'}) t.wait_until_visible() t.value = name s.click() s.wait_until_not_present() del t del s def value(self): """return a dictionary with the name and size properties""" # show text looks like this: # <filename>, <size> <units> # simulink.jpg, 41.99 Kb size = self.show.text().split(',')[1].strip() return({'name':self.name.text(), 'size':size})
class MembersDashboardMySessionsItem(ItemListItem): def __init__(self, owner, locatordict={},row_number=0): super(MembersDashboardMySessionsItem,self)\ .__init__(owner,locatordict,row_number) # load hub's classes MembersDashboardMySessionsItem_Locators = \ self.load_class('MembersDashboardMySessionsItem_Locators') # update this object's locator self.locators.update(MembersDashboardMySessionsItem_Locators.locators) # update the locators with those from the owner self.update_locators_from_owner() # setup page object's components self.quick_launch = Link(self,{'base':'quick_launch'}) self.title = Link(self,{'base':'title'}) self.snapshotlink = Link(self,{'base':'snapshotlink'}) self.access_time = TextReadOnly(self,{'base':'access_time'}) self.session_owner = Link(self,{'base':'session_owner'}) self.resume = Link(self,{'base':'resume'}) self.terminate = Link(self,{'base':'terminate'}) self.disconnect = Link(self,{'base':'disconnect'}) # update the component's locators with this objects overrides self._updateLocators() def value(self): """return a dictionary of properties for this session""" # open the slide down window if necessary was_open = True if not self.is_slide_open(): was_open = False self.toggle_slide() properties = { 'title' : self.title.text(), 'access_time' : self.get_last_accessed()[1], 'session_owner' : self.get_session_owner(), 'session_number' : self.get_session_number(), } if was_open is False: # close the slide down window # if it was originally closed self.toggle_slide() return properties def quick_launch_session(self): """use the quick_launch link to open the session""" self.quick_launch.click() return def get_title(self): """return the title of the session""" return self.title.text() def toggle_slide(self): """open or close the session item slide down""" check_invisible = self.resume.is_displayed() self.title.click() if check_invisible: message = 'while closing toggle, waiting for resume to disappear' self.resume.wait_until_invisible(message) else: message = 'while closing toggle, waiting for resume to appear' self.resume.wait_until_visible(message) return def is_slide_open(self): """check if the session item slide down is open""" return (self.title.is_displayed() and self.resume.is_displayed()) def get_last_accessed(self): """return the last accessed time stamp as a string and datetime object""" at_text = self.access_time.value dt_text = re.sub(r'Last Accessed:\s+','',at_text,flags=re.IGNORECASE) # dt_text should look something like this: # October 12, 2013 @ 12:44am dt = datetime.datetime.strptime(dt_text,'%B %d, %Y @ %I:%M%p') return (dt_text,dt) def get_session_owner(self): """return the session owner""" owner_text = None if self.session_owner.is_displayed(): owner_text = self.session_owner.text() return owner_text def get_session_number(self): """return the session number based on the url for the "open" link""" self.logger.debug('retrieving session number') snre = re.compile(r'=([0-9]+)') href = self.resume.get_attribute('href') self.logger.debug('href = %s' % (href)) match = snre.search(href) if match: session_number = int(match.group(1)) else: session_number = None self.logger.debug('session_number = %d' % (session_number)) return session_number def resume_session(self): """open this session""" return self.resume.click() def terminate_session(self,confirm=True): """terminate this session""" self.terminate.click() alert = self._browser.switch_to_alert() if confirm: self.logger.debug('accepting alert') alert.accept() else: self.logger.debug('dismissing alert') alert.dismiss() self._browser.switch_to_default_content() def disconnect_session(self,confirm=True): """disconnect from this shared session""" self.disconnect.click() alert = self._browser.switch_to_alert() if confirm: self.logger.debug('accepting alert') alert.accept() else: self.logger.debug('dismissing alert') alert.dismiss() self._browser.switch_to_default_content()