def assign_user_group_to_configuration(cls,group_name): # Page.delayed_click(cls.xpaths['user_groups'],0,2) cls.switch_to_tab("user_groups") Page.delayed_click(cls.xpaths['add_user_groups'], sleep_time=2) if Page.locate_element("//div[@id='config-user-groups']//label[text()='%s']/input/ancestor::tr[1]" % group_name).get_attribute('class') == '': user_group_checkbox = "//div[@id='config-user-groups']//label[text()='%s']/input" % group_name Page.delayed_click(user_group_checkbox, sleep_time=2)
def create_report(cls, type): if type in ('Billing Summary', 'Billing Detail', 'Machine WatchList', 'Machine Status', 'Machine Status', 'Resources Added', 'Machine Over Quota'): Page.delayed_click(cls.xpaths['reportBuilderLnk']) Page.delayed_click("//a[text()='%s']" % type) else: print "type should be one of 'Billing Summary', 'Billing Detail', 'Machine WatchList', 'Machine Status', 'Machine Status', 'Resources Added', 'Machine Over Quota' "
def start_use_mozy(cls): try: Page.delayed_click(cls.xpaths['start_using_mozy_btn'], sleep_time=2) return True except Exception: LogHelper.error("Click Start Using Mozy Button failed.") # Page.quit() return False
def click_client_configuration(cls): try: Page.delayed_click(cls.xpaths['client_configuration_link'], sleep_time=2) return True except Exception: LogHelper.error("Click Client Configration link failed.") # Page.quit() return False
def select_folder(self): try: Page.wait_for_element_list(self.xpaths['folderIcon']).click() return True except Exception: LogHelper.error("Select folder failed.") # Page.quit() return False
def act_as_partner(cls): try: Page.delayed_click(cls.xpaths['act_as_link'], sleep_time=2) cls.start_use_mozy() return True except Exception: LogHelper.error("Act as partner failed.") # Page.quit() return False
def step_impl(context): #Generate dir full path LogHelper.info('Generate directory full path') root = ConfigAdapter.get_testdata_path() for row in context.table: dir_name = row.get('entity') full_path = os.path.join(root, dir_name) #remve unwanted empty string drill_down_list = filter(lambda x: len(x) > 0, full_path.split(os.path.sep)) if RUNNER_CONFIG.get('PRODUCT').upper() in ('MAC', "LINUX", 'MAC_MACFRYR'): drill_down_list.insert(0, os.path.sep) # Drill down folders result = FreyjaPage.drill_down_folders(drill_down_list[0:-1]) try: (result).should.be(True) except AssertionError: LogHelper.error("Frejya fail to Expand folder.") FreyjaPage.quit() else: # Select folder checkbox result = FreyjaPage.check_entity(full_path) try: (result).should.be(True) except AssertionError: LogHelper.error("Frejya fail to check folder checkbox.") FreyjaPage.quit() else: context.kpi = KPI(testcase=context.tc.name, category="Web", start_time=strftime("%Y-%m-%dT%H:%M:%SZ", gmtime()), name="Frejya Create MZD", result="Fail", hostname=context.tc.machine_hostname, ip=context.tc.machine_ip, env=context.env) result = FreyjaPage.create_mzd() try: (result).should.be(True) except AssertionError: context.kpi.message = "Frejya fail to create MZD." FreyjaPage.quit() else: context.kpi.result = "SUCCESS" finally: context.kpi.end_time = strftime("%Y-%m-%dT%H:%M:%SZ", gmtime()) context.kpi.write_to_elasticsearch(context.senddb) context.kpi = None Page.quit()
def get_role_id(cls, name): Page.locate_element(cls.xpaths['listRoleLnk']).click() el = Page.locate_element( "//a[starts-with(@href,'/roles/show/') and text()='%s']" % name) role_link = el.get_attribute("href") print("role_link:%s" % role_link) last_index = role_link.rfind('/') root_role_id = ast.literal_eval(role_link[(last_index - len(role_link) + 1):]) print("root_role_id:%s" % root_role_id) return root_role_id
def drill_down_folders(folder_list): try: for folder_name in folder_list: target_folder = "//span[text()='" + folder_name + "']" LogHelper.info("Try to click '%s'" % target_folder) Page.delayed_click(target_folder) return True except Exception: LogHelper.error("Fail to drill down folder.") return False
def visit(self): self.dashboardpage_driver = Page.current_driver() env = RUNNER_CONFIG.get('ENVIRONMENT') or 'QA12' bushost = GLOBAL_CONFIG.get('QA_ENVIRONMENT').get(env).get('mozy.bushost') or 'www.mozypro.com' dashboardpage_url = "{bushost}/dashboard".format(bushost=bushost) if not bushost.startswith('https://'): dashboardpage_url = "https://{page}".format(page=dashboardpage_url) try: self.dashboardpage_driver.get(dashboardpage_url) except: self.dashboardpage_driver = Page.create_browser(force=True) self.dashboardpage_driver.get(dashboardpage_url)
def dig_to_folder(folders): time.sleep(3) folder_hierarchy = folders.split('/') try: for folder_name in folder_hierarchy: if folder_name == '': folder_name = '/' target_folder = "//span[text()='" + folder_name + "']" Page.delayed_click(target_folder) return True except Exception: LogHelper.error("Fail to dig folder.") return False
def visit(self, machineid): self.machinepage_driver = Page.current_driver() env = RUNNER_CONFIG.get('ENVIRONMENT') or 'QA12' bushost = GLOBAL_CONFIG.get('QA_ENVIRONMENT').get(env).get('mozy.bushost') or 'www.mozypro.com' if not bushost.startswith('https://'): machinepage_url = "https://{bushost}/admin/view_restores/{machineid}".format(bushost=bushost, machineid=machineid) else: machinepage_url = "{bushost}/admin/view_restores/{machineid}".format(bushost=bushost, machineid=machineid) # self.machinepage_driver = Page.create_browser() try: self.machinepage_driver.get(machinepage_url) except: self.machinepage_driver = Page.create_browser(force=True) self.machinepage_driver.get(machinepage_url)
def login(self, username=None, password=None): env = RUNNER_CONFIG.get('ENVIRONMENT') or 'QA12' username = username or GLOBAL_CONFIG.get('QA_ENVIRONMENT').get(env).get('bus_admin') password = password or GLOBAL_CONFIG.get('QA_ENVIRONMENT').get(env).get('bus_admin_password') try: Page.locate_element(self.xpaths['usernameTxtBox']).send_keys(username) Page.locate_element(self.xpaths['passwordTxtBox']).send_keys(password) el=Page.locate_element(self.xpaths['submitLogin']) el.click() return True except Exception: LogHelper.error("Can't login BUS.") # Page.quit() return False
def validate_machine_ecnryption(cls, encryptiontype="default"): if encryptiontype.upper() in ("PKEY", "CKEY", "RANDOM"): encryptiontype = "CUSTOM" encryption_web = Page.locate_element(cls.xpaths['encryptiontype']) return (encryption_web.text.upper() == encryptiontype.upper())
def visit(cls): # TODO: Remove hard when config ready # https://win-ko2af9k2doa.mtdev.mozypro.local/adfs/ls/?SAMLRequest=7b0HYBxJliUmL23Ke39K9UrX4HShCIBgEyTYkEAQ7MGIzeaS7B1pRyMpqyqBymVWZV1mFkDM7Z28995777333nvvvfe6O51OJ%2fff%2fz9cZmQBbPbOStrJniGAqsgfP358Hz8iHjfZolw9Ol638%2bWr%2fBet86ZNz55%2b9tHv%2f%2bk0m9w%2ff3iwfX%2fv%2fqfb%2b7uTe9sH%2bw92ts%2f3Pp083Ls%2fme4fHHyU%2fmReN0W1%2fOyjvfHOR%2blZ06zzs2XTZsuWPtrZfbC98%2bn27t6bnb1He7v0v%2fHDnf2f%2bih9Sr0Uy6zlN%2bdtu2oe3b17VSy331Z72fnDt3uzKhsv2ll%2bOV5UP7he1dW4rKZZeTebnTd3y%2bbuR%2blJtWxy9LKul4%2bqrCmaR8tskTeP2umj18dfPH9ECD2aSqNH62WzyqfFeZHPPkrfLcpl84iHvflt6ratplX50dFjHlgtr25%2bKWuavMbAPjrCwGhc3z17sf17fbl3%2fOzh77X39Mvj4XHRi5fFNG%2futvW6aR%2fflU6PHtNQZwVANu%2bJwOPj9azIl9P8FdG7Lqb41H14ZAif0dzvMULjabW4%2b4uy3b1ltazyxWpdlndBqMd37Uvu1wDoXYck%2fdHnqaP%2fBw%3d%3d&Signature=PE5xudj2pJEbvkfVY%2bBDCwOVIyLW0USobV%2bgONyZgAbTuJgrZ1ab62bFUksGexqIgP8SnecXjXcgSWCghDuXqdZxdxwmnW1TBnGwNPrEWuPvm0VTCYpsENUT3XxplC45Rrt8SGczowwKTBG1EFF8G9bdfd5cDF5ulNiJzxUDve58UBLzEOFo4NXsvChIcaWUgBZOhf07ietvEBagnZzPNOd2B0i8juxdF%2fXYqlrekIzED4tno0FvHUiMnhYMOsG4NH1K3dKhclordj4Bq787YQzrwZegf3WOllaq%2fPB6%2fapEoakI3b1mk54MMK2EWDrR1i0dJbiV%2bLl1YRX204T7Tg%3d%3d&SigAlg=http%3a%2f%2fwww.w3.org%2f2001%2f04%2fxmldsig-more%23rsa-sha256 #fedidpage_url = "https://win-ko2af9k2doa.mtdev.mozypro.local/adfs/ls/IdpInitiatedSignOn.aspx" fedidpage_url = "https://10.29.103.120/adfs/ls/IdpInitiatedSignOn.aspx" cls.driver = Page.create_browser() cls.driver.get(fedidpage_url)
def select_restore(self, table): self.driver = Page.current_driver() self.driver.switch_to.window(self.driver.window_handles[-1]) self.locate_element(self.xpaths['deviceTab']).click() machine_xpath = "//span[text()='" + table[0].get( 'restore_machine') + "']" self.wait_for_element_list(machine_xpath, 1).click() self.dig_to_folder(table[0].get('folder_hierarchy')) for row in table: xpath = "//tr[contains(@id, '" + row.get( 'restore_item' ) + "')]/td[@class='center col col-checkbox']//span" self.delayed_click(xpath) if platform.system() == "Windows": right_click_target = "//tr[contains(@id, '" + table[-1].get( 'restore_item' ) + "')]/td[@class='center col col-checkbox']//span" self.select_menu(right_click_target, 'Large Download Options...') else: try: self.locate_element( '//div[text()="Large Download Options..."]').click() except: self.locate_element( '//div[contains(@class, "panel-toggle") and @title="View Actions pane"]' ).click() self.locate_element( '//div[text()="Large Download Options..."]').click()
def select_folder(cls): try: el = Page.wait_for_element_list(cls.xpaths['folderIcon']) el.click() return True except Exception: LogHelper.error("BUS Select folder failed.") # Page.quit() return False
def search_user(self, username = None): result = False try: el = Page.locate_element(self.xpaths['searchTxtBox']) if el is None: LogHelper.error("Fail to locate search user text box.") else: el.send_keys(username) el = Page.locate_element(self.xpaths['submitSearch']) if el is None: LogHelper.error("Fail to locate search user button.") else: el.click() result = Page.delayed_click(self.xpaths['userLink'], 0, 10) except Exception: LogHelper.error("Search user failed.") finally: return result
def download_now(self): """ click download now button in Action Panel :return: """ try: download_now_btn_xpath = self.xpaths['downloadNowBtn'] if self.is_element_exist(download_now_btn_xpath, 1) is None: #Action Panel is not visible Page.delayed_click(self.xpaths['actionPanel']) self.delayed_click(download_now_btn_xpath) # cls.delayed_click(cls.xpaths['noticeDialog'], -1) result = self.wait_for_download_complete() return result except Exception: LogHelper.error("Fail to instant download.") return False
def create_role(cls, name="default", include_list=[], exclude_list=[], sub_role=True, include_all=False, exclude_all=True): el = Page.locate_element(cls.xpaths['addNewRoleLnk']) cls.driver.execute_script("arguments[0].scrollIntoView();", el) el.click() if sub_role: Page.select_dropbox(cls.xpaths['roleTypeDropBox'], "Partner admin") Page.locate_element(cls.xpaths['roleNameTxtBox']).send_keys(name) Page.locate_element(cls.xpaths['saveChangesBtn']).click() if include_all: els = Page.locate_elements(cls.xpaths['all_roleUncheckbox']) for el in els: cls.driver.execute_script("arguments[0].scrollIntoView();", el) el.click() Page.locate_element(cls.xpaths['saveChanges4SpecificRole']).click()
def step_impl(context): context.kpi = KPI(testcase=context.tc.name, category="Web", start_time=strftime("%Y-%m-%dT%H:%M:%SZ", gmtime()), name="BUS Login", result="Fail", hostname=context.tc.machine_hostname, ip=context.tc.machine_ip, env=context.env) result = BusPage.visit() try: (result).should_not.be(False) except AssertionError: context.kpi.end_time = strftime("%Y-%m-%dT%H:%M:%SZ", gmtime()) context.kpi.message = "Can't access BUS." context.kpi.write_to_elasticsearch(context.senddb) context.kpi = None Page.quit() else: env = RUNNER_CONFIG.get('ENVIRONMENT') or 'QA12' username = GLOBAL_CONFIG.get('QA_ENVIRONMENT').get(env).get( 'bus_admin') password = GLOBAL_CONFIG.get('QA_ENVIRONMENT').get(env).get( 'bus_admin_password') result = BusPage.login(username, password) try: (result).should.be(True) except AssertionError: context.kpi.message = "Fail to Login BUS." Page.quit() else: context.kpi.result = "SUCCESS" finally: context.kpi.end_time = strftime("%Y-%m-%dT%H:%M:%SZ", gmtime()) context.kpi.write_to_elasticsearch(context.senddb) context.kpi = None
def step_impl(context): context.kpi = KPI(testcase=context.tc.name, category="Web", start_time=strftime("%Y-%m-%dT%H:%M:%SZ", gmtime()), name="Frejya Response", result="Fail", hostname=context.tc.machine_hostname, ip=context.tc.machine_ip, env=context.env) result = BusPage.go_to_freya() try: (result).should.be(True) except AssertionError: context.kpi.message = "Fail to open Freyja." Page.quit() else: context.kpi.result = "SUCCESS" finally: context.kpi.end_time = strftime("%Y-%m-%dT%H:%M:%SZ", gmtime()) context.kpi.write_to_elasticsearch(context.senddb) context.kpi = None
def step_impl(context): username = context.user.username or "*****@*****.**" LogHelper.info('Search User %s' % username) # context.execute_steps(unicode('When I log web "BUS Search User" KPI start time')) context.kpi = KPI(testcase=context.tc.name, category="Web", start_time=strftime("%Y-%m-%dT%H:%M:%SZ", gmtime()), name="BUS Search User", result="Fail", hostname=context.tc.machine_hostname, ip=context.tc.machine_ip, env=context.env) result = BusPage.search_user(username) try: (result).should.be(True) except AssertionError: context.kpi.message = "Fail to search user." Page.quit() else: context.kpi.result = "SUCCESS" finally: context.kpi.end_time = strftime("%Y-%m-%dT%H:%M:%SZ", gmtime()) context.kpi.write_to_elasticsearch(context.senddb) context.kpi = None
def visit(self): env = RUNNER_CONFIG.get('ENVIRONMENT') or 'QA12' bushost = GLOBAL_CONFIG.get('QA_ENVIRONMENT').get(env).get('mozy.bushost') or 'www.mozypro.com' if not bushost.startswith('https://'): bus_url = "https://{bushost}/login/admin?old_school=1".format(bushost=bushost) else: bus_url = "{bushost}/login/admin?old_school=1".format(bushost=bushost) self.bus_driver = Page.create_browser() self.bus_driver.set_page_load_timeout(30) result = False try: self.bus_driver.get(bus_url) except Exception: LogHelper.error("Can't access BUS.") # Page.quit() return result else: # If page is opened successfully result = Page.is_element_exist(self.xpaths['loginfield'], wait_time=40) return result
def search_partner(cls, partnername = None,): try: Page.locate_element(cls.xpaths['partnerSearchTxtBox']).send_keys(partnername) Page.locate_element(cls.xpaths['partnerSubmitSearch']).click() Page.delayed_click(cls.xpaths['partnerLink'], sleep_time=5) return True except Exception: LogHelper.error("Search partner failed.") # Page.quit() return False
def uncheck_all_backup_sets(cls,backup_sets_type): if backup_sets_type in ("windows_backup_sets", "mac_backup_sets", "linux_backup_sets"): print backup_sets_type BusPage.switch_to_tab(backup_sets_type) # Page.delayed_click((cls.xpaths[backup_sets_type]), sleep_time=2) if backup_sets_type == "mac_backup_sets": checkbox_xpath = 'macset_active_checkbox' elif backup_sets_type == "windows_backup_sets": checkbox_xpath = 'set_active_checkbox' els = Page.locate_elements("//input[starts-with(@id,'%s')]" % checkbox_xpath) for el in els: cls.driver.execute_script("arguments[0].scrollIntoView();", el) if el.get_attribute("checked"): el.click() pass else: assert "backup sets is not included in windows_backup_sets,mac_backup_sets,linux_backup_sets"
def direct_download(self, table): try: self.driver = Page.create_browser() self.driver.switch_to.window(self.driver.window_handles[-1]) self.locate_element(self.xpaths['deviceTab']).click() machine_xpath = "//span[text()='" + table[0].get( 'restore_machine') + "']" self.wait_for_element_list(machine_xpath, 1).click() self.dig_to_folder(table[0].get('folder_hierarchy')) for row in table: xpath = "//tr[contains(@id, '" + row.get( 'restore_item' ) + "')]/td[@class='center col col-checkbox']//span" self.delayed_click(xpath) self.delayed_click(self.xpaths['downloadBtn']) self.delayed_click(self.xpaths['noticeDialog'], -1) result = self.wait_for_download_complete() return result except Exception: LogHelper.error("Fail to direct download.") return False
def step_impl(context): #Generate dir full path LogHelper.info('Generate directory full path') root = ConfigAdapter.get_testdata_path() for row in context.table: dir_name = row.get('entity') full_path = os.path.join(root, dir_name) #remve unwanted empty string drill_down_list = filter(lambda x: len(x) > 0, full_path.split(os.path.sep)) if RUNNER_CONFIG.get('PRODUCT').upper() in ('MAC', "LINUX", 'MAC_MACFRYR'): drill_down_list.insert(0, os.path.sep) try: starttime = datetime.datetime.now() result = FreyjaPage.drill_down_folders(drill_down_list[0:-1]) endtime = datetime.datetime.now() expand_folder_time = (endtime - starttime).seconds context.kpi = KPI(testcase=context.tc.name, category="Web", start_time=strftime("%Y-%m-%dT%H:%M:%SZ", gmtime()), name="Frejya Direct Download", result="Fail", message="Expand file: %s" % expand_folder_time, hostname=context.tc.machine_hostname, ip=context.tc.machine_ip, env=context.env) LogHelper.info("Expand file complete.") (result).should.be(True) except AssertionError: context.kpi.write_to_elasticsearch(context.senddb) FreyjaPage.quit() else: cb_target = '//tr[contains(@id, "{entity_name}")]//span[contains(@class, "check")]'.format( entity_name=drill_down_list[-1]) FreyjaPage.locate_element(cb_target, 30).click() #FreyjaPage.check_entity(drill_down_list[-1]) # context.execute_steps(unicode('When I log web "Frejya Direct Download" KPI start time')) context.kpi = KPI(testcase=context.tc.name, category="Web", start_time=strftime("%Y-%m-%dT%H:%M:%SZ", gmtime()), name="Frejya Direct Download", result="Fail", hostname=context.tc.machine_hostname, ip=context.tc.machine_ip, env=context.env) result = FreyjaPage.download_now() try: (result).should.be(True) except AssertionError: context.kpi.message = "Frejya fail to direct download." else: context.kpi.result = "SUCCESS" finally: context.kpi.end_time = strftime("%Y-%m-%dT%H:%M:%SZ", gmtime()) context.kpi.write_to_elasticsearch(context.senddb) context.kpi = None Page.quit()
def openbrowser(self): try: self.bus_driver = Page.create_browser() except Exception: LogHelper.error("Can't open browser.") return False
def visit_cas(self): env = RUNNER_CONFIG.get('ENVIRONMENT') or 'QA12' if "QA" in env: cas_host = GLOBAL_CONFIG.get('QA_ENVIRONMENT').get(env).get('mozy.cashost') self.bus_driver = Page.create_browser() self.bus_driver.get(cas_host)