class ResourcesToolScreenshotUploadRow(ItemListItem): def __init__(self, owner, locatordict={}, row_number=0): super(ResourcesToolScreenshotUploadRow,self).__init__(owner,locatordict,row_number) # load hub's classes ResourcesToolScreenshotUploadRow_Locators = self.load_class('ResourcesToolScreenshotUploadRow_Locators') # update this object's locator self.locators.update(ResourcesToolScreenshotUploadRow_Locators.locators) # update the locators with those from the owner self.update_locators_from_owner() # setup page object's components self.edit = Link(self,{'base':'edit'}) self.img_edit = Link(self,{'base':'img_edit'}) self.delete = Link(self,{'base':'delete'}) # update the component's locators with this objects overrides self._updateLocators() def value(self): """return the title""" return self.img_edit.get_attribute('title')
class Header3(Header): """ represents header on hubs where the username and my account links lead to the my account/dashboard page, and there is no profile link. generally found in older templates. here we use the username link to get the account number """ def __init__(self, owner, locatordict={}): super(Header3,self).__init__(owner,locatordict) # setup page object's additional components self.username = Link(self,{'base':'username'}) # update the component's locators with this objects overrides self._updateLocators() def _checkLocatorsLoggedIn(self): widgets = [self.logout,self.myaccount,self.username] self._checkLocators(widgets=widgets,cltype='LoggedIn') def goto_username(self): """click the username link to go to the member's account page""" return self.username.click() def get_account_number(self): """return the user's account number based on the "Username" link""" url = self.username.get_attribute('href') if not url: raise RuntimeError("link '%s' has no href" % (self.username.locator)) path = urlparse.urlsplit(url)[2] if not path: raise RuntimeError("url '%s' has no path" % (url)) matches = re.search("/members/(\d+)",path) if matches is None: raise RuntimeError("path '%s' does not contain an account number" % (path)) account_number = matches.group(1) return account_number
class Header(BasePageWidget): def __init__(self, owner, locatordict={}): super(Header,self).__init__(owner,locatordict) # load hub's classes Header_Locators = self.load_class('Header_Locators') # update this object's locator self.locators.update(Header_Locators.locators) # update the locators with those from the owner self.update_locators_from_owner() # setup page object's components self.login = Link(self,{'base':'login'}) self.register = Link(self,{'base':'register'}) self.logout = Link(self,{'base':'logout'}) self.myaccount = Link(self,{'base':'myaccount'}) # self.search = Search(self,{'base':'search'}) # update the component's locators with this objects overrides self._updateLocators() def _checkLocatorsLoggedOut(self): widgets = [self.login,self.register] self._checkLocators(widgets=widgets,cltype='LoggedOut') def _checkLocatorsLoggedIn(self): widgets = [self.logout,self.myaccount] self._checkLocators(widgets=widgets,cltype='LoggedIn') def goto_login(self): """click the login link""" return self.login.click() def goto_register(self): """click the register link""" return self.register.click() def goto_logout(self): """click the logout link""" self.logout.click() message = 'logout button visible while trying to logout' self.logout.wait_until_invisible(message) return def goto_myaccount(self): """click the link to go to the member's myaccount page""" return self.myaccount.click() def is_logged_in(self): """check if user is logged in, returns True or False""" return self.logout.is_displayed() def get_account_number(self): """return the user's account number based on the "My Account" url""" url = self.myaccount.get_attribute('href') if not url: raise RuntimeError("link '%s' has no href" % (self.myaccount.locator)) path = urlparse.urlsplit(url)[2] if not path: raise RuntimeError("url '%s' has no path" % (url)) matches = re.search("/members/(\d+)",path) if matches is None: raise RuntimeError("path '%s' does not contain an account number" % (path)) account_number = matches.group(1) return account_number
class Header2(BasePageWidget): """ represents header on hubs that use a javascripty dropdown menu to hold account links for dashboard, profile, messages and logout. """ def __init__(self, owner, locatordict={}): super(Header2,self).__init__(owner,locatordict) # load hub's classes Header_Locators = self.load_class('Header_Locators') # update this object's locator self.locators.update(Header_Locators.locators) # update the locators with those from the owner self.update_locators_from_owner() # setup page object's components self.login = Link(self,{'base':'login'}) self.register = Link(self,{'base':'register'}) self.logout = Link(self,{'base':'logout'}) self.details = Link(self,{'base':'details'}) self.dashboard = Link(self,{'base':'dashboard'}) self.messages = Link(self,{'base':'messages'}) self.profile = Link(self,{'base':'profile'}) # self.search = Search(self,'search') self._links = ['details','dashboard','messages','profile','logout'] # update the component's locators with this objects overrides self._updateLocators() def _checkLocatorsLoggedOut(self,widgets=None,cltype=""): widgets = [self.login] self._checkLocators(widgets=widgets,cltype='LoggedOut') def _checkLocatorsLoggedIn(self,widgets=None,cltype=""): widgets = [self.logout,self.dashboard, self.messages,self.profile] base = self.owner.find_element(self.locators['acctbase']) # hover mouse over the group manager toolbar to expand it actionProvider = ActionChains(self.owner._browser)\ .move_to_element(base) actionProvider.perform() # check for locators self._checkLocators(widgets=widgets,cltype='LoggedIn') def get_options_items(self): return self._links def goto_options_item(self,link): """this function does selenium specific stuff""" if not link in self._links: raise ValueError("invalid link name: '%s'",link) # hover mouse over the account toolbar to expand it # move the mouse to the correct link and click it menu = self.find_element(self.locators['acctbase']) loc = self.locators[link] menu_item = self.find_element(loc) self.logger.debug("moving mouse over account dropdown") self.logger.debug("clicking drowdown menu option '%s': %s" % (link,loc)) actionProvider = ActionChains(self.owner._browser)\ .move_to_element(menu)\ .move_to_element(menu_item)\ .click() actionProvider.perform() def goto_login(self): return self.login.click() def goto_register(self): return self.register.click() def goto_logout(self): lockey = 'logout' self.goto_options_item(lockey) # wait until the element is no longer visible (ie. the menu has closed) # before proceeding to the next task loc = self.locators[lockey] self.wait_until_not_present(locator=loc) def goto_myaccount(self): # deprecated function, use goto_dashboard() instead return self.goto_options_item('dashboard') def goto_dashboard(self): return self.goto_options_item('dashboard') def goto_messages(self): return self.goto_options_item('messages') def goto_profile(self): return self.goto_options_item('profile') def is_logged_in(self): """check if user is logged in, returns True or False""" # return not self.login.is_displayed() return self.logout.is_present() def get_account_number(self): """return the user's account number based on the "Username" url""" url = None # use dashboard instead of details because some hubs (like catalyzecare) # don't make details a link. url = self.dashboard.get_attribute('href') if url is None: raise RuntimeError("link '%s' has no href" \ % (self.details.locators['base'])) path = urlparse.urlsplit(url)[2] if not path: raise RuntimeError("url '%s' has no path" % (url)) # the url looks something like: # https://hubname.org/members/1234/dashboard matches = re.search("/members/(\d+)",path) if matches is None: raise RuntimeError("path '%s' does not contain an account number" \ % (path)) account_number = matches.group(1) return account_number
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()