class Backuprestore(object): def __init__(self, driver): self.driver = driver self.getElem = getElement(driver) self.selectElem = selectElement(driver) self.frameElem = frameElement(driver) self.cmf = commonFun(driver) self.cnEn = cnEncode() self.comsuit = CommonSuiteData(self.driver) self.command = CommandRule(self.driver) self.tableElem = tableElement(driver) self.log = log() self.userElem = UserPage(self.driver) u'''点击自动备份开关''' def auto_backup_switch(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_click_EC("id", "btn_qh") u'''勾选系统配置''' def check_sys_config(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") values = self.check_common() if values[0] == None: self.getElem.find_element_wait_and_click_EC("id", "configBackUp") if values[1] != None: self.getElem.find_element_wait_and_click_EC("id", "databaseBackUp") u'''勾选实体配置''' def check_entity_config(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") values = self.check_common() if values[0] != None: self.getElem.find_element_wait_and_click_EC("id", "configBackUp") if values[1] == None: self.getElem.find_element_wait_and_click_EC("id", "databaseBackUp") u'''勾选实体配置和系统配置''' def check_all_config(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") values = self.check_common() if values[0] == None: self.getElem.find_element_wait_and_click_EC("id", "configBackUp") if values[1] == None: self.getElem.find_element_wait_and_click_EC("id", "databaseBackUp") u'''勾选实体或者系统配置公共方法''' def check_common(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") selem = self.getElem.find_element_with_wait_EC("id", "configBackUp") value = selem.get_attribute('checked') selemdb = self.getElem.find_element_with_wait_EC("id", "databaseBackUp") valuedb = selemdb.get_attribute('checked') list = [value, valuedb] return list u'''勾选实体或者系统配置 parameter: - stauts:勾选配置信息1代表系统配置2代表实体配置,3代表系统配置和实体配置 ''' def check_config(self, stauts): staut = self.cnEn.is_float(stauts) if staut == '1': self.check_sys_config() elif staut == '2': self.check_entity_config() else: self.check_all_config() u'''选择备份方式 parameter: - stauts:value属性值,1代表一次性执行,2代表周期性执行 ''' def select_backup_mode(self, stauts): staut = self.cnEn.is_float(stauts) self.frameElem.from_frame_to_otherFrame("rigthFrame") selem = self.getElem.find_element_with_wait_EC("id", "backUpType") self.selectElem.select_element_by_value(selem, staut) u'''选择执行小时 parameter: - stauts:value属性值 ''' def select_hour(self, stauts): staut = self.cnEn.is_float(stauts) self.frameElem.from_frame_to_otherFrame("rigthFrame") selem = self.getElem.find_element_with_wait_EC("id", "startHour") self.selectElem.select_element_by_value(selem, staut) u'''填写分钟 parameter: - minute:分钟 ''' def set_minute(self, minute): minu = self.cnEn.is_float(minute) self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_clear_EC("id", "startMinute") self.getElem.find_element_wait_and_sendkeys("id", "startMinute", minu) u'''选择执行方式 parameter: - staut:0代表按天,1代表按周,2代表按月,3代表按年 ''' def select_execu_mode(self, staut): self.frameElem.from_frame_to_otherFrame("rigthFrame") if staut == 0: self.getElem.find_element_wait_and_click_EC("id", "dayradio") elif staut == 1: self.getElem.find_element_wait_and_click_EC("id", "weekradio") elif staut == 2: self.getElem.find_element_wait_and_click_EC("id", "monthRadio") else: self.getElem.find_element_wait_and_click_EC("id", "yearRadio") u'''选择存储位置 parameter: - stauts:value属性值1代表本地备份2代表ftp备份 ''' def select_storage_location(self, stauts): staut = self.cnEn.is_float(stauts) self.frameElem.from_frame_to_otherFrame("rigthFrame") selem = self.getElem.find_element_with_wait_EC("id", "backUpLocation") self.selectElem.select_element_by_value(selem, staut) u'''填写远程路径 parameter: - path:远程路径 ''' def set_remote_path(self, path): pat = self.cnEn.is_float(path) self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_clear_EC("id", "path") self.getElem.find_element_wait_and_sendkeys("id", "path", pat) u'''填写服务器IP parameter: - ip:服务器IP ''' def set_ftpip(self, ip): self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_clear_EC("id", "ip") self.getElem.find_element_wait_and_sendkeys("id", "ip", ip) u'''填写连接用户名 parameter: - minute:连接用户名 ''' def set_name(self, name): nam = self.cnEn.is_float(name) self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_clear_EC("id", "username") self.getElem.find_element_wait_and_sendkeys("id", "username", nam) u'''填写连接口令 parameter: - password:连接口令 ''' def set_password(self, password): pwd = self.cnEn.is_float(password) self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_clear_EC("id", "password") self.getElem.find_element_wait_and_sendkeys("id", "password", pwd) u'''填写确认口令 parameter: - minute:分钟 ''' def set_password_again(self, password): pwd = self.cnEn.is_float(password) self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_clear_EC("id", "passwordAgain") self.getElem.find_element_wait_and_sendkeys("id", "passwordAgain", pwd) u'''点击立刻备份''' def click_backup_immediately(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_click_EC("id", "back_up_now") u'''点击保存''' def click_save(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_click_EC("id", "back_up_save") u'''选择系统备份还原或者查看备份文件 parameter: - staut:0代表系统备份还原,1代表查看备份文件 ''' def select_backup_menu(self, staut): self.frameElem.from_frame_to_otherFrame("rigthFrame") if staut == 0: self.getElem.find_element_wait_and_click_EC("id", "tit1") elif staut == 1: self.getElem.find_element_wait_and_click_EC("id", "tit2") u'''点击操作列操作 Parameters: - filename:文件名称 - value:1代表下载,2代表删除,3代表还原 ''' def click_operat_file(self,filename, value): self.frameElem.from_frame_to_otherFrame("rigthFrame") row = 1 selems = self.driver.find_elements_by_name("file") for selem in selems: idvalue = selem.get_attribute('id') row = row +1 if idvalue == filename: xpath = ".//*[@id='content_rt02']/div/table/tbody/tr[" + str(row) + "]/td[7]/input[" + str(value) + "]" self.getElem.find_element_wait_and_click_EC("xpath", xpath) time.sleep(1) u'''下载上传完成后点击操作列操作 Parameters: - filename:文件名称 - value:1代表下载,2代表删除,3代表还原 ''' def upload_click_operat_file(self,filename, value): self.frameElem.from_frame_to_otherFrame("rigthFrame") row = 1 filenames = ""+filename[:-6] + ""+filename+"" selems = self.driver.find_elements_by_name("file") for selem in selems: idvalue = selem.get_attribute('id') row = row +1 if idvalue == filename or idvalue == filenames: xpath = ".//*[@id='content_rt02']/div/table/tbody/tr[" + str(row) + "]/td[7]/input[" + str(value) + "]" self.getElem.find_element_wait_and_click_EC("xpath", xpath) time.sleep(1) u'''点击还原系统配置''' def click_restore_sys_config(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_click_EC("id", "deleConfig1") u'''点击清空数据库''' def click_reset_database(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_click_EC("id", "resetDataBase1") u'''点击清空数据库''' def click_reset_audit(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_click_EC("id", "delAuditFile1") u'''填写syslogip parameter: - syslogip:syslogip ''' def set_syslogip(self, syslogip): ip = self.cnEn.is_float(syslogip) self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_clear_EC("id", "host") self.getElem.find_element_wait_and_sendkeys("id", "host", ip) u'''填写syslog端口 parameter: - port:syslog端口 ''' def set_port(self, port): sysport = self.cnEn.is_float(port) self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_clear_EC("id", "port") self.getElem.find_element_wait_and_sendkeys("id", "port", sysport) u'''点击syslog保存''' def click_syslog_save(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_click_EC("id", "save_syslog") u'''获取syslogip值''' def get_syslog_port(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") selem = self.getElem.find_element_with_wait_EC("id", "port") value = selem.get_attribute("value") return value u'''获取文件名称''' def get_file_name(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") selem = self.getElem.find_element_with_wait_EC("xpath", ".//*[@id='content_rt02']/div/table/tbody/tr[2]") value = selem.get_attribute('id') return value u'''编辑syslog parameter: - ip:syslogip - port:端口 ''' def set_syslog(self, port, ip='no'): time.sleep(3) self.comsuit.switch_to_moudle(u'系统配置', u'关联服务') self.command.click_left_rule(1) if ip != 'no': self.set_syslogip(ip) self.set_port(port) self.click_syslog_save() self.frameElem.switch_to_content() self.cmf.click_msg_button(1) u'''检验syslog端口是否为备份之前信息 parameter: - port:端口 - checklog:检验信息 ''' def check_syslog_content(self, port, checklog): self.comsuit.switch_to_moudle(u'系统配置', u'关联服务') self.command.click_left_rule(1) elemText = self.get_syslog_port() strdata3 = self.cnEn.is_float(port) if elemText == strdata3: self.log.log_detail(checklog, True) else: self.log.log_detail(checklog, False) u'''校验用户或者角色信息 Parameters: - namevalue:传入的要被查询名称 - name:表格列的name属性 - checklog:日志信息 return:定位该名称位于第几行 ''' def check_content(self,namevalue, name, checklog): row = self.cmf.find_row_by_name(namevalue, name) if row != 0: self.log.log_detail(checklog, True) else: self.log.log_detail(checklog, False) u'''填写用户信息 parameters: account : 用户账号 name : 用户名称 pwd : 用户密码 agpwd : 确认密码 ''' def set_user_info(self, account, name, pwd, agpwd): self.comsuit.switch_to_moudle(u"运维管理", u"用户") self.frameElem.from_frame_to_otherFrame("mainFrame") self.userElem.add_button() self.userElem.set_user_account(account) self.userElem.set_user_name(name) self.userElem.set_user_pwd(pwd) self.userElem.set_user_enquire_pwd(agpwd) self.userElem.save_button() self.frameElem.switch_to_content() self.cmf.click_login_msg_button() u'''点击用户操作列对应的删除按钮 parameters: - account : 用户账号 ''' def del_user_info(self, account): self.comsuit.switch_to_moudle(u"运维管理", u"用户") self.frameElem.from_frame_to_otherFrame("mainFrame") self.userElem.operate_delete(account) self.frameElem.switch_to_content() self.cmf.click_msg_button(1) self.frameElem.switch_to_content() self.cmf.click_msg_button(1) u'''点击备份还原配置文件的删除 parameters: - filename : 文件名称 - loginfo : 日志信息 ''' def del_backup_file(self, filename, loginfo): self.click_operat_file(filename, 2) self.frameElem.switch_to_content() self.cmf.click_msg_button(1) self.frameElem.switch_to_content() self.cmf.click_msg_button(1) time.sleep(1) self.log.log_detail(loginfo, True) u'''执行还原操作 parameters: - filename :执行还原的文件名称 - loginfo :日志信息 - stauts :状态1代表执行操作列按钮2代表进行上传后操作列按钮 ''' def execute_restore(self, filename, loginfo, stauts=1): self.comsuit.switch_to_moudle(u'系统配置', u'备份还原') self.command.click_left_rule(0) self.select_backup_menu(1) if stauts == 1: self.click_operat_file(filename, 3) elif stauts == 2: self.upload_click_operat_file(filename, 3) time.sleep(8) self.frameElem.switch_to_content() self.getElem.find_element_with_wait_EC("classname", "aui_state_highlight") time.sleep(5) self.cmf.click_msg_button(1) self.log.log_detail(loginfo, True) u'''配置备份信息 parameters: - data :数据文件集 - backMsg :保存成功的弹出框信息 - flag :无检查点的测试项标识,如果为True说明通过 ''' def config_backup(self, data, backMsg, flag): self.comsuit.switch_to_moudle(u'系统配置', u'备份还原') self.command.click_left_rule(0) self.check_config(data[12]) self.select_backup_mode(data[4]) self.backup_time(data[5], data[6]) self.select_storage_location(data[7]) self.click_save() time.sleep(3) self.frameElem.switch_to_content() self.cmf.test_win_check_point("xpath", backMsg, data, flag) self.click_backup_immediately() time.sleep(2) self.frameElem.switch_to_content() self.cmf.click_msg_button(1) self.log.log_detail(data[9], True) self.select_backup_menu(1) u'''执行日期 Parameters: - type :t代表今天,c代表clear,q代表确定,默认选择今天 - backuptime :执行日期设定的日期,格式为2016-9-7 11:42:42 ''' def backup_time(self, types, backuptime): self.frameElem.from_frame_to_otherFrame("rigthFrame") # 时间控件的fram的xpath fxpath = "//iframe[@hidefocus='true']" # 日期控件table的xpath路径 txpath = "/html/body/div/div[3]/table" status = self.cnEn.is_float('1') type = self.cnEn.is_float(types) # 转成datetime对象 date = datetime(*xldate_as_tuple(backuptime, 0)) end = date.strftime('%Y-%m-%d %H:%M:%S') self.option_time("backUpTime", fxpath, status, type, txpath, end) u'''操作时间控件 Parameters: - wdateId:日期控件input控件的ID值 - fxpath:日期控件frame的xpath路径 - status: 日期控件是否有时分秒 - txpath:日期控件table的xpath路径 - time:设定的日期,格式为2016-9-7 11:42:42 - type:t代表今天,c代表clear,q代表确定,默认选择今天 ''' def option_time(self,wdateId,fxpath,status='0',type='t',txpath = None,dtime = None): self.getElem.find_element_wait_and_click("id",wdateId) frame = self.driver.find_element_by_xpath(fxpath) self.driver.switch_to_frame(frame) if type == 't': self.getElem.find_element_wait_and_click("id","dpTodayInput") elif type == 'c': self.getElem.find_element_wait_and_click("id","dpClearInput") elif type == 'q': if dtime is not None: list = dtime.split() ymdList = list[0].split("-") hmsList = list[1].split(":") #年 tYear = ymdList[0] #月 tMon = ymdList[1] #日 tDay = ymdList[2] #时 tHour = hmsList[0] #分 tMin = hmsList[1] #秒 tSen = hmsList[2] dTitle = self.getElem.find_element_with_wait("id","dpTitle").find_elements_by_tag_name("input") #设定月 dTitle[0].clear() dTitle[0].send_keys(tMon) #设定年 dTitle[1].clear() dTitle[1].send_keys(tYear) self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_click_EC("id", "backUpTime") self.driver.switch_to_frame(frame) if txpath is not None: iStatus = False for itr in range(7): if itr != 0: for itd in range(7): ct = self.tableElem.get_table_cell_text(txpath,itr,itd)[0] #排除第一行大于7的 if itr == 1 and int(ct) > 7: continue #排除倒数第二行小于15的 if itr == 5 and int(ct) < 15: continue #排除最后一行小于15的 if itr == 6 and int(ct) < 15: continue #如果跟给定的日期一致,点击日期 if int(ct) == int(tDay): self.tableElem.get_table_cell_text(txpath,itr,itd)[1].click() iStatus = True break #找到日期后跳出循环 if iStatus: break #日期控件是否有时分秒 if status == '1': dTime = self.getElem.find_element_with_wait("id","dpTime").find_elements_by_tag_name("input") #设定小时 dTime[0].clear() dTime[0].send_keys(tHour) #设定分钟 dTime[2].clear() dTime[2].send_keys(tMin) #设定秒 dTime[4].clear() dTime[4].send_keys(tSen) self.getElem.find_element_wait_and_click("id","dpOkInput") u'''上传操作 parameters: - filename :执行还原的文件名称 - loginfo :日志信息 ''' def backup_file_upload(self, filename, loginfo): self.frameElem.from_frame_to_otherFrame("rigthFrame") value = "C:\Users\Administrator\Downloads\\" + filename+"" self.getElem.find_element_wait_and_sendkeys("id", "backUpFile", value) time.sleep(2) self.getElem.find_element_wait_and_click_EC("id", "up_file") self.frameElem.switch_to_content() self.cmf.click_msg_button(1) time.sleep(1) self.log.log_detail(loginfo, True)
class AddressRule(object): def __init__(self, driver): self.driver = driver self.getElem = getElement(driver) self.selectElem = selectElement(driver) self.frameElem = frameElement(driver) self.cmf = commonFun(driver) self.cnEn = cnEncode() self.acproval = Accapproval(driver) self.user = UserPage(driver) u'''点击批量删除''' def click_bulkdel_address(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_click_EC("id", "delete_rule_address") u'''点击编辑按钮 Parameters: - addressname:地址规则名称 ''' def click_edit_address(self, addressname): try: self.frameElem.from_frame_to_otherFrame("rigthFrame") row = self.acproval.find_name_by_row(addressname, "fortRuleAddressName") update_xpath = ".//*[@id='content_table']/tbody/tr[" + str(row) + "]/td[5]/input[1]" time.sleep(3) self.getElem.find_element_wait_and_click("xpath", update_xpath) except Exception: print("Click the Edit button to fail") u'''点击删除按钮 Parameters: - addressname:时间规则名称 ''' def click_del_address(self, addressname): try: self.frameElem.from_frame_to_otherFrame("rigthFrame") row = self.acproval.find_name_by_row(addressname, "fortRuleAddressName") del_xpath = ".//*[@id='content_table']/tbody/tr[" + str(row) + "]/td[5]/input[2]" self.getElem.find_element_wait_and_click("xpath", del_xpath) except Exception: print("Click the Del button to fail") u'''填写检索名称 Parameters: - addressname:名称 ''' def set_search_addressname(self, addressname): self.frameElem.from_frame_to_otherFrame("rigthFrame") name = self.cnEn.is_float(addressname) self.getElem.find_element_wait_and_clear("id", "rule_address_id") self.getElem.find_element_wait_and_sendkeys("id", "rule_address_id", name) u'''点击检索按钮''' def click_search_address(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_click_EC("id", "rule_address") u'''填写地址规则名称 Parameters: - rulename:规则名称 ''' def set_rulename(self, rulename): name = self.cnEn.is_float(rulename) self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_clear("id", "fortRuleAddressName") self.getElem.find_element_wait_and_sendkeys("id", "fortRuleAddressName", name) u'''选择IP规则 Parameters: - stauts:1代表勾选IP掩码,2代表勾选IP区间,3代表IP掩码和IP区间 ''' def checkbox_ip_rule(self, stauts): staut = self.cnEn.is_float(stauts) self.frameElem.from_frame_to_otherFrame("rigthFrame") if staut == '1': self.getElem.find_element_wait_and_click_EC("id", "one_ip") elif staut == '2': self.getElem.find_element_wait_and_click_EC("id", "duo_ip") else: self.getElem.find_element_wait_and_click_EC("id", "one_ip") self.getElem.find_element_wait_and_click_EC("id", "duo_ip") u'''点击增加多个IP''' def click_add_more_ip(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_click_EC("id", "add_ip_mask") u'''填写ip地址 Parameters: - iplist:所填写的IP列表集合 ''' def set_ip(self, iplist): self.frameElem.from_frame_to_otherFrame("rigthFrame") #获取所有页面IP地址集合 fortips = self.driver.find_elements_by_name("fortIp") ipaddress = iplist.split() self.ip_mask_common(fortips, ipaddress) u'''填写ip地址掩码 Parameters: - masklist:所填写的IP掩码value值列表集合 ''' def set_ip_mask(self, masklist): self.frameElem.from_frame_to_otherFrame("rigthFrame") #获取所有页面IP掩码集合 fortMasks = self.driver.find_elements_by_name("fortMask") masklists = masklist.split() self.ip_mask_common(fortMasks, masklists) u'''填写IP地址和掩码公共方法 Parameters: - ipsets:页面IP段集合 - dataipsets:列表数据集合 ''' def ip_mask_common(self, ipsets, dataipsets): #获取页面集合长度 ipsetth = len(ipsets) fortth = 0 #循环ip掩码进行填写操作 for ipset in ipsets: if fortth < ipsetth and dataipsets[fortth] != 'no': fortips = self.driver.find_elements_by_name("fortIp") if ipsets == fortips: ipset.clear() ipset.send_keys(dataipsets[fortth]) fortth = fortth + 1 u'''点击增加多个IP段''' def click_add_ip_segment(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_click_EC("id", "add_ip_range") u'''填写起始段IP Parameters: - ipstartlist:所填写的起始段IP列表集合 ''' def set_ip_start(self, ipstartlist): self.frameElem.from_frame_to_otherFrame("rigthFrame") ipstarts = ipstartlist.split() self.ip_segment_common("fortIpStart", ipstarts) u'''填写结束段IP Parameters: - ipendlist:所填写的结束段IP列表集合 ''' def set_ip_end(self, ipendlist): self.frameElem.from_frame_to_otherFrame("rigthFrame") ipends = ipendlist.split() self.ip_segment_common("fortIpEnd", ipends) u'''填写区间段IP公共方法 Parameters: - ipsetname:页面IP段name属性 - dataipsets:列表数据集合 ''' def ip_segment_common(self, ipsetname, dataipsets): #获取所有页面IP段集合 ipsets = self.driver.find_elements_by_name(ipsetname) #获取IP段集合长度 ipsetsth = len(ipsets) fortth = 0 #循环进行段ip填写操作 for ipset in ipsets: if fortth < ipsetsth: ipset.clear() ipset.send_keys(dataipsets[fortth]) fortth = fortth + 1 u'''点击测试''' def click_test(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_click_EC("id", "test_ip") u'''填写测试ip地址 Parameters: - testip:ip地址 ''' def set_ip_test(self, testip): ip = self.cnEn.is_float(testip) self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_clear("id", "testIp") self.getElem.find_element_wait_and_sendkeys("id", "testIp", ip) u'''填写描述信息 Parameters: - description:描述信息 ''' def set_description(self, description): descript = self.cnEn.is_float(description) self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_clear("id", "fortDescription") self.getElem.find_element_wait_and_sendkeys("id", "fortDescription", descript) u'''点击保存''' def click_save(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_click_EC("id", "save_rule_address") u'''点击返回''' def click_back(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_click_EC("id", "history_skip") u'''给用户添加地址规则 Parameters: - username:要编辑的用户名称 - adrerule:地址规则名称 ''' def edit_user_address_rule(self, username, adrerule): self.frameElem.from_frame_to_otherFrame("mainFrame") name = self.cnEn.is_float(username) self.user.operate_edit(name) self.user.click_advanced_option() self.select_adress_rule(adrerule) self.user.save_button() self.cmf.click_login_msg_button() self.user.click_back_button() u'''选择地址规则 Parameters: - adrerule:地址规则名称 ''' def select_adress_rule(self, adrerule): self.frameElem.from_frame_to_otherFrame("mainFrame") addressrule = self.cnEn.is_float(adrerule) select_elem = self.getElem.find_element_with_wait_EC('id',"fortRuleAddressId") self.selectElem.select_element_by_visible_text(select_elem, addressrule)
class AddressRule(object): def __init__(self, driver): self.driver = driver self.getElem = getElement(driver) self.selectElem = selectElement(driver) self.frameElem = frameElement(driver) self.cmf = commonFun(driver) self.cnEn = cnEncode() self.acproval = Accapproval(driver) self.user = UserPage(driver) u'''点击批量删除''' def click_bulkdel_address(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_click_EC("id", "delete_rule_address") u'''点击编辑按钮 Parameters: - addressname:地址规则名称 ''' def click_edit_address(self, addressname): try: self.frameElem.from_frame_to_otherFrame("rigthFrame") row = self.acproval.find_name_by_row(addressname, "fortRuleAddressName") update_xpath = ".//*[@id='content_table']/tbody/tr[" + str(row) + "]/td[5]/input[1]" time.sleep(3) self.getElem.find_element_wait_and_click("xpath", update_xpath) except Exception: print("Click the Edit button to fail") u'''点击删除按钮 Parameters: - addressname:时间规则名称 ''' def click_del_address(self, addressname): try: self.frameElem.from_frame_to_otherFrame("rigthFrame") row = self.acproval.find_name_by_row(addressname, "fortRuleAddressName") del_xpath = ".//*[@id='content_table']/tbody/tr[" + str(row) + "]/td[5]/input[2]" self.getElem.find_element_wait_and_click("xpath", del_xpath) except Exception: print("Click the Del button to fail") u'''填写检索名称 Parameters: - addressname:名称 ''' def set_search_addressname(self, addressname): self.frameElem.from_frame_to_otherFrame("rigthFrame") name = self.cnEn.is_float(addressname) self.getElem.find_element_wait_and_clear("id", "rule_address_id") self.getElem.find_element_wait_and_sendkeys("id", "rule_address_id", name) u'''点击检索按钮''' def click_search_address(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_click_EC("id", "rule_address") u'''填写地址规则名称 Parameters: - rulename:规则名称 ''' def set_rulename(self, rulename): name = self.cnEn.is_float(rulename) self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_clear("id", "fortRuleAddressName") self.getElem.find_element_wait_and_sendkeys("id", "fortRuleAddressName", name) u'''选择IP规则 Parameters: - stauts:1代表勾选IP掩码,2代表勾选IP区间,3代表IP掩码和IP区间 ''' def checkbox_ip_rule(self, stauts): staut = self.cnEn.is_float(stauts) self.frameElem.from_frame_to_otherFrame("rigthFrame") if staut == '1': self.getElem.find_element_wait_and_click_EC("id", "one_ip") elif staut == '2': self.getElem.find_element_wait_and_click_EC("id", "duo_ip") else: self.getElem.find_element_wait_and_click_EC("id", "one_ip") self.getElem.find_element_wait_and_click_EC("id", "duo_ip") u'''点击增加多个IP''' def click_add_more_ip(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_click_EC("id", "add_ip_mask") u'''填写ip地址 Parameters: - iplist:所填写的IP列表集合 ''' def set_ip(self, iplist): self.frameElem.from_frame_to_otherFrame("rigthFrame") #获取所有页面IP地址集合 fortips = self.driver.find_elements_by_name("fortIp") ipaddress = iplist.split() self.ip_mask_common(fortips, ipaddress) u'''填写ip地址掩码 Parameters: - masklist:所填写的IP掩码value值列表集合 ''' def set_ip_mask(self, masklist): self.frameElem.from_frame_to_otherFrame("rigthFrame") #获取所有页面IP掩码集合 fortMasks = self.driver.find_elements_by_name("fortMask") masklists = masklist.split() self.ip_mask_common(fortMasks, masklists) u'''填写IP地址和掩码公共方法 Parameters: - ipsets:页面IP段集合 - dataipsets:列表数据集合 ''' def ip_mask_common(self, ipsets, dataipsets): #获取页面集合长度 ipsetth = len(ipsets) fortth = 0 #循环ip掩码进行填写操作 for ipset in ipsets: if fortth < ipsetth and dataipsets[fortth] != 'no': fortips = self.driver.find_elements_by_name("fortIp") if ipsets == fortips: ipset.clear() ipset.send_keys(dataipsets[fortth]) fortth = fortth + 1 u'''点击增加多个IP段''' def click_add_ip_segment(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_click_EC("id", "add_ip_range") u'''填写起始段IP Parameters: - ipstartlist:所填写的起始段IP列表集合 ''' def set_ip_start(self, ipstartlist): self.frameElem.from_frame_to_otherFrame("rigthFrame") ipstarts = ipstartlist.split() self.ip_segment_common("fortIpStart", ipstarts) u'''填写结束段IP Parameters: - ipendlist:所填写的结束段IP列表集合 ''' def set_ip_end(self, ipendlist): self.frameElem.from_frame_to_otherFrame("rigthFrame") ipends = ipendlist.split() self.ip_segment_common("fortIpEnd", ipends) u'''填写区间段IP公共方法 Parameters: - ipsetname:页面IP段name属性 - dataipsets:列表数据集合 ''' def ip_segment_common(self, ipsetname, dataipsets): #获取所有页面IP段集合 ipsets = self.driver.find_elements_by_name(ipsetname) #获取IP段集合长度 ipsetsth = len(ipsets) fortth = 0 #循环进行段ip填写操作 for ipset in ipsets: if fortth < ipsetsth: ipset.clear() ipset.send_keys(dataipsets[fortth]) fortth = fortth + 1 u'''点击测试''' def click_test(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_click_EC("id", "test_ip") u'''填写测试ip地址 Parameters: - testip:ip地址 ''' def set_ip_test(self, testip): ip = self.cnEn.is_float(testip) self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_clear("id", "testIp") self.getElem.find_element_wait_and_sendkeys("id", "testIp", ip) u'''填写描述信息 Parameters: - description:描述信息 ''' def set_description(self, description): descript = self.cnEn.is_float(description) self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_clear("id", "fortDescription") self.getElem.find_element_wait_and_sendkeys("id", "fortDescription", descript) u'''点击保存''' def click_save(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_click_EC("id", "save_rule_address") u'''点击返回''' def click_back(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_click_EC("id", "history_skip") u'''给用户添加地址规则 Parameters: - username:要编辑的用户名称 - adrerule:地址规则名称 ''' def edit_user_address_rule(self, username, adrerule): self.frameElem.from_frame_to_otherFrame("mainFrame") name = self.cnEn.is_float(username) self.user.operate_edit(name) self.user.click_advanced_option() self.select_adress_rule(adrerule) self.user.save_button() self.cmf.click_login_msg_button() self.user.click_back_button() u'''选择地址规则 Parameters: - adrerule:地址规则名称 ''' def select_adress_rule(self, adrerule): self.frameElem.from_frame_to_otherFrame("mainFrame") addressrule = self.cnEn.is_float(adrerule) select_elem = self.getElem.find_element_with_wait_EC('id',"fortRuleAddressId") self.selectElem.select_element_by_visible_text(select_elem, addressrule)
class TimeRule(object): def __init__(self, driver): self.driver = driver self.getElem = getElement(driver) self.selectElem = selectElement(driver) self.frameElem = frameElement(driver) self.tableElem = tableElement(driver) self.cmf = commonFun(driver) self.cnEn = cnEncode() self.acproval = Accapproval(driver) self.user = UserPage(driver) u'''点击批量删除''' def click_bulkdel_time(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_click_EC("id", "delete_rule_time") u'''填写时间规则名称 Parameters: - rulename:时间规则名称 ''' def set_rulename(self, rulename): name = self.cnEn.is_float(rulename) self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_clear("id", "fortRuleTimeName") self.getElem.find_element_wait_and_sendkeys("id", "fortRuleTimeName", name) u'''选择部门 Parameters: - deptname:部门名称 ''' def select_depart(self, deptname): name = self.cnEn.is_float(deptname) self.select_depart_right_common("department_name", "tree_1_switch", name) time.sleep(2) u'''启动日期 Parameters: - type:t代表今天,c代表clear,q代表确定,默认选择今天 - starttime:启动日期 ''' def start_date(self, types, starttime=None): self.frameElem.from_frame_to_otherFrame("rigthFrame") # 时间控件的fram的xpath # fxpath = "//iframe[@hidefocus='true']" fxpath = "/html/body/div/iframe" # 日期控件table的xpath路径 txpath = "/html/body/div/div[3]/table" status = self.cnEn.is_float('0') type = self.cnEn.is_float(types) if starttime != None: # 转成datetime对象 date = datetime(*xldate_as_tuple(starttime, 0)) start = date.strftime('%Y-%m-%d %H:%M:%S') self.option_time_rule("fortStartTime", fxpath, status, type, txpath, start) else: self.option_time_rule("fortStartTime", fxpath, status, type, txpath) u'''结束日期 Parameters: - type:t代表今天,c代表clear,q代表确定,默认选择今天 - endtime:结束日期设定的日期,格式为2016-9-7 11:42:42 ''' def date_of_termination(self, types, endtime): self.frameElem.from_frame_to_otherFrame("rigthFrame") # 时间控件的fram的xpath fxpath = "//iframe[@hidefocus='true']" # 日期控件table的xpath路径 txpath = "/html/body/div/div[3]/table" status = self.cnEn.is_float('0') type = self.cnEn.is_float(types) # 转成datetime对象 date = datetime(*xldate_as_tuple(endtime, 0)) end = date.strftime('%Y-%m-%d %H:%M:%S') self.option_time_rule("fortEndTime", fxpath, status, type, txpath, end) u'''设置状态类型 Parameters: - status: 状态类型0代表禁止使用,1代表允许使用 ''' def set_status_type(self, status): self.frameElem.from_frame_to_otherFrame("rigthFrame") statu = self.cnEn.is_float(status) selem = self.getElem.find_element_with_wait_EC("id", "fortAccessType") self.selectElem.select_element_by_value(selem, statu) u'''设置时间 Parameters: - method: 设置方式 option的value值 - weeks: 星期(可多选)option的value值 - hours: 小时(可多选) ''' def set_time(self, methods, weeks, hours='no'): self.frameElem.from_frame_to_otherFrame("rigthFrame") #设置时间方式 method = self.cnEn.is_float(methods) selem = self.getElem.find_element_with_wait_EC("id", "method") self.selectElem.select_element_by_value(selem, method) #设置日期 week = weeks.split() if methods == "weeks": for data in week: welem = self.getElem.find_element_with_wait_EC("id", "fortWeeks") self.selectElem.select_element_by_value(welem, data) elif methods == "days": for data in week: welem = self.getElem.find_element_with_wait_EC("id", "fortDays") self.selectElem.select_element_by_value(welem, data) if hours != 'no': #设置小时 hour = hours.split() for hr in hour: helem = self.getElem.find_element_with_wait_EC("id", "fortHours") self.selectElem.select_element_by_value(helem, hr) u'''取消时间 Parameters: - method: 设置方式 option的value值 - weeks: 星期(可多选)option的value值 - hours: 小时(可多选) ''' def deselect_time(self, methods, weeks, hours='no'): self.frameElem.from_frame_to_otherFrame("rigthFrame") #设置日期 week = weeks.split() if methods == "weeks": for data in week: welem = self.getElem.find_element_with_wait_EC("id", "fortWeeks") self.selectElem.deselect_element_by_value(welem, data) elif methods == "days": for data in week: welem = self.getElem.find_element_with_wait_EC("id", "fortDays") self.selectElem.deselect_element_by_value(welem, data) if hours != 'no': #设置小时 hour = hours.split() for hr in hour: helem = self.getElem.find_element_with_wait_EC("id", "fortHours") self.selectElem.deselect_element_by_value(helem, hr) u'''填写描述信息 Parameters: - descrip:描述信息 ''' def set_descrip(self, descrip): self.frameElem.from_frame_to_otherFrame("rigthFrame") description = self.cnEn.is_float(descrip) self.getElem.find_element_wait_and_clear("id", "fortDescription") self.getElem.find_element_wait_and_sendkeys("id", "fortDescription", description) u'''点击保存按钮''' def click_save_time(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_click_EC("id", "save_rule_time") u'''填写检索名称 Parameters: - timename:名称 ''' def set_search_timename(self, timename): self.frameElem.from_frame_to_otherFrame("rigthFrame") name = self.cnEn.is_float(timename) self.getElem.find_element_wait_and_clear("id", "fortRuleTimeName") self.getElem.find_element_wait_and_sendkeys("id", "fortRuleTimeName", name) u'''点击检索按钮''' def click_search_time(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_click_EC("id", "retFortRuleTimeName") u'''点击重置''' def click_reset_time(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_click_EC("id", "resetting") u'''点击编辑按钮 Parameters: - timename:时间规则名称 ''' def click_edit_time(self, timename): try: self.frameElem.from_frame_to_otherFrame("rigthFrame") row = self.acproval.find_name_by_row(timename, "fortRuleTimeName") update_xpath = "/html/body/div/div[6]/div[2]/div/table/tbody/tr[" + str(row) + "]/td[6]/input[1]" self.getElem.find_element_wait_and_click("xpath", update_xpath) except Exception: print("Click the Edit button to fail") u'''点击删除按钮 Parameters: - timename:时间规则名称 ''' def click_del_time(self, timename): try: self.frameElem.from_frame_to_otherFrame("rigthFrame") row = self.acproval.find_name_by_row(timename, "fortRuleTimeName") del_xpath = "/html/body/div/div[6]/div[2]/div/table/tbody/tr[" + str(row) + "]/td[6]/input[2]" self.getElem.find_element_wait_and_click("xpath", del_xpath) except Exception: print("Click the Del button to fail") u'''选择部门公共方法 parameter: - idname:填写框id - swithid:部门展开按钮id - deptname:部门名称 ''' def select_depart_right_common(self, idname, swithid, deptname): try: self.frameElem.from_frame_to_otherFrame("rigthFrame") self.driver.implicitly_wait(10) self.getElem.find_element_wait_and_click_EC('id', idname) self.driver.implicitly_wait(10) self.getElem.find_element_wait_and_click_EC('id', swithid) self.driver.implicitly_wait(10) #获取所有a标签的对象 elems = self.driver.find_elements_by_tag_name("a") for elem in elems: elemtext = elem.get_attribute("title") elemid = elem.get_attribute("id") if deptname == elemtext: self.getElem.find_element_wait_and_click("id", elemid) break except Exception as e: print "Department select error:" + str(e) u'''操作时间控件 Parameters: - wdateId:日期控件input控件的ID值 - fxpath:日期控件frame的xpath路径 - status: 日期控件是否有时分秒 - txpath:日期控件table的xpath路径 - time:设定的日期,格式为2016-9-7 11:42:42 - type:t代表今天,c代表clear,q代表确定,默认选择今天 ''' def option_time_rule(self,wdateId,fxpath,status='0',type='t',txpath = None,dtime = None): self.getElem.find_element_wait_and_click("id",wdateId) frame = self.driver.find_element_by_xpath(fxpath) self.driver.switch_to_frame(frame) if type == 't': self.getElem.find_element_wait_and_click("id","dpTodayInput") elif type == 'c': self.getElem.find_element_wait_and_click("id","dpClearInput") elif type == 'q': if dtime is not None: list = dtime.split() ymdList = list[0].split("-") hmsList = list[1].split(":") #年 tYear = ymdList[0] #月 tMon = ymdList[1] #日 tDay = ymdList[2] #时 tHour = hmsList[0] #分 tMin = hmsList[1] #秒 tSen = hmsList[2] dTitle = self.getElem.find_element_with_wait("id","dpTitle").find_elements_by_tag_name("input") #设定月 dTitle[0].clear() dTitle[0].send_keys(tMon) #设定年 dTitle[1].clear() dTitle[1].send_keys(tYear) self.frameElem.from_frame_to_otherFrame("rigthFrame") if wdateId == "fortStartTime": self.getElem.find_element_wait_and_click_EC("id", "fortStartTime") elif wdateId == "fortEndTime": self.getElem.find_element_wait_and_click_EC("id", "fortEndTime") self.driver.switch_to_frame(frame) if txpath is not None: iStatus = False for itr in range(7): if itr != 0: for itd in range(7): ct = self.tableElem.get_table_cell_text(txpath,itr,itd)[0] #排除第一行大于7的 if itr == 1 and int(ct) > 7: continue #排除倒数第二行小于15的 if itr == 5 and int(ct) < 15: continue #排除最后一行小于15的 if itr == 6 and int(ct) < 15: continue #如果跟给定的日期一致,点击日期 if int(ct) == int(tDay): self.tableElem.get_table_cell_text(txpath,itr,itd)[1].click() iStatus = True break #找到日期后跳出循环 if iStatus: break #日期控件是否有时分秒 if status == '1': dTime = self.getElem.find_element_with_wait("id","dpTime").find_elements_by_tag_name("input") #设定小时 dTime[0].clear() dTime[0].send_keys(tHour) #设定分钟 dTime[2].clear() dTime[2].send_keys(tMin) #设定秒 dTime[4].clear() dTime[4].send_keys(tSen) self.getElem.find_element_wait_and_click("id","dpOkInput") u'''给用户添加时间规则 Parameters: - username:要编辑的用户名称 - timerule:时间规则test值 ''' def edit_user_time_rule(self, username, timerule): self.frameElem.from_frame_to_otherFrame("mainFrame") name = self.cnEn.is_float(username) self.user.operate_edit(name) self.user.click_advanced_option() self.select_time_rule(timerule) self.user.save_button() self.cmf.click_login_msg_button() self.user.click_back_button() u'''选择时间规则 Parameters: - timerule:时间规则test值 ''' def select_time_rule(self, timerule): self.frameElem.from_frame_to_otherFrame("mainFrame") timer = self.cnEn.is_float(timerule) select_elem = self.getElem.find_element_with_wait_EC('id',"fortRuleTimeId") self.selectElem.select_element_by_visible_text(select_elem, timer)
class CommonSuiteData(): def __init__(self, driver): self.driver = driver self.dataFile = dataFileName() self.cmf = commonFun(self.driver) self.initDriver = initDriver() self.loginElem = loginPage(self.driver) self.roleElem = Role(self.driver) self.userElem = UserPage(self.driver) self.frameElem = frameElement(self.driver) self.authElem = AuthMethodPage(self.driver) self.dptment = Department(self.driver) self.resource = Resource(self.driver) self.account = Accountmgr(self.driver) self.windowsElem = WindowsResource(self.driver) self.databaseElem = DatabaseResource(self.driver) self.usergroup = Usergroup(self.driver) self.regroup = Regroup(self.driver) self.appElem = AppPage(self.driver) self.authorizationElem = AuthorizationPage(self.driver) self.testAutho = testAuthorization(self.driver) self.clientElem = ClientPage(self.driver) self.command = CommandRule(self.driver) self.ntp = NtpService(self.driver) self.mail = MailPage(self.driver) self.syslog = Syslog(driver) self.ssoElem = SsoPage(self.driver) self.alarm = AlarmPage(self.driver) self.PwdStr = PwdStrategy(self.driver) self.passwdenvelope = EnvelopePage(self.driver) u'''切换模块 parameter: levelText1 : 一级模块名称 levelText2 : 二级模块名称 ''' def switch_to_moudle(self, levelText1, levelText2): time.sleep(2) self.frameElem.from_frame_to_otherFrame("topFrame") self.cmf.select_menu(levelText1) self.cmf.select_menu(levelText1, levelText2) #----------------------------------------用户相关------------------------------ u'''填写用户信息 parameters: data[1] : 用户名称 data[3] : 用户账号 data[4] : 用户密码 data[5] : 确认密码 data[6] : 开始时间 data[7] : 访问方式 data[8] : AD域账号 roleText : 用户角色 ''' def set_user_basic_info(self, data, roleText, status='no'): self.frameElem.from_frame_to_otherFrame("mainFrame") if status != 'no': self.userElem.add_role_button() else: self.userElem.add_button() self.userElem.set_user_account(data[3]) self.userElem.set_user_name(data[1]) self.userElem.set_user_pwd(data[4]) self.userElem.set_user_enquire_pwd(data[5]) self.userElem.set_start_time(data[6]) if data[12] != "": self.userElem.set_user_email(data[12]) if data[10] != "": self.userElem.set_dep(data[10]) if data[7] != "": #设置访问方式 self.userElem.click_advanced_option() self.userElem.set_auth_method_rule(data[7]) #访问方式不是默认方式 if int(data[7]) != 2: self.userElem.set_ad_name(data[8]) if data[9] != "": self.userElem.set_user_role(roleText) self.userElem.click_role_add_button() self.userElem.save_button() self.cmf.click_login_msg_button() u'''删除用户''' def del_user(self): self.switch_to_moudle(u"运维管理", u"用户") self.frameElem.from_frame_to_otherFrame("mainFrame") self.userElem.select_all_button() self.userElem.del_button() self.frameElem.switch_to_content() self.cmf.click_login_msg_button() self.cmf.click_login_msg_button() u'''用户退出''' def user_quit(self): self.loginElem.quit() #-----------------------------部门-------------------------------------------- u'''填写部门名称 parameters : data[0] : 部门名称 data[1] : 操作类型(添加:0) data[2] : 添加的部门名称 ''' def set_dep(self, data): self.switch_to_moudle(u"运维管理", u"组织定义") self.dptment.click_left_department() #点击展开按钮 self.dptment.click_dept_switch() self.dptment.click_basic_operation(data[0], int(data[1])) self.dptment.popup_sendkey(data[2]) self.dptment.click_ok_button() self.cmf.click_login_msg_button() def set_del_dep(self, data): self.switch_to_moudle(u"运维管理", u"组织定义") self.dptment.click_left_department() self.dptment.click_dept_switch() self.dptment.click_basic_operation(data[0], int(data[1])) self.cmf.click_login_msg_button() self.cmf.click_login_msg_button() #-----------------------------用户组------------------------------------------ u'''添加用户到用户组''' def set_user_to_group(self, data): # self.usergroup.click_left_usergroup() # self.usergroup.click_usergroup_switch() self.usergroup.click_usergroup_add_user(data[3], data[4]) self.regroup.check_depart(data[5]) self.usergroup.click_usergroup_add_user_query() self.regroup.check_all_resource() self.regroup.click_resource_okbutton() self.cmf.click_login_msg_button() u'''填写用户组信息 parameters: data[0] : 操作类型(添加:0) data[1] : 部门名称 data[2] : 编辑的用户组名称 data[3] : 添加的用户组名称 ''' def set_add_user_group(self, data): self.switch_to_moudle(u"运维管理", u"组织定义") self.usergroup.click_left_usergroup() self.usergroup.click_usergroup_switch() self.usergroup.usergroup_click_basic_operation(int(data[0]), data[1], data[2]) self.dptment.popup_sendkey(data[3]) self.dptment.click_ok_button() self.cmf.click_login_msg_button() if data[4] != "": self.set_user_to_group(data) u'''删除用户组 parameters : data[0] : 操作类型(删除:4) data[1] : 部门名称 data[2] : 删除的用户组名称 ''' def set_del_user_group(self, data): self.switch_to_moudle(u"运维管理", u"组织定义") self.usergroup.click_left_usergroup() self.usergroup.click_usergroup_switch() self.usergroup.usergroup_click_basic_operation(int(data[0]), data[1], data[2]) self.cmf.click_login_msg_button() self.cmf.click_login_msg_button() #-----------------------------资源组------------------------------------------ u'''添加资源到资源组''' def set_res_to_group(self, data): self.regroup.click_regroup_add_resouce(data[3], data[4]) self.regroup.check_depart(data[5]) self.regroup.click_regroup_add_resouce_query() self.regroup.check_all_resource() self.regroup.click_resource_okbutton() time.sleep(1) self.cmf.click_login_msg_button() u'''填写资源组信息 parameters: data[0] : 操作类型(添加:0) data[1] : 部门名称 data[2] : 编辑的资源组名称 data[3] : 添加的资源组名称 ''' def set_add_res_group(self, data): self.switch_to_moudle(u"运维管理", u"组织定义") self.regroup.click_left_regroup() self.regroup.click_regroup_switch() self.regroup.regroup_click_basic_operation(int(data[0]), data[1], data[2]) self.dptment.popup_sendkey(data[3]) self.dptment.click_ok_button() self.cmf.click_login_msg_button() if data[4] != "": self.set_res_to_group(data) u'''删除资源组 parameters : data[0] : 操作类型(删除:4) data[1] : 部门名称 data[2] : 删除的资源组名称 ''' def set_del_res_group(self, data): self.switch_to_moudle(u"运维管理", u"组织定义") self.regroup.click_left_regroup() self.regroup.click_regroup_switch() self.regroup.regroup_click_basic_operation(int(data[0]), data[1], data[2]) self.cmf.click_login_msg_button() self.cmf.click_login_msg_button() #-----------------------------资源-------------------------------------------- u'''填写资源基本信息 parameters : data[0]:资源类型 data[1]:资源名称 data[2]:资源IP data[3]:部门 ''' def set_resource_info(self, data): self.switch_to_moudle(u"运维管理", u"资源") self.frameElem.from_frame_to_otherFrame("mainFrame") self.resource.click_add_edit_button() self.resource.select_resource_type(data[0]) self.resource.set_resource_name(data[1]) self.resource.set_resource_ip(data[2]) if data[3] != 'no': time.sleep(5) self.resource.set_depart(data[3]) #选择协议 if data[4] != "": self.resource.select_agreement(data[4]) if data[5] != "": self.resource.click_account_sync() self.resource.set_admin_account(data[5]) self.resource.set_admin_pwd(data[6]) self.resource.set_confirm_pwd(data[7]) #提权口令 if data[8] != "": self.resource.click_up_super() self.resource.set_super_pwd(data[8]) self.resource.set_super_confirm_pwd(data[9]) #填写域名 if data[10] != "": self.databaseElem.set_domain_name(data[10]) #账号分类 if data[11] != "": self.resource.click_account_sync() self.windowsElem.select_account_type(data[11]) #归属域控主机 if data[12] != "": self.windowsElem.select_attach_domian(data[12]) #主机名 if data[13] != "": self.databaseElem.set_host_name(data[13]) self.resource.click_save_button() self.cmf.click_login_msg_button() time.sleep(3) # self.driver.implicitly_wait(3) self.cmf.back() u'''填写数据库基本信息''' def set_database_res_info(self, data): self.switch_to_moudle(u"运维管理", u"资源") self.frameElem.from_frame_to_otherFrame("mainFrame") self.resource.click_add_edit_button() self.resource.select_resource_type(data[2]) self.databaseElem.add_edit_database_resource(data) self.cmf.click_login_msg_button() time.sleep(3) self.cmf.back() u'''填写资源账号基本信息 parameters: data[1]:资源名称 data[4] : 账号编辑方式 data[5] : 账号名称 data[6] : 口令 data[7] : 确认口令 ''' def set_res_account(self, data): self.switch_to_moudle(u"运维管理", u"资源") self.account.click_account_manage_button(data[0]) time.sleep(1) self.account.click_account_add_edit_button(data[2]) self.account.select_edit_way(data[1]) if data[2] != "no": self.account.set_account_name(data[2]) self.account.set_account_pwd(data[3]) self.account.set_account_confirm_pwd(data[4]) self.account.set_authorize() self.account.click_save_account() self.cmf.click_login_msg_button() #-----------------------------授权---------------------------------------- u'''填写授权基本信息 parameters: data[1]:授权名称 data[2]:部门名称 data[3]:状态 ''' def set_authorization(self, data): self.switch_to_moudle(u'运维管理', u'授权') self.authorizationElem.add_button() self.authorizationElem.set_auth_name(data[1]) self.authorizationElem.set_dep(data[2], data[3]) self.authorizationElem.click_add_user() self.authorizationElem.set_select_user_search_button() self.authorizationElem.set_user_check_all_button() self.authorizationElem.set_ok_button() #添加资源 self.authorizationElem.click_add_res() self.authorizationElem.set_select_res_search_button() self.authorizationElem.set_res_check_all_button() self.authorizationElem.set_ok_button() self.authorizationElem.save_button() self.cmf.click_login_msg_button() self.cmf.back() #---------------------------------填写应用发布信息---------------------------- u'''填写应用发布信息''' def set_application_info(self, data): self.switch_to_moudle(u"系统配置", u"关联服务") self.appElem.app_module_button() self.appElem.click_add_button() self.appElem.set_name(data[0]) self.appElem.set_ip(data[1]) self.appElem.set_app_account(data[3]) self.appElem.set_pwd(data[4]) self.appElem.set_repwd(data[5]) self.appElem.ip_is_succ() self.appElem.click_save_button() self.cmf.click_login_msg_button() u'''删除应用发布''' def del_application(self, rowList): self.switch_to_moudle(u"系统配置", u"关联服务") self.appElem.app_module_button() self.frameElem.from_frame_to_otherFrame("rigthFrame") app_data = self.get_table_data("add_application") for dataRow in rowList: data = app_data[dataRow] if dataRow != 0: self.appElem.operate_del(data[0]) self.cmf.click_login_msg_button() self.cmf.click_login_msg_button() #-------------------------------------客户端----------------------------------- u'''填写客户端基本信息''' def set_client_info(self, data): #self.switch_to_moudle(u"系统配置",u"客户端配置") self.frameElem.from_frame_to_otherFrame("mainFrame") self.clientElem.add_button() self.clientElem.set_client_name(data[2]) self.clientElem.set_action_stream(data[3]) self.clientElem.set_database_res_type(data[0], data[1]) self.clientElem.save_button() u'''删除客户端''' def set_delete_client_info(self, data): #self.switch_to_moudle(u"系统配置",u"客户端配置") self.frameElem.from_frame_to_otherFrame("mainFrame") self.clientElem.select_query_res_type(data[0], data[1]) self.clientElem.click_query_button() self.clientElem.del_operation(data[2]) self.cmf.click_login_msg_button() #------------------------------资源账号授权------------------------------------ u'''添加用户和资源账号类型的授权''' def set_authorization_info(self, data): self.switch_to_moudle(u"运维管理", u"授权") self.testAutho.common_part(data) self.testAutho.add_user(data) self.authorizationElem.click_add_res_account() self.authorizationElem.set_select_res_ip(data[6]) self.authorizationElem.set_select_res_account(data[8]) self.authorizationElem.set_select_res_search_button() self.authorizationElem.set_res_check_all_button() self.authorizationElem.set_ok_button() self.authorizationElem.res_account_status() self.authorizationElem.save_button() self.cmf.click_login_msg_button() u'''删除授权''' def del_authorization(self): self.switch_to_moudle(u"运维管理", u"授权") self.frameElem.from_frame_to_otherFrame("mainFrame") self.authorizationElem.check_all() self.authorizationElem.del_button() self.cmf.click_login_msg_button() self.cmf.click_login_msg_button() #-----------------------------数据---------------------------------------- u'''获取数据 Parameters: - sheetname:sheet名称 return:表格数据 ''' def get_table_data(self, sheetname): filePath = self.dataFile.get_common_suite_test_data_url() fileData = self.dataFile.get_data(filePath, sheetname) return fileData u'''添加应用发布''' def add_application(self, rowList): app_data = self.get_table_data('add_application') for dataRow in rowList: data = app_data[dataRow] if dataRow != 0: self.set_application_info(data) u'''初始化用户登录''' def isomper_login(self): login_data = self.get_table_data('add_user') logindata = login_data[4] self.loginElem.login(logindata) u'''添加用户数据模板''' def add_user_data_module(self, rowList): self.switch_to_moudle(u"运维管理", u"用户") user_data = self.get_table_data("add_user") for dataRow in rowList: data = user_data[dataRow] if dataRow != 0: self.set_user_basic_info(data, data[9], data[13]) self.userElem.click_back_button() u'''添加系统管理员和部门管理员的用户''' def add_user_with_role(self): rowList = [1] self.add_user_data_module(rowList) u'''登录并切换至角色公用方法 parameters: login_status :'no'(登录状态:没有登录) ''' def login_and_switch_to_common(self, login_status='no'): login_data = self.get_table_data("add_user") logindata = login_data[1] if login_status == 'no': self.loginElem.login(logindata) #获取角色 roleList = logindata[9].split(',') return roleList u'''使用系统管理员登录系统''' def login_sysadmin(self): login_data = self.get_table_data('add_user') logindata = login_data[1] self.loginElem.login(logindata) u'''使用安全保密管理员登录系统''' def login_secadmin(self): login_data = self.get_table_data('add_user') logindata = login_data[2] self.loginElem.login(logindata) u'''使用安全审计员登录系统''' def login_sysaudit(self): login_data = self.get_table_data('add_user') logindata = login_data[3] self.loginElem.login(logindata) u'''用户登录系统''' def login_user(self, row): login_data = self.get_table_data('add_user') logindata = login_data[int(row)] self.loginElem.login(logindata) u'''切换至运维操作员''' def switch_to_operation(self): self.cmf.select_role_by_text(u"运维操作员") #使用新添加的用户登录 def use_new_user_login(self): login_data = self.get_table_data("add_user") logindata = login_data[1] time.sleep(2) self.loginElem.login(logindata) u'''运维管理员登录''' def sso_user_login(self, rowList): login_data = self.get_table_data("add_user") logindata = login_data[rowList] time.sleep(1) self.loginElem.login(logindata) u'''运维管理员AD域方式登录''' def sso_user_ad_login(self, rowList): login_data = self.get_table_data("add_user") logindata = login_data[rowList] self.frameElem.switch_to_content() self.loginElem.set_login_method(logindata[2]) self.loginElem.set_ad_login_username(logindata[3]) self.loginElem.set_ad_login_pwd(logindata[11]) time.sleep(1) self.loginElem.click_login_button() u'''添加认证配置''' def add_meth_method(self): meth_data = self.get_table_data("meth_method") methData = meth_data[1] self.switch_to_moudle(u"策略配置", u"认证强度") self.authElem.select_all_auth(methData) u'''会话配置,设置最大登录数''' def set_login_max_num(self): self.loginElem.set_max_login_count() u'''添加登录测试数据''' def add_login_data(self): rowList = [2, 3, 4, 5, 6, 7] self.add_user_data_module(rowList) u'''添加授权用户''' def add_authorization_user(self): rowList = [8, 9, 10, 11, 12] self.add_user_data_module(rowList) u'''添加应用发布用户''' def add_app_user(self): rowList = [3] self.add_user_data_module(rowList) u'''添加单点登录用户''' def add_sso_user(self): rowList = [6, 8, 9, 10, 11, 13] self.add_user_data_module(rowList) u'''添加部门''' def add_dep(self, rowList): dep_data = self.get_table_data("add_dep") for dataRow in rowList: data = dep_data[dataRow] if dataRow != 0: self.set_dep(data) u'''删除部门''' def del_dep(self, rowList): dep_data = self.get_table_data("del_dep") for dataRow in rowList: data = dep_data[dataRow] if dataRow != 0: self.set_del_dep(data) u'''增加资源数据模板''' def add_resource_modele(self, rowList): res_data = self.get_table_data("add_res") for dataRow in rowList: data = res_data[dataRow] if dataRow != 0: self.set_resource_info(data) u'''添加授权资源''' def add_resource(self): rowList = [1, 2] self.add_resource_modele(rowList) u'''添加sso资源''' def add_sso_resource(self): #rowList = [1,2,3,4,5,7,8] rowList = [1, 3, 4, 5] self.add_resource_modele(rowList) u'''添加依附操作系统''' def add_database_resource(self): rowList = [2] self.add_resource_modele(rowList) u'''添加资源账号数据模板''' def add_res_account_module(self, rowList): account_data = self.get_table_data("res_account") for dataRow in rowList: data = account_data[dataRow] if dataRow != 0: self.set_res_account(data) u'''添加授权资源账号''' def add_res_account(self): rowList = [1, 3] self.add_res_account_module(rowList) u'''添加sso资源账号''' def add_sso_res_account(self): rowList = [1, 2, 4, 5, 6, 7] #rowList = [1,2,3,4,5,6,7,9,10] self.add_res_account_module(rowList) u'''添加用户组''' def add_user_group(self, rowList): user_group_data = self.get_table_data("add_user_group") for dataRow in rowList: data = user_group_data[dataRow] if dataRow != 0: self.set_add_user_group(data) u'''删除用户组''' def del_user_group(self, rowList): user_group_data = self.get_table_data("del_user_group") for dataRow in rowList: data = user_group_data[dataRow] if dataRow != 0: self.set_del_user_group(data) u'''添加资源组''' def add_res_group(self, rowList): res_group_data = self.get_table_data("add_res_group") for dataRow in rowList: data = res_group_data[dataRow] if dataRow != 0: self.set_add_res_group(data) u'''删除资源组''' def del_res_group(self, rowList): res_group_data = self.get_table_data("del_res_group") for dataRow in rowList: data = res_group_data[dataRow] if dataRow != 0: self.set_del_res_group(data) u'''添加授权''' def add_authrization(self, rowList): auth_data = self.get_table_data("add_authorization") for dataRow in rowList: data = auth_data[dataRow] if dataRow != 0: self.set_authorization(data) u'''添加授权数据模板''' def add_authorization_module(self, rowList): autho_data = self.get_table_data("add_account_auth") for dataRow in rowList: data = autho_data[dataRow] if dataRow != 0: self.set_authorization_info(data) self.authorizationElem.back_button() u'''添加单点登录授权''' def add_sso_authorization(self): rowList = [1] #rowList = [1,2,3,4,5,6,7] self.add_authorization_module(rowList) u'''单点登录模板''' def sso_module(self, rowList): sso_data = self.get_table_data("sso") for dataRow in rowList: data = sso_data[dataRow] if dataRow != 0: self.frameElem.from_frame_to_otherFrame("rigthFrame") self.ssoElem.select_account(data[0], data[1]) self.ssoElem.select_sso_icon(data[0], data[2]) if data[3] != "": self.ssoElem.select_protocol(data[3]) #self.ssoElem.execute_chrome_key() self.ssoElem.choice_browser(data[2], data[4], data[5], data[6]) u'''添加客户端数据模板''' def add_client_module(self, rowList): client_data = self.get_table_data("add_client") self.switch_to_moudle(u"系统配置", u"客户端配置") for dataRow in rowList: data = client_data[dataRow] if dataRow != 0: self.set_client_info(data) u'''删除客户端数据模板''' def del_client_module(self, rowList): client_data = self.get_table_data("del_client") self.switch_to_moudle(u"系统配置", u"客户端配置") for dataRow in rowList: data = client_data[dataRow] if dataRow != 0: self.set_delete_client_info(data) u'''添加数据库资源模板''' def add_database_res_module(self, rowList): database_data = self.get_table_data("add_database") for dataRow in rowList: data = database_data[dataRow] if dataRow != 0: self.set_database_res_info(data) u'''删除用户数据模板''' def del_user_data_module(self, rowList): self.switch_to_moudle(u"运维管理", u"用户") self.frameElem.from_frame_to_otherFrame("mainFrame") user_data = self.get_table_data("add_user") for dataRow in rowList: data = user_data[dataRow] if dataRow != 0: self.switch_to_moudle(u"运维管理", u"用户") self.userElem.operate_delete(data[1]) self.frameElem.switch_to_content() self.cmf.click_login_msg_button() self.cmf.click_login_msg_button() u'''添加密码策略数据模板''' def add_strategy_data_module(self, rowList): self.switch_to_moudle(u"策略配置", u"密码策略") self.frameElem.from_frame_to_otherFrame("mainFrame") pwd_data = self.get_table_data("add_strategy") for dataRow in rowList: data = pwd_data[dataRow] if dataRow != 0: self.PwdStr.add_pwd_button() self.PwdStr.set_pwd_name(data[1]) self.PwdStr.term_of_validity(data[2]) self.PwdStr.password_length_min(data[3]) self.PwdStr.password_length_max(data[4]) self.PwdStr.set_lower_case(data[5]) self.PwdStr.set_capital(data[6]) self.PwdStr.set_minimum_digital(data[7]) self.PwdStr.set_Minimum_symbol(data[8]) self.PwdStr.save_button() self.frameElem.switch_to_content() self.cmf.click_msg_button(1) self.PwdStr.return_button() u'''删除密码策略数据模板''' def del_strategy_data_module(self, rowList): self.switch_to_moudle(u"策略配置", u"密码策略") self.frameElem.from_frame_to_otherFrame("mainFrame") pwd_data = self.get_table_data("add_strategy") for dataRow in rowList: data = pwd_data[dataRow] if dataRow != 0: self.PwdStr.del_sing_strategy(data[1]) self.frameElem.switch_to_content() self.cmf.click_login_msg_button() self.cmf.click_login_msg_button() u'''删除资源数据模板''' def del_resource_modele(self, rowList): self.switch_to_moudle(u"运维管理", u"资源") self.frameElem.from_frame_to_otherFrame("mainFrame") res_data = self.get_table_data("add_res") for dataRow in rowList: data = res_data[dataRow] if dataRow != 0: self.resource.click_del_button(data[1]) self.frameElem.switch_to_content() self.cmf.click_login_msg_button() self.cmf.click_login_msg_button() u'''删除授权数据模板''' def del_authorization_module(self, rowList): self.switch_to_moudle(u'运维管理', u'授权') self.frameElem.from_frame_to_otherFrame("mainFrame") autho_data = self.get_table_data("add_account_auth") for dataRow in rowList: data = autho_data[dataRow] if dataRow != 0: self.authorizationElem.click_auth_checkbox(data[2]) self.authorizationElem.del_button() self.frameElem.switch_to_content() self.cmf.click_login_msg_button() self.cmf.click_login_msg_button() #-------------------------------添加涉密版用户前置条件--------------------------------------- u'''前置条件通用''' def secret_user_prefix_condition(self): self.isomper_login() self.switch_to_moudle(u'角色管理', u'角色定义') #------------------------------部门前置条件----------------------------------- def depart_module_prefix_condition(self): #使用系统管理员登录 self.login_sysadmin() #切换到组织定义 self.switch_to_moudle(u"运维管理", u"组织定义") #------------------------------资源组前置条件----------------------------------- def regroup_module_prefix_condition(self): #使用安全保密管理员登录 self.login_secadmin() #添加资源 self.add_resource_modele([9, 6]) self.user_quit() #使用系统管理员登录 self.login_sysadmin() #切换到组织定义 self.switch_to_moudle(u"运维管理", u"组织定义") def regroup_module_post_condition(self): self.user_quit() #使用安全保密管理员登录 self.login_secadmin() #删除资源 self.del_resource_modele([9, 6]) self.user_quit() #------------------------------用户组前置条件----------------------------------- def usergroup_module_prefix_condition(self): #使用系统管理员登录 self.login_sysadmin() #添加用户 self.add_user_data_module([5, 6, 7, 8]) #切换到组织定义 self.switch_to_moudle(u"运维管理", u"组织定义") def usergroup_module_post_condition(self): self.del_user_data_module([5, 6, 7, 8]) self.user_quit() #------------------------------NTP服务前置条件--------------------------------- def ntp_module_prefix_condition(self): #使用系统管理员登录 self.login_sysadmin() #切换到NTP服务 self.switch_to_moudle(u'系统配置', u'关联服务') self.ntp.click_left_moudle(0) #-------------------------------SYSLOG前置条件--------------------------------- def syslog_module_prefix_condition(self): #使用系统管理员登录 self.login_sysadmin() #切换到NTP服务 self.switch_to_moudle(u'系统配置', u'关联服务') self.ntp.click_left_moudle(1) #------------------------------邮件前置条件--------------------------------- def mail_module_prefix_condition(self): #使用系统管理员登录 self.login_sysadmin() #切换到邮件服务 self.switch_to_moudle(u'系统配置', u'关联服务') self.mail.click_left_moudle_test() #------------------------------密码信封前置条件--------------------------------- def passwd_envelope_module_prefix_condition(self): #使用系统管理员登录 self.login_sysadmin() #切换到邮件服务 self.switch_to_moudle(u'系统配置', u'关联服务') self.passwdenvelope.click_left_moudle_envelope() #-------------------------------应用发布后置条件------------------------------- def application_module_prefix_condition(self): #使用系统管理员登录 self.login_sysadmin() self.add_user_data_module([9, 10]) self.switch_to_moudle(u"系统配置", u"关联服务") def application_module_post_condition(self): self.del_user_data_module([9, 10]) self.user_quit() #-------------------------------网卡配置前置条件------------------------------- def network_card_module_prefix_condition(self): #使用系统管理员登录 self.login_sysadmin() #切换到网卡配置 self.switch_to_moudle(u'系统配置', u'网络配置') #-------------------------------路由配置前置条件------------------------------- def routing_module_prefix_condition(self): #使用系统管理员登录 self.login_sysadmin() #切换到路由配置 self.cmf.select_menu(u'系统配置', u'网络配置', u'路由配置') #------------------------------备份还原前置条件----------------------------------- def backup_restore_module_prefix_condition(self): #使用系统管理员登录 self.login_sysadmin() #-----------------------------客户端配置前置条件------------------------------ def client_module_prefix_condition(self): #使用系统管理员登录 self.login_sysadmin() self.switch_to_moudle(u"系统配置", u"客户端配置") #-----------------------------AD域抽取前置条件------------------------------ def ad_module_prefix_condition(self): #使用系统管理员登录 self.login_sysadmin() self.add_user_data_module([18]) self.switch_to_moudle(u"系统配置", u"AD定时抽取") u'''AD域抽取后置条件''' def ad_module_post_condition(self): self.del_user_data_module([18]) self.user_quit() #------------------------------使用授权前置条件--------------------------------- def use_auth_module_prefix_condition(self): #使用系统管理员登录 self.login_sysadmin() self.switch_to_moudle(u'系统配置', u'使用授权') #------------------------------用户模块前置条件-------------------------------- u'''用户模块前置条件''' def user_module_prefix_condition(self): #使用系统管理员登录 self.login_sysadmin() self.switch_to_moudle(u'运维管理', u'用户') #--------------------------认证方式前置条件------------------------------------ u'''认证方式前置条件''' def auth_method_prefix_condition(self): #使用安全保密管理员登录 self.login_secadmin() self.add_user_data_module([11]) self.switch_to_moudle(u"策略配置", u"认证强度") self.frameElem.from_frame_to_otherFrame("mainFrame") u'''认证方式后置条件''' def auth_method_post_condition(self): self.del_user_data_module([11]) self.user_quit() #---------------------------------登录模块前置条件----------------------------- u'''登录模块前置条件''' def login_module_prefix_condition(self): #使用安全保密管理员登录 self.login_secadmin() #配置认证方式 self.add_meth_method() #配置最大登录数 self.set_login_max_num() #添加登录用户数据 self.add_user_data_module([12, 13, 14, 15, 16, 17]) #改变a的状态为关 self.userElem.change_user_status_off("gyrlogin2") #系统管理员退出 self.user_quit() u'''登录模块后置条件''' def login_module_post_condition(self): #使用安全保密管理员登录 self.login_secadmin() #删除认证方式 self.authElem.del_auth_method() self.del_user_data_module([12, 13, 14, 15, 16, 17]) self.user_quit() #------------------------------告警策略前置条件--------------------------------- def alarm_strategy_module_prefix_condition(self): #使用安全保密管理员登录 self.login_secadmin() def alarm_strategy_module_post_condition(self): self.alarm.del_command_config() self.alarm.del_default_config() self.alarm.del_auth_config() self.user_quit() #------------------------------会话配置前置条件-------------------------------- def session_module_prefix_condition(self): #使用安全保密管理员登录 self.login_secadmin() self.switch_to_moudle(u"策略配置", u"会话配置") #------------------------------密码策略前置条件-------------------------------- def pwdstr_module_prefix_condition(self): #使用安全保密管理员登录 self.login_secadmin() #添加资源 self.add_resource_modele([14]) self.add_user_data_module([19]) self.switch_to_moudle(u"策略配置", u"密码策略") def pwdstr_module_post_condition(self): self.del_resource_modele([14]) self.del_user_data_module([19]) self.user_quit() #------------------------------linux资源前置条件----------------------------------- def linuxre_module_prefix_condition(self): #使用安全保密管理员登录 self.login_secadmin() #添加密码策略 self.add_strategy_data_module([1]) #切换到资源 self.switch_to_moudle(u"运维管理", u"资源") def linuxre_module_post_condition(self): #删除密码策略 self.del_strategy_data_module([1]) self.user_quit() #------------------------------network资源前置条件----------------------------------- def networkre_module_prefix_condition(self): #使用安全保密管理员登录 self.login_secadmin() #切换到资源 self.switch_to_moudle(u"运维管理", u"资源") #------------------------------windows资源前置条件----------------------------------- def windowre_module_prefix_condition(self): #使用安全保密管理员登录 self.login_secadmin() #添加密码策略 self.add_strategy_data_module([2]) #切换到资源 self.switch_to_moudle(u"运维管理", u"资源") def windowre_module_post_condition(self): #删除密码策略 self.del_strategy_data_module([2]) self.user_quit() #-----------------------------数据库前置条件---------------------------------- def database_resource_prefix_condition(self): self.login_sysadmin() #添加应用发布 self.add_application([1]) self.user_quit() #使用安全保密管理员登录 self.login_secadmin() self.add_resource_modele([17]) self.switch_to_moudle(u"运维管理", u"资源") def database_resource_post_condition(self): self.del_resource_modele([17]) self.user_quit() self.login_sysadmin() self.del_application([1]) self.user_quit() #------------------------------授权前置条件----------------------------------- def authori_module_prefix_condition(self): #使用安全保密管理员登录 self.login_secadmin() self.add_resource_modele([15, 16]) self.add_res_account_module([18, 19]) self.user_quit() self.login_sysadmin() #添加授权用户 self.add_user_data_module([20, 21, 22, 23, 24]) self.add_res_group([1]) self.add_user_group([1]) self.user_quit() self.login_secadmin() self.switch_to_moudle(u'运维管理', u'授权') def authori_module_post_condition(self): self.del_resource_modele([15, 16]) self.user_quit() self.login_sysadmin() self.del_res_group([1]) self.del_user_group([1]) self.del_user_data_module([20, 21, 22, 23, 24]) self.user_quit() #------------------------------命令规则前置条件----------------------------------- def commandrule_module_prefix_condition(self): self.login_sysadmin() #添加用户 self.add_user_data_module([25]) self.user_quit() self.login_secadmin() #添加资源 self.add_resource_modele([3]) #添加资源账号 self.add_res_account_module([4]) #添加授权 self.add_authorization_module([2]) #切换到规则定义 self.switch_to_moudle(u'运维管理', u'规则定义') self.command.click_left_rule(0) def commandrule_module_post_condition(self): #删除授权 self.del_authorization_module([2]) #删除资源 self.del_resource_modele([3]) self.user_quit() self.login_sysadmin() #删除用户 self.del_user_data_module([25]) self.user_quit() #------------------------------时间规则前置条件----------------------------------- def timerule_module_prefix_condition(self): self.login_secadmin() #添加用户 self.add_user_data_module([26, 27, 28, 29, 30]) #切换到规则定义 self.switch_to_moudle(u'运维管理', u'规则定义') self.command.click_left_rule(1) def timerule_module_post_condition(self): #删除用户 self.del_user_data_module([26, 27, 28, 29, 30]) self.user_quit() #------------------------------地址规则前置条件----------------------------------- def addressrule_module_prefix_condition(self): self.login_secadmin() #添加用户 self.add_user_data_module([31, 32, 33, 34, 35, 36, 37, 38]) #切换到规则定义 self.switch_to_moudle(u'运维管理', u'规则定义') self.command.click_left_rule(2) def addressrule_module_post_condition(self): self.del_user_data_module([31, 32, 33, 34, 35, 36, 37, 38]) self.user_quit() #------------------------------资源时间规则前置条件----------------------------------- def retimerule_module_prefix_condition(self): self.login_sysadmin() #添加用户 self.add_user_data_module([39]) self.user_quit() self.login_secadmin() #添加资源 self.add_resource_modele([4, 5, 10]) #添加资源账号 self.add_res_account_module([5, 6, 14]) self.add_authorization_module([6]) #切换到规则定义 self.switch_to_moudle(u'运维管理', u'规则定义') self.command.click_left_rule(3) def retimerule_module_post_condition(self): self.user_quit() self.login_sysadmin() #删除用户 self.del_user_data_module([39]) self.user_quit() self.login_secadmin() #删除资源 self.del_resource_modele([4, 5, 10]) #删除授权 self.del_authorization_module([6]) self.user_quit() #------------------------------流程前置条件----------------------------------- def process_module_prefix_condition(self): self.login_sysadmin() #添加用户 self.add_user_data_module([40, 41, 42, 43, 44]) self.user_quit() self.login_secadmin() #添加资源 self.add_resource_modele([11, 12]) #添加资源账号 self.add_res_account_module([15, 16]) self.add_authrization([1]) def process_module_post_condition(self): #删除授权 self.del_authorization_module([7]) #删除资源 self.del_resource_modele([11, 12]) self.user_quit() self.login_sysadmin() #删除用户 self.del_user_data_module([40, 41, 42, 43, 44]) self.user_quit() #------------------------------双人授权前置条件----------------------------------- def dualmandate_module_prefix_condition(self): self.login_sysadmin() #添加用户 self.add_user_data_module([45, 46]) self.user_quit() self.login_secadmin() #添加资源 self.add_resource_modele([13]) #添加资源账号 self.add_res_account_module([17]) #添加授权 self.add_authrization([4]) def dualmandate_module_post_condition(self): #删除授权 self.del_authorization_module([8]) #删除资源 self.del_resource_modele([13]) self.user_quit() self.login_sysadmin() #删除用户 self.del_user_data_module([45, 46]) self.user_quit() #-----------------------------行为报表前置条件--------------------------------- def opt_report_module_prefix_condition(self): self.login_secadmin() self.add_resource_modele([18]) self.user_quit() self.login_sysadmin() self.add_user_data_module([47]) self.add_res_group([2]) self.add_user_group([2]) self.user_quit() self.login_sysaudit() self.switch_to_moudle(u"报表管理", u"审计报表") def opt_report_module_post_condition(self): self.user_quit() self.login_secadmin() self.del_resource_modele([18]) self.user_quit() self.login_sysadmin() self.del_user_data_module([47]) self.del_res_group([2]) self.del_user_group([2]) self.user_quit() #-----------------------------配置报表前置条件--------------------------------- def conf_report_module_prefix_condition(self): self.login_sysadmin() self.add_user_data_module([48]) self.add_user_group([3]) self.user_quit() self.login_sysaudit() self.switch_to_moudle(u"报表管理", u"审计报表") def conf_report_module_post_condition(self): self.user_quit() self.login_sysadmin() self.del_user_data_module([48]) self.del_user_group([3]) self.user_quit() #-----------------------------配置审计前置条件------------------------------ def system_log_prefix_condition(self): self.login_sysadmin() self.add_user_data_module([49]) self.switch_to_moudle(u"系统配置", u"关联服务") self.ntp.click_left_moudle(1) #填写syslog信息 self.frameElem.from_frame_to_otherFrame("rigthFrame") self.syslog.set_ip("172.16.10.11") self.syslog.set_ident("aa") self.syslog.save_button() self.cmf.click_login_msg_button() self.user_quit() self.login_sysaudit() self.switch_to_moudle(u"审计管理", u"配置审计") def system_log_post_condition(self): self.user_quit() self.login_sysadmin() self.del_user_data_module([49]) self.user_quit() #-----------------------------运维审计前置条件------------------------------ def audit_log_prefix_condition(self): self.login_and_switch_to_dep() self.add_user_data_module([43]) self.add_resource_modele([22]) self.add_res_account_module([20]) self.add_authorization_module([9]) self.switch_to_operation() self.sso_module([1]) self.user_quit() #新添加的运维管理员登录 self.sso_user_login(43) self.sso_module([1]) #新添加的运维管理员退出 self.user_quit() self.login_and_switch_to_sys() self.switch_to_moudle(u"审计管理", u"运维审计") def audit_log_post_condition(self): self.sys_switch_to_dep() self.del_authorization_module([9]) self.del_resource_modele([22]) self.del_user_data_module([43]) self.user_quit() #------------------------------命令单点登录前置条件---------------------------- u'''单点登录前置条件''' def sso_prefix_condition(self): self.login_and_switch_to_dep() self.add_resource_modele([1, 3, 4, 5]) self.add_res_account_module([1, 2, 4, 5, 6, 7]) self.add_authorization_module([1]) self.switch_to_operation() #self.user_quit() #self.login_and_switch_to_common() u'''单点登录后置条件''' def sso_post_condition(self): self.user_quit() self.login_and_switch_to_dep() self.del_resource_modele([1, 3, 4, 5]) self.del_authorization_module([1]) self.user_quit() #------------------------------windows单点登录前置条件------------------------- u'''windows单点登录前置条件''' def windows_sso_prefix_condition(self): self.login_and_switch_to_sys() #配置认证方式 self.add_meth_method() self.add_user_data_module([42]) self.sys_switch_to_dep() #self.login_and_switch_to_dep() self.add_resource_modele([2, 7, 8]) self.add_res_account_module([3, 9, 10]) self.add_authorization_module([3, 4]) self.switch_to_operation() #self.user_quit() #self.login_and_switch_to_common() u'''单点登录后置条件''' def windows_sso_post_condition(self): self.user_quit() self.login_and_switch_to_dep() self.del_authorization_module([3, 4]) self.del_user_data_module([42]) self.del_resource_modele([8, 7, 2]) self.user_quit() #------------------------------数据库单点登录前置条件------------------------- u'''数据库单点登录前置条件''' def database_sso_prefix_condition(self): #使用公共用户登录系统 self.login_and_switch_to_sys() #添加应用发布 self.add_application([2]) #添加客户端 self.add_client_module([1, 2]) self.sys_switch_to_dep() self.add_database_res_module([1, 2, 3]) self.add_res_account_module([11, 12, 13]) self.add_authorization_module([5]) self.switch_to_operation() u'''数据库单点登录后置条件''' def database_sso_post_condition(self): self.user_quit() self.login_and_switch_to_dep() self.del_authorization_module([5]) self.del_resource_modele([19, 20, 21]) self.dep_switch_to_sys() self.del_application([2]) self.del_client_module([1, 2]) self.user_quit()
class User(): def __init__(self,driver): self.driver = driver self.log = log() self.user = UserPage(driver) self.cmf = commonFun(driver) self.getElem = getElement(driver) self.cnEnde = cnEncode() self.selectElem = selectElement(driver) self.dataFile = dataFileName() self.frameElem = frameElement(self.driver) self.tableEle = tableElement(self.driver) u'''提示框元素路径''' def user_msg(self): user_msg = "html/body/div[1]/div/table/tbody/tr[2]/td[2]/div/table/tbody/tr[2]/td[2]/div" return user_msg u'''获取测试数据 Parameters: - sheetname:sheet名称 return:表格数据 ''' def get_table_data(self,sheetname): dataFile = dataFileName() filePath = dataFile.get_person_test_data_url() authFileData = dataFile.get_data(filePath,sheetname) return authFileData u'''校验有弹出框类型用例是否通过 parameters: data : 检查点 flag : 通过标识(True or False) ''' def check_with_pop_up(self,data,flag): #点击保存按钮弹出框 user_msg = self.user_msg() self.frameElem.switch_to_content() self.cmf.test_win_check_point("xpath",user_msg,data,flag) u'''校验没有弹出框类型用例是否通过 parameters: data : 检查点 flag : 通过标识(True lse) status : 0,代表判断条件为相等 ''' def check_without_pop_up(self,var1,var2,data): #点击保存按钮弹出框 user_msg = self.user_msg() if var1 == var2: self.cmf.test_win_check_point("","",data,True) else: self.cmf.test_win_check_point("","",data,False) u'''重置''' def reset(self): self.user.click_reset_button() self.user.click_search_button() u'''切换至用户模块''' def switch_to_user_module(self): self.frameElem.switch_to_content() self.frameElem.switch_to_top() self.cmf.select_menu(u"运维管理") self.cmf.select_menu(u"运维管理",u"用户") u'''添加用户''' def add_user_001(self): #日志开始记录 self.log.log_start("addUser") #获取添加用户的数据 user_data = self.get_table_data("add_user") #无检查点的测试项标识,如果为True说明通过 flag = False for dataRow in range(len(user_data)): data = user_data[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: self.frameElem.from_frame_to_otherFrame("mainFrame") self.user.add_button() self.user.set_user_account(data[2]) self.user.set_user_name(data[3]) if data[6] != "": self.user.set_dep(data[6]) self.user.set_user_pwd(data[7]) self.user.set_user_enquire_pwd(data[8]) self.user.set_user_role(data[15]) self.user.click_role_add_button() self.user.save_button() #判断测试项是否通过 self.check_with_pop_up(data,flag) #清空标识状态 flag = False # self.switch_to_user_module() # self.cmf.back() self.user.click_back_button() if self.cmf.is_namevalue_exsit(data[2],"fortUserAccount"): print ("add user success") except Exception as e: print ("user add fail: ") + str(e) self.log.log_end("addUser") u'''编辑用户''' def edit_user_002(self): #日志开始记录 self.log.log_start("editUser") #获取编辑用户的数据 user_data = self.get_table_data("mod_user") #无检查点的测试项标识,如果为True说明通过 flag = False for dataRow in range(len(user_data)): data = user_data[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: self.frameElem.from_frame_to_otherFrame("mainFrame") self.user.operate_edit(data[2]) self.user.set_user_account(data[3]) self.user.set_user_name(data[4]) self.user.set_user_status(data[8]) self.user.set_user_pwd(data[9]) self.user.set_user_enquire_pwd(data[10]) self.user.save_button() #判断测试项是否通过 self.check_with_pop_up(data,flag) #清空标识状态 flag = False self.switch_to_user_module() # self.cmf.back() # self.user.click_back_button() if self.cmf.is_namevalue_exsit(data[2],"fortUserAccount"): print ("edit user success") except Exception as e: print ("edit user fail: ") + str(e) self.log.log_end("editUser") u'''生成证书''' def create_user_cert_003(self): #日志开始记录 self.log.log_start("CreateUserCert") #获取生成证书用户的数据 user_data = self.get_table_data("create_cert") #无检查点的测试项标识,如果为True说明通过 flag = False for dataRow in range(len(user_data)): data = user_data[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: self.frameElem.from_frame_to_otherFrame("mainFrame") self.user.operate_cert(data[3]) self.user.create_cert() cert_name = self.user.get_cert() #判断生成的证书名字和指定的名字是否相等 self.check_without_pop_up(cert_name,data[2],data) #清空标识状态 flag = False self.switch_to_user_module() # self.cmf.back() except Exception as e: print ("Create user cert fail: ") + str(e) self.log.log_end("CreateUserCert") u'''重新生成证书''' def create_user_cert_again_003(self): #点击保存按钮弹出框 user_msg = self.user_msg() #日志开始记录 self.log.log_start("ReCreateUserCert") #获取重新生成证书的数据 user_data = self.get_table_data("reCreate_cert") #无检查点的测试项标识,如果为True说明通过 flag = False for dataRow in range(len(user_data)): data = user_data[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: self.frameElem.from_frame_to_otherFrame("mainFrame") self.user.operate_cert(data[2]) cert_num_old = self.user.get_cert_serial_num() self.user.create_cert() self.cmf.click_login_msg_button() self.frameElem.from_frame_to_otherFrame("mainFrame") cert_num_new = self.user.get_cert_serial_num() if cert_num_old != cert_num_new: self.cmf.test_win_check_point("","",data,True) else: self.cmf.test_win_check_point("","",data,False) #清空标识状态 flag = False self.switch_to_user_module() # self.cmf.back() except Exception as e: print ("ReCreate user cert fail: ") + str(e) self.log.log_end("ReCreateUserCert") u'''删除证书''' def delete_user_cert_004(self): #日志开始记录 self.log.log_start("DeleteUserCert") #获取删除证书的数据 user_data = self.get_table_data("delete_cert") #无检查点的测试项标识,如果为True说明通过 flag = False for dataRow in range(len(user_data)): data = user_data[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: self.frameElem.from_frame_to_otherFrame("mainFrame") self.user.operate_cert(data[3]) self.user.delete_cert() #判断测试项是否通过 self.check_with_pop_up(data,flag) self.frameElem.from_frame_to_otherFrame("mainFrame") if self.user.get_init_cert_name() == data[2]: print ("Delete cert success!") #清空标识状态 flag = False self.frameElem.from_frame_to_otherFrame("mainFrame") # self.switch_to_user_module() self.cmf.back() except Exception as e: print ("Delete user cert fail: ") + str(e) self.log.log_end("DeleteUserCert") u'''校验用户''' def checkout_user_005(self): #保存成功的弹出框 user_msg = self.user_msg() #日志开始记录 self.log.log_start("checkoutUser") #获取用户校验的数据 user_data = self.get_table_data("user_check")#user_check #无检查点的测试项标识,如果为True说明通过 self.frameElem.from_frame_to_otherFrame("mainFrame") self.user.add_button() flag = False for dataRow in range(len(user_data)): data = user_data[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: self.frameElem.from_frame_to_otherFrame("mainFrame") self.user.set_user_account(data[2]) self.user.set_user_name(data[3]) if dataRow == range(len(user_data))[-1]: self.user.clear_dep() self.user.set_user_pwd(data[7]) self.user.set_user_enquire_pwd(data[8]) self.user.set_user_mobile(data[9]) self.user.set_user_phone(data[10]) self.user.set_user_email(data[11]) self.user.save_button() #判断测试项是否通过 self.check_with_pop_up(data,flag) #清空标识状态 flag = False except Exception as e: print ("checkoutUser fail: ") + str(e) self.switch_to_user_module() self.log.log_end("checkoutUser") u'''检索条件:用户状态''' def search_user_by_status_006(self): #日志开始记录 self.log.log_start("Search user by status") #获取按照用户状态检索的数据 user_data = self.get_table_data("search_by_status")#user_check #无检查点的测试项标识,如果为True说明通过 flag = False for dataRow in range(len(user_data)): data = user_data[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: self.frameElem.from_frame_to_otherFrame("mainFrame") row = self.user.search_by_status(data[3]) self.user.search_by_user_status(data[2]) self.user.click_search_button() search_row = self.user.get_rows() #判断测试项是否通过 self.check_without_pop_up(row,search_row,data) self.reset() #清空标识状态 flag = False except Exception as e: print ("search user by status fail: ") + str(e) self.log.log_end("Search user by status") u'''检索条件:账号或者名称''' def search_user_by_username_006(self): #日志开始记录 self.log.log_start("Search user by username") #获取按照账号或名称检索的数据 user_data = self.get_table_data("search_by_name")#user_check #无检查点的测试项标识,如果为True说明通过 flag = False for dataRow in range(len(user_data)): data = user_data[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: self.frameElem.from_frame_to_otherFrame("mainFrame") row = self.user.search_direct_by_account_or_name(data[3]) self.user.search_accountorname(data[3]) self.user.click_search_button() search_row = self.user.get_rows() #判断测试项是否通过 self.check_without_pop_up(row,search_row,data) self.reset() #清空标识状态 flag = False except Exception as e: print ("search user by username fail: ") + str(e) self.log.log_end("Search user by username") u'''检索条件:部门''' def search_user_by_dep_006(self): #日志开始记录 self.log.log_start("Search user by department") #获取按部门检索的数据 user_data = self.get_table_data("search_by_dep")#user_check #无检查点的测试项标识,如果为True说明通过 flag = False for dataRow in range(len(user_data)): data = user_data[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: self.frameElem.from_frame_to_otherFrame("mainFrame") if dataRow == 1: row = self.user.search_direct_by_dep(data[3]) self.user.set_dep(data[3]) elif dataRow == 2: row = self.user.get_rows() self.user.click_child_node() self.user.set_dep(data[3]) self.user.click_search_button() search_row = self.user.get_rows() #判断测试项是否通过 self.check_without_pop_up(row,search_row,data) self.reset() #清空标识状态 flag = False except Exception as e: print ("search user by department fail: ") + str(e) self.log.log_end("Search user by department") u'''检索条件:角色''' def search_user_by_role_006(self): #日志开始记录 self.log.log_start("SearchUserByRole") #获取按角色检索的数据 user_data = self.get_table_data("search_by_role")#user_check #无检查点的测试项标识,如果为True说明通过 flag = False for dataRow in range(len(user_data)): data = user_data[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: self.frameElem.from_frame_to_otherFrame("mainFrame") row = self.user.search_direct_by_role(data[3]) self.user.search_user_role(data[3]) self.user.click_search_button() search_row = self.user.get_rows() #判断测试项是否通过 self.check_without_pop_up(row,search_row,data) self.reset() #清空标识状态 flag = False except Exception as e: print ("search user by role fail: ") + str(e) self.log.log_end("SearchUserByRole") u'''删除单个用户''' def del_user_007(self): #日志开始记录 self.log.log_start("DelOneUser") #获取删除用户(单个)的数据 user_data = self.get_table_data("del_user")#user_check #无检查点的测试项标识,如果为True说明通过 flag = False for dataRow in range(len(user_data)): data = user_data[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: self.frameElem.from_frame_to_otherFrame("mainFrame") self.user.operate_delete(data[2]) self.cmf.click_login_msg_button() #判断测试项是否通过 self.check_with_pop_up(data,flag) #清空标识状态 flag = False #判断删除的账号是否存在 if not self.cmf.is_namevalue_exsit(data[2],"fortUserAccount"): print ("del user success") except Exception as e: print ("DelOneUser fail: ") + str(e) self.log.log_end("DelOneUser") u'''删除全部用户''' def del_all_user_008(self): #日志开始记录 self.log.log_start("DelAllUser") #获取用户删除的数据 user_data = self.get_table_data("del_all_user")#user_check #无检查点的测试项标识,如果为True说明通过 flag = False for dataRow in range(len(user_data)): data = user_data[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: # self.frameElem.from_frame_to_otherFrame("mainFrame") # self.user.page_select_all() self.frameElem.from_frame_to_otherFrame("mainFrame") self.user.del_specified_user(data[2]) #self.user.select_all_button() self.user.del_button() self.cmf.click_login_msg_button() #判断测试项是否通过 self.check_with_pop_up(data,flag) #清空标识状态 flag = False except Exception as e: print ("del all fail: ") + str(e) self.log.log_end("DelAllUser") #if __name__ == "__main__":#internet explorer # browser = setDriver().set_local_driver() # commonSuite = CommonSuiteData(browser) # userCase = User(browser) # commonSuite.isomper_login() # cmf = commonFun(browser) # # #添加角色 # commonSuite.add_sys_role() ## commonSuite.add_dep_role() # cmf.select_menu(u'运维管理') # cmf.select_menu(u'运维管理','用户') # userCase.add_user_001() # userCase.edit_user_002() # userCase.create_user_cert_003() # userCase.create_user_cert_again_003() # userCase.delete_user_cert_004() # # userCase.checkout_user_005() # userCase.search_user_by_username_006() # userCase.search_user_by_status_006() # userCase.search_user_by_dep_006() # userCase.search_user_by_role_006() # userCase.del_user_007() # userCase.del_all_user_008()
class PasswordStr(): def __init__(self, driver): self.driver = driver self.log = log() self.PwdStr = PwdStrategy(self.driver) self.cmf = commonFun(driver) self.getElem = getElement(driver) self.cnEnde = cnEncode() self.dataFile = dataFileName() self.frameElem = frameElement(self.driver) self.commonsuite = CommonSuiteData(driver) self.user = UserPage(self.driver) self.session = sessionConfig(self.driver) self.conStr = conversationStrategy(driver) self.conuser = User(driver) self.resource = Resource(driver) self.account = Accountmgr(driver) u'''提示框元素路径''' def save_msg(self): save_msg = "html/body/div[1]/div/table/tbody/tr[2]/td[2]/div/table/tbody/tr[2]/td[2]/div" return save_msg u'''获取测试数据 Parameters: sheetname:sheet名称 return:表格数据 ''' def get_table_data(self, sheetname): dataFile = dataFileName() filePath = dataFile.get_password_stratrgy_test_data_url() authFileData = dataFile.get_data(filePath, sheetname) return authFileData u'''切换至会话配置模块''' def switch_to_session_module(self): self.frameElem.switch_to_content() self.frameElem.switch_to_top() self.cmf.select_menu(u"策略配置") self.cmf.select_menu(u"策略配置", u"会话配置") u'''切换至资源模块''' def switch_to_resource_module(self): self.frameElem.switch_to_content() self.frameElem.switch_to_top() self.cmf.select_menu(u"运维管理") self.cmf.select_menu(u"运维管理", u"资源") u'''切换至密码策略''' def switch_to_pwdStr_module(self): self.frameElem.switch_to_content() self.frameElem.switch_to_top() self.cmf.select_menu(u"策略配置") self.cmf.select_menu(u"策略配置", u"密码策略") #添加策略 def add_strategy_001(self): #日志开始记录 self.log.log_start("pwdStrategy") #获取数据 strategy_data = self.get_table_data("add_strategy") #保存弹框 saveMsg = self.save_msg() #无检查点的测试项标识,如果为True说明通过 flag = False for dataRow in range(len(strategy_data)): data = strategy_data[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: self.frameElem.from_frame_to_otherFrame("mainFrame") self.PwdStr.add_pwd_button() self.PwdStr.set_pwd_name(data[2]) self.PwdStr.term_of_validity(data[3]) self.PwdStr.password_length_min(data[4]) self.PwdStr.password_length_max(data[5]) self.PwdStr.set_lower_case(data[6]) self.PwdStr.set_capital(data[7]) self.PwdStr.set_minimum_digital(data[8]) self.PwdStr.set_Minimum_symbol(data[9]) self.PwdStr.set_prohibition_of_using_keywords(data[10]) self.PwdStr.add_using_keywords_button() self.PwdStr.save_button() self.frameElem.switch_to_content() self.cmf.test_win_check_point("xpath", saveMsg, data, flag) self.PwdStr.return_button() except Exception as e: print("Policy adding error: ") + str(e) self.log.log_end("pwdStrategy") #编辑策略test def edit_strategy_002(self): #日志开始记录 self.log.log_start("editPwdStrategy") #获取数据 strategy_data = self.get_table_data("edit_strategy") #保存弹框 saveMsg = self.save_msg() #无检查点的测试项标识,如果为True说明通过 flag = False for dataRow in range(len(strategy_data)): data = strategy_data[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: self.frameElem.from_frame_to_otherFrame("mainFrame") self.PwdStr.edit(data[2]) self.PwdStr.set_pwd_name(data[3]) self.PwdStr.term_of_validity(data[4]) self.PwdStr.password_length_min(data[5]) self.PwdStr.password_length_max(data[6]) self.PwdStr.set_lower_case(data[7]) self.PwdStr.set_capital(data[8]) self.PwdStr.set_minimum_digital(data[9]) self.PwdStr.set_Minimum_symbol(data[10]) self.PwdStr.set_prohibition_of_using_keywords(data[11]) self.PwdStr.add_using_keywords_button() self.PwdStr.save_button() self.frameElem.switch_to_content() self.cmf.test_win_check_point("xpath", saveMsg, data, flag) self.PwdStr.return_button() except Exception as e: print("Policy edit error: ") + str(e) self.log.log_end("editPwdStrategy") #策略校验 def check_strategy_003(self): #日志开始记录 self.log.log_start("checkPwdStrategy") #获取数据 strategy_data = self.get_table_data("check_strategy") #保存弹框 saveMsg = self.save_msg() #无检查点的测试项标识,如果为True说明通过 flag = False for dataRow in range(len(strategy_data)): data = strategy_data[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: self.frameElem.from_frame_to_otherFrame("mainFrame") self.PwdStr.add_pwd_button() self.PwdStr.set_pwd_name(data[2]) self.PwdStr.term_of_validity(data[3]) self.PwdStr.password_length_min(data[4]) self.PwdStr.password_length_max(data[5]) self.PwdStr.set_lower_case(data[6]) self.PwdStr.set_capital(data[7]) self.PwdStr.set_minimum_digital(data[8]) self.PwdStr.set_Minimum_symbol(data[9]) self.PwdStr.set_prohibition_of_using_keywords(data[10]) self.PwdStr.add_using_keywords_button() self.PwdStr.save_button() self.frameElem.switch_to_content() self.cmf.test_win_check_point("xpath", saveMsg, data, flag) self.PwdStr.return_button() except Exception as e: print("Policy checkout error: ") + str(e) self.log.log_end("checkeditPwdStrategy") #检索名称test def search_strategy_004(self): #日志开始记录 self.log.log_start("searchPwdStrategy") #获取数据 strategy_data = self.get_table_data("search_strategy") #无检查点的测试项标识,如果为True说明通过 flag = False for dataRow in range(len(strategy_data)): data = strategy_data[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: self.PwdStr.search_name(data[2]) self.PwdStr.click_search_button() self.PwdStr.click_reset_button() self.PwdStr.click_search_button() #清空标识状态 flag = False self.log.log_detail(data[0], True) except Exception as e: print("Policy search error: ") + str(e) self.log.log_end("searchPwdStrategy") #删除单个策略 def del_sing_policy_005(self): #日志开始记录 self.log.log_start("delPwdStrategy") #获取数据 strategy_data = self.get_table_data("del_strategy") #保存弹框 saveMsg = self.save_msg() #无检查点的测试项标识,如果为True说明通过 flag = False for dataRow in range(len(strategy_data)): data = strategy_data[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: self.frameElem.from_frame_to_otherFrame("mainFrame") self.PwdStr.del_sing_strategy(data[2]) self.frameElem.switch_to_content() self.cmf.click_msg_button(1) self.cmf.test_win_check_point("xpath", saveMsg, data, flag) #校验删除后的名称是否存在 if self.cmf.is_namevalue_exsit(data[2], "fortStrategyPasswordName"): print("Delete success") except Exception as e: print("Policy del error: ") + str(e) self.log.log_end("delPwdStrategy") #与密码策略关联的会话配置 def session_association_007(self): #日志开始记录 self.log.log_start("sessionAssociation") #获取数据 strate_data = self.get_table_data("configure_strateg") #保存弹框 saveMsg = self.save_msg() #无检查点的测试项标识,如果为True说明通过 flag = False for dataRow in range(len(strate_data)): data = strate_data[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: self.switch_to_session_module() self.frameElem.from_frame_to_otherFrame("mainFrame") self.PwdStr.set_pwd_strategy(data[4]) self.session.add_session(data[2]) self.session.add_locking_time(data[3]) self.session.save_global_button() self.frameElem.switch_to_content() self.cmf.test_win_check_point("xpath", saveMsg, data, flag) except Exception as e: print("session association error: ") + str(e) self.log.log_end("sessionAssociation") #与密码策略关联的用户 def user_association_008(self): #日志开始记录 self.log.log_start("userAssociation") #获取数据 strate_data = self.get_table_data("user_association") #保存弹框 saveMsg = self.save_msg() #无检查点的测试项标识,如果为True说明通过 flag = False for dataRow in range(len(strate_data)): data = strate_data[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: self.conuser.switch_to_user_module() self.frameElem.from_frame_to_otherFrame("mainFrame") self.PwdStr.user_edit(data[2]) self.PwdStr.set_pwd(data[9]) self.PwdStr.set_pwd_agin(data[10]) self.user.save_button() self.frameElem.switch_to_content() self.cmf.test_win_check_point("xpath", saveMsg, data, flag) self.user.click_back_button() except Exception as e: print("user association error: ") + str(e) self.log.log_end("userAssociation") #为Windows资源添加密码策略 def resource_association_009(self): #日志开始记录 self.log.log_start("resourAcessociation") #获取数据 strate_data = self.get_table_data("resource_association") #保存弹框 saveMsg = self.save_msg() #无检查点的测试项标识,如果为True说明通过 flag = False for dataRow in range(len(strate_data)): data = strate_data[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: self.commonsuite.sys_switch_to_dep() self.switch_to_resource_module() self.frameElem.from_frame_to_otherFrame("mainFrame") self.PwdStr.resource_edit(data[2]) self.PwdStr.set_resource_strategy(data[8]) self.resource.click_save_button() self.frameElem.switch_to_content() self.cmf.test_win_check_point("xpath", saveMsg, data, flag) self.PwdStr.return_button() except Exception as e: print("resour acessociation error: ") + str(e) self.log.log_end("resourAcessociation") #为Windows资源账号添加密码策略 def resource_account_association_010(self): #日志开始记录 self.log.log_start("resourAceccountAssociation") #获取数据 strate_data = self.get_table_data("resource_account_association") #保存弹框 saveMsg = self.save_msg() #无检查点的测试项标识,如果为True说明通过 flag = False for dataRow in range(len(strate_data)): data = strate_data[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: self.PwdStr.account_manage(data[2]) self.account.click_account_add() self.PwdStr.set_resource_account_name(data[3]) self.PwdStr.set_resource_account_pwd(data[4]) self.PwdStr.set_resource_account_pwdagin(data[5]) self.PwdStr.save_account() self.frameElem.switch_to_content() self.cmf.test_win_check_point("xpath", saveMsg, data, flag) #点击资源账号编辑页面返回 self.PwdStr.return_button() #点击资源账号页面返回 self.PwdStr.return_button() except Exception as e: print("resour aceccount association error: ") + str(e) self.log.log_end("resourAceccountAssociation") #删除全部策略 def del_all_policy_006(self): #日志开始记录 self.log.log_start("delAllPwdStrategy") #获取数据 strategy_data = self.get_table_data("del_all_strategy") #保存弹框 saveMsg = self.save_msg() #无检查点的测试项标识,如果为True说明通过 flag = False for dataRow in range(len(strategy_data)): data = strategy_data[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: self.commonsuite.dep_switch_to_sys() self.switch_to_pwdStr_module() self.frameElem.from_frame_to_otherFrame("mainFrame") self.PwdStr.select_all_button() self.PwdStr.del_button() self.frameElem.switch_to_content() self.cmf.click_msg_button(1) self.cmf.test_win_check_point("xpath", saveMsg, data, flag) #校验删除后的名称是否存在 if self.cmf.is_namevalue_exsit(data[2], "fortStrategyPasswordName"): print("Delete all success") except Exception as e: print("Policy delAll error: ") + str(e) self.log.log_end("delAllPwdStrategy") #if __name__ == "__main__": # browser = setDriver().set_local_driver() # commonSuite = CommonSuiteData(browser) # pwdCase = PasswordStr(browser) # commonSuite.pwdstr_module_prefix_condition() # pwdCase.add_strategy_001() # pwdCase.edit_strategy_002() # pwdCase.check_strategy_003() # pwdCase.search_strategy_004() # pwdCase.del_sing_policy_005() # pwdCase.session_association_007() # pwdCase.user_association_008() # pwdCase.resource_association_009() # pwdCase.resource_account_association_010() # pwdCase.del_all_policy_006() # commonSuite.pwdstr_module_post_condition()
class User(): def __init__(self, driver): self.driver = driver self.log = log() self.user = UserPage(driver) self.cmf = commonFun(driver) self.getElem = getElement(driver) self.cnEnde = cnEncode() self.selectElem = selectElement(driver) self.dataFile = dataFileName() self.frameElem = frameElement(self.driver) self.tableEle = tableElement(self.driver) u'''提示框元素路径''' def user_msg(self): user_msg = "html/body/div[1]/div/table/tbody/tr[2]/td[2]/div/table/tbody/tr[2]/td[2]/div" return user_msg u'''获取测试数据 Parameters: - sheetname:sheet名称 return:表格数据 ''' def get_table_data(self, sheetname): dataFile = dataFileName() filePath = dataFile.get_person_test_data_url() authFileData = dataFile.get_data(filePath, sheetname) return authFileData u'''校验有弹出框类型用例是否通过 parameters: data : 检查点 flag : 通过标识(True or False) ''' def check_with_pop_up(self, data, flag): #点击保存按钮弹出框 user_msg = self.user_msg() self.frameElem.switch_to_content() self.cmf.test_win_check_point("xpath", user_msg, data, flag) u'''校验没有弹出框类型用例是否通过 parameters: data : 检查点 flag : 通过标识(True lse) status : 0,代表判断条件为相等 ''' def check_without_pop_up(self, var1, var2, data): #点击保存按钮弹出框 user_msg = self.user_msg() if var1 == var2: self.cmf.test_win_check_point("", "", data, True) else: self.cmf.test_win_check_point("", "", data, False) u'''重置''' def reset(self): self.user.click_reset_button() self.user.click_search_button() u'''切换至用户模块''' def switch_to_user_module(self): self.frameElem.switch_to_content() self.frameElem.switch_to_top() self.cmf.select_menu(u"运维管理") self.cmf.select_menu(u"运维管理", u"用户") u'''添加用户''' def add_user_001(self): #日志开始记录 self.log.log_start("addUser") #获取添加用户的数据 user_data = self.get_table_data("add_user") #无检查点的测试项标识,如果为True说明通过 flag = False for dataRow in range(len(user_data)): data = user_data[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: self.frameElem.from_frame_to_otherFrame("mainFrame") self.user.add_button() self.user.set_user_account(data[2]) self.user.set_user_name(data[3]) if data[6] != "": self.user.set_dep(data[6]) self.user.set_user_pwd(data[7]) self.user.set_user_enquire_pwd(data[8]) self.user.set_user_role(data[15]) self.user.click_role_add_button() self.user.save_button() #判断测试项是否通过 self.check_with_pop_up(data, flag) #清空标识状态 flag = False # self.switch_to_user_module() # self.cmf.back() self.user.click_back_button() if self.cmf.is_namevalue_exsit(data[2], "fortUserAccount"): print("add user success") except Exception as e: print("user add fail: ") + str(e) self.log.log_end("addUser") u'''编辑用户''' def edit_user_002(self): #日志开始记录 self.log.log_start("editUser") #获取编辑用户的数据 user_data = self.get_table_data("mod_user") #无检查点的测试项标识,如果为True说明通过 flag = False for dataRow in range(len(user_data)): data = user_data[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: self.frameElem.from_frame_to_otherFrame("mainFrame") self.user.operate_edit(data[2]) self.user.set_user_account(data[3]) self.user.set_user_name(data[4]) self.user.set_user_status(data[8]) self.user.set_user_pwd(data[9]) self.user.set_user_enquire_pwd(data[10]) self.user.save_button() #判断测试项是否通过 self.check_with_pop_up(data, flag) #清空标识状态 flag = False self.switch_to_user_module() # self.cmf.back() # self.user.click_back_button() if self.cmf.is_namevalue_exsit(data[2], "fortUserAccount"): print("edit user success") except Exception as e: print("edit user fail: ") + str(e) self.log.log_end("editUser") u'''生成证书''' def create_user_cert_003(self): #日志开始记录 self.log.log_start("CreateUserCert") #获取生成证书用户的数据 user_data = self.get_table_data("create_cert") #无检查点的测试项标识,如果为True说明通过 flag = False for dataRow in range(len(user_data)): data = user_data[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: self.frameElem.from_frame_to_otherFrame("mainFrame") self.user.operate_cert(data[3]) self.user.create_cert() cert_name = self.user.get_cert() #判断生成的证书名字和指定的名字是否相等 self.check_without_pop_up(cert_name, data[2], data) #清空标识状态 flag = False self.switch_to_user_module() # self.cmf.back() except Exception as e: print("Create user cert fail: ") + str(e) self.log.log_end("CreateUserCert") u'''重新生成证书''' def create_user_cert_again_003(self): #点击保存按钮弹出框 user_msg = self.user_msg() #日志开始记录 self.log.log_start("ReCreateUserCert") #获取重新生成证书的数据 user_data = self.get_table_data("reCreate_cert") #无检查点的测试项标识,如果为True说明通过 flag = False for dataRow in range(len(user_data)): data = user_data[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: self.frameElem.from_frame_to_otherFrame("mainFrame") self.user.operate_cert(data[2]) cert_num_old = self.user.get_cert_serial_num() self.user.create_cert() self.cmf.click_login_msg_button() self.frameElem.from_frame_to_otherFrame("mainFrame") cert_num_new = self.user.get_cert_serial_num() if cert_num_old != cert_num_new: self.cmf.test_win_check_point("", "", data, True) else: self.cmf.test_win_check_point("", "", data, False) #清空标识状态 flag = False self.switch_to_user_module() # self.cmf.back() except Exception as e: print("ReCreate user cert fail: ") + str(e) self.log.log_end("ReCreateUserCert") u'''删除证书''' def delete_user_cert_004(self): #日志开始记录 self.log.log_start("DeleteUserCert") #获取删除证书的数据 user_data = self.get_table_data("delete_cert") #无检查点的测试项标识,如果为True说明通过 flag = False for dataRow in range(len(user_data)): data = user_data[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: self.frameElem.from_frame_to_otherFrame("mainFrame") self.user.operate_cert(data[3]) self.user.delete_cert() #判断测试项是否通过 self.check_with_pop_up(data, flag) self.frameElem.from_frame_to_otherFrame("mainFrame") if self.user.get_init_cert_name() == data[2]: print("Delete cert success!") #清空标识状态 flag = False self.frameElem.from_frame_to_otherFrame("mainFrame") # self.switch_to_user_module() self.cmf.back() except Exception as e: print("Delete user cert fail: ") + str(e) self.log.log_end("DeleteUserCert") u'''校验用户''' def checkout_user_005(self): #保存成功的弹出框 user_msg = self.user_msg() #日志开始记录 self.log.log_start("checkoutUser") #获取用户校验的数据 user_data = self.get_table_data("user_check") #user_check #无检查点的测试项标识,如果为True说明通过 self.frameElem.from_frame_to_otherFrame("mainFrame") self.user.add_button() flag = False for dataRow in range(len(user_data)): data = user_data[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: self.frameElem.from_frame_to_otherFrame("mainFrame") self.user.set_user_account(data[2]) self.user.set_user_name(data[3]) if dataRow == range(len(user_data))[-1]: self.user.clear_dep() self.user.set_user_pwd(data[7]) self.user.set_user_enquire_pwd(data[8]) self.user.set_user_mobile(data[9]) self.user.set_user_phone(data[10]) self.user.set_user_email(data[11]) self.user.save_button() #判断测试项是否通过 self.check_with_pop_up(data, flag) #清空标识状态 flag = False except Exception as e: print("checkoutUser fail: ") + str(e) self.switch_to_user_module() self.log.log_end("checkoutUser") u'''检索条件:用户状态''' def search_user_by_status_006(self): #日志开始记录 self.log.log_start("Search user by status") #获取按照用户状态检索的数据 user_data = self.get_table_data("search_by_status") #user_check #无检查点的测试项标识,如果为True说明通过 flag = False for dataRow in range(len(user_data)): data = user_data[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: self.frameElem.from_frame_to_otherFrame("mainFrame") row = self.user.search_by_status(data[3]) self.user.search_by_user_status(data[2]) self.user.click_search_button() search_row = self.user.get_rows() #判断测试项是否通过 self.check_without_pop_up(row, search_row, data) self.reset() #清空标识状态 flag = False except Exception as e: print("search user by status fail: ") + str(e) self.log.log_end("Search user by status") u'''检索条件:账号或者名称''' def search_user_by_username_006(self): #日志开始记录 self.log.log_start("Search user by username") #获取按照账号或名称检索的数据 user_data = self.get_table_data("search_by_name") #user_check #无检查点的测试项标识,如果为True说明通过 flag = False for dataRow in range(len(user_data)): data = user_data[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: self.frameElem.from_frame_to_otherFrame("mainFrame") row = self.user.search_direct_by_account_or_name(data[3]) self.user.search_accountorname(data[3]) self.user.click_search_button() search_row = self.user.get_rows() #判断测试项是否通过 self.check_without_pop_up(row, search_row, data) self.reset() #清空标识状态 flag = False except Exception as e: print("search user by username fail: ") + str(e) self.log.log_end("Search user by username") u'''检索条件:部门''' def search_user_by_dep_006(self): #日志开始记录 self.log.log_start("Search user by department") #获取按部门检索的数据 user_data = self.get_table_data("search_by_dep") #user_check #无检查点的测试项标识,如果为True说明通过 flag = False for dataRow in range(len(user_data)): data = user_data[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: self.frameElem.from_frame_to_otherFrame("mainFrame") if dataRow == 1: row = self.user.search_direct_by_dep(data[3]) self.user.set_dep(data[3]) elif dataRow == 2: row = self.user.get_rows() self.user.click_child_node() self.user.set_dep(data[3]) self.user.click_search_button() search_row = self.user.get_rows() #判断测试项是否通过 self.check_without_pop_up(row, search_row, data) self.reset() #清空标识状态 flag = False except Exception as e: print("search user by department fail: ") + str(e) self.log.log_end("Search user by department") u'''检索条件:角色''' def search_user_by_role_006(self): #日志开始记录 self.log.log_start("SearchUserByRole") #获取按角色检索的数据 user_data = self.get_table_data("search_by_role") #user_check #无检查点的测试项标识,如果为True说明通过 flag = False for dataRow in range(len(user_data)): data = user_data[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: self.frameElem.from_frame_to_otherFrame("mainFrame") row = self.user.search_direct_by_role(data[3]) self.user.search_user_role(data[3]) self.user.click_search_button() search_row = self.user.get_rows() #判断测试项是否通过 self.check_without_pop_up(row, search_row, data) self.reset() #清空标识状态 flag = False except Exception as e: print("search user by role fail: ") + str(e) self.log.log_end("SearchUserByRole") u'''删除单个用户''' def del_user_007(self): #日志开始记录 self.log.log_start("DelOneUser") #获取删除用户(单个)的数据 user_data = self.get_table_data("del_user") #user_check #无检查点的测试项标识,如果为True说明通过 flag = False for dataRow in range(len(user_data)): data = user_data[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: self.frameElem.from_frame_to_otherFrame("mainFrame") self.user.operate_delete(data[2]) self.cmf.click_login_msg_button() #判断测试项是否通过 self.check_with_pop_up(data, flag) #清空标识状态 flag = False except Exception as e: print("DelOneUser fail: ") + str(e) self.log.log_end("DelOneUser") u'''删除全部用户''' def del_all_user_008(self): #日志开始记录 self.log.log_start("DelAllUser") #获取用户删除的数据 user_data = self.get_table_data("del_all_user") #user_check #无检查点的测试项标识,如果为True说明通过 flag = False for dataRow in range(len(user_data)): data = user_data[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: # self.frameElem.from_frame_to_otherFrame("mainFrame") # self.user.page_select_all() self.frameElem.from_frame_to_otherFrame("mainFrame") self.user.del_specified_user(data[2]) #self.user.select_all_button() self.user.del_button() self.cmf.click_login_msg_button() #判断测试项是否通过 self.check_with_pop_up(data, flag) #清空标识状态 flag = False except Exception as e: print("del all fail: ") + str(e) self.log.log_end("DelAllUser") #if __name__ == "__main__":#internet explorer # browser = setDriver().set_local_driver() # commonSuite = CommonSuiteData(browser) # userCase = User(browser) # commonSuite.isomper_login() # cmf = commonFun(browser) # # #添加角色 # commonSuite.add_sys_role() ## commonSuite.add_dep_role() # cmf.select_menu(u'运维管理') # cmf.select_menu(u'运维管理','用户') # userCase.add_user_001() # userCase.edit_user_002() # userCase.create_user_cert_003() # userCase.create_user_cert_again_003() # userCase.delete_user_cert_004() # # userCase.checkout_user_005() # userCase.search_user_by_username_006() # userCase.search_user_by_status_006() # userCase.search_user_by_dep_006() # userCase.search_user_by_role_006() # userCase.del_user_007() # userCase.del_all_user_008()
class TimeRule(object): def __init__(self, driver): self.driver = driver self.getElem = getElement(driver) self.selectElem = selectElement(driver) self.frameElem = frameElement(driver) self.tableElem = tableElement(driver) self.cmf = commonFun(driver) self.cnEn = cnEncode() self.acproval = Accapproval(driver) self.user = UserPage(driver) u'''点击批量删除''' def click_bulkdel_time(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_click_EC("id", "delete_rule_time") u'''填写时间规则名称 Parameters: - rulename:时间规则名称 ''' def set_rulename(self, rulename): name = self.cnEn.is_float(rulename) self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_clear("id", "fortRuleTimeName") self.getElem.find_element_wait_and_sendkeys("id", "fortRuleTimeName", name) u'''选择部门 Parameters: - deptname:部门名称 ''' def select_depart(self, deptname): name = self.cnEn.is_float(deptname) self.select_depart_right_common("department_name", "tree_1_switch", name) time.sleep(2) u'''启动日期 Parameters: - type:t代表今天,c代表clear,q代表确定,默认选择今天 - starttime:启动日期 ''' def start_date(self, types, starttime=None): time.sleep(2) self.frameElem.from_frame_to_otherFrame("rigthFrame") # 时间控件的fram的xpath # fxpath = "//iframe[@hidefocus='true']" fxpath = "/html/body/div/iframe" # 日期控件table的xpath路径 txpath = "/html/body/div/div[3]/table" status = self.cnEn.is_float('0') type = self.cnEn.is_float(types) if starttime != None: # 转成datetime对象 date = datetime(*xldate_as_tuple(starttime, 0)) start = date.strftime('%Y-%m-%d %H:%M:%S') self.option_time_rule("fortStartTime", fxpath, status, type, txpath, start) else: self.option_time_rule("fortStartTime", fxpath, status, type, txpath) u'''结束日期 Parameters: - type:t代表今天,c代表clear,q代表确定,默认选择今天 - endtime:结束日期设定的日期,格式为2016-9-7 11:42:42 ''' def date_of_termination(self, types, endtime): self.frameElem.from_frame_to_otherFrame("rigthFrame") # 时间控件的fram的xpath fxpath = "//iframe[@hidefocus='true']" # 日期控件table的xpath路径 txpath = "/html/body/div/div[3]/table" status = self.cnEn.is_float('0') type = self.cnEn.is_float(types) # 转成datetime对象 date = datetime(*xldate_as_tuple(endtime, 0)) end = date.strftime('%Y-%m-%d %H:%M:%S') self.option_time_rule("fortEndTime", fxpath, status, type, txpath, end) u'''设置状态类型 Parameters: - status: 状态类型0代表禁止使用,1代表允许使用 ''' def set_status_type(self, status): self.frameElem.from_frame_to_otherFrame("rigthFrame") statu = self.cnEn.is_float(status) selem = self.getElem.find_element_with_wait_EC("id", "fortAccessType") self.selectElem.select_element_by_value(selem, statu) u'''设置时间 Parameters: - method: 设置方式 option的value值 - weeks: 星期(可多选)option的value值 - hours: 小时(可多选) ''' def set_time(self, methods, weeks, hours='no'): self.frameElem.from_frame_to_otherFrame("rigthFrame") #设置时间方式 method = self.cnEn.is_float(methods) selem = self.getElem.find_element_with_wait_EC("id", "method") self.selectElem.select_element_by_value(selem, method) #设置日期 week = weeks.split() if methods == "weeks": for data in week: welem = self.getElem.find_element_with_wait_EC("id", "fortWeeks") self.selectElem.select_element_by_value(welem, data) elif methods == "days": for data in week: welem = self.getElem.find_element_with_wait_EC("id", "fortDays") self.selectElem.select_element_by_value(welem, data) if hours != 'no': #设置小时 hour = hours.split() for hr in hour: helem = self.getElem.find_element_with_wait_EC("id", "fortHours") self.selectElem.select_element_by_value(helem, hr) u'''取消时间 Parameters: - method: 设置方式 option的value值 - weeks: 星期(可多选)option的value值 - hours: 小时(可多选) ''' def deselect_time(self, methods, weeks, hours='no'): self.frameElem.from_frame_to_otherFrame("rigthFrame") #设置日期 week = weeks.split() if methods == "weeks": for data in week: welem = self.getElem.find_element_with_wait_EC("id", "fortWeeks") self.selectElem.deselect_element_by_value(welem, data) elif methods == "days": for data in week: welem = self.getElem.find_element_with_wait_EC("id", "fortDays") self.selectElem.deselect_element_by_value(welem, data) if hours != 'no': #设置小时 hour = hours.split() for hr in hour: helem = self.getElem.find_element_with_wait_EC("id", "fortHours") self.selectElem.deselect_element_by_value(helem, hr) u'''填写描述信息 Parameters: - descrip:描述信息 ''' def set_descrip(self, descrip): self.frameElem.from_frame_to_otherFrame("rigthFrame") description = self.cnEn.is_float(descrip) self.getElem.find_element_wait_and_clear("id", "fortDescription") self.getElem.find_element_wait_and_sendkeys("id", "fortDescription", description) u'''点击保存按钮''' def click_save_time(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_click_EC("id", "save_rule_time") u'''填写检索名称 Parameters: - timename:名称 ''' def set_search_timename(self, timename): self.frameElem.from_frame_to_otherFrame("rigthFrame") name = self.cnEn.is_float(timename) self.getElem.find_element_wait_and_clear("id", "fortRuleTimeName") self.getElem.find_element_wait_and_sendkeys("id", "fortRuleTimeName", name) u'''点击检索按钮''' def click_search_time(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_click_EC("id", "retFortRuleTimeName") u'''点击重置''' def click_reset_time(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_click_EC("id", "resetting") u'''点击编辑按钮 Parameters: - timename:时间规则名称 ''' def click_edit_time(self, timename): try: self.frameElem.from_frame_to_otherFrame("rigthFrame") row = self.acproval.find_name_by_row(timename, "fortRuleTimeName") update_xpath = "/html/body/div/div[6]/div[2]/div/table/tbody/tr[" + str(row) + "]/td[6]/input[1]" self.getElem.find_element_wait_and_click("xpath", update_xpath) except Exception: print("Click the Edit button to fail") u'''点击删除按钮 Parameters: - timename:时间规则名称 ''' def click_del_time(self, timename): try: self.frameElem.from_frame_to_otherFrame("rigthFrame") row = self.acproval.find_name_by_row(timename, "fortRuleTimeName") del_xpath = "/html/body/div/div[6]/div[2]/div/table/tbody/tr[" + str(row) + "]/td[6]/input[2]" self.getElem.find_element_wait_and_click("xpath", del_xpath) except Exception: print("Click the Del button to fail") u'''选择部门公共方法 parameter: - idname:填写框id - swithid:部门展开按钮id - deptname:部门名称 ''' def select_depart_right_common(self, idname, swithid, deptname): try: time.sleep(2) self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_click_EC('id', idname) time.sleep(2) self.getElem.find_element_wait_and_click_EC('id', swithid) #获取所有a标签的对象 elems = self.driver.find_elements_by_tag_name("a") for elem in elems: elemtext = elem.get_attribute("title") elemid = elem.get_attribute("id") if deptname == elemtext: self.getElem.find_element_wait_and_click("id", elemid) break except Exception as e: print "Department select error:" + str(e) u'''操作时间控件 Parameters: - wdateId:日期控件input控件的ID值 - fxpath:日期控件frame的xpath路径 - status: 日期控件是否有时分秒 - txpath:日期控件table的xpath路径 - time:设定的日期,格式为2016-9-7 11:42:42 - type:t代表今天,c代表clear,q代表确定,默认选择今天 ''' def option_time_rule(self,wdateId,fxpath,status='0',type='t',txpath = None,dtime = None): self.getElem.find_element_wait_and_click("id",wdateId) frame = self.driver.find_element_by_xpath(fxpath) self.driver.switch_to_frame(frame) if type == 't': self.getElem.find_element_wait_and_click("id","dpTodayInput") elif type == 'c': self.getElem.find_element_wait_and_click("id","dpClearInput") elif type == 'q': if dtime is not None: list = dtime.split() ymdList = list[0].split("-") hmsList = list[1].split(":") #年 tYear = ymdList[0] #月 tMon = ymdList[1] #日 tDay = ymdList[2] #时 tHour = hmsList[0] #分 tMin = hmsList[1] #秒 tSen = hmsList[2] dTitle = self.getElem.find_element_with_wait("id","dpTitle").find_elements_by_tag_name("input") #设定月 dTitle[0].clear() dTitle[0].send_keys(tMon) #设定年 dTitle[1].clear() dTitle[1].send_keys(tYear) time.sleep(2) self.frameElem.from_frame_to_otherFrame("rigthFrame") if wdateId == "fortStartTime": self.getElem.find_element_wait_and_click_EC("id", "fortStartTime") elif wdateId == "fortEndTime": self.getElem.find_element_wait_and_click_EC("id", "fortEndTime") self.driver.switch_to_frame(frame) if txpath is not None: iStatus = False for itr in range(7): if itr != 0: for itd in range(7): ct = self.tableElem.get_table_cell_text(txpath,itr,itd)[0] #排除第一行大于7的 if itr == 1 and int(ct) > 7: continue #排除倒数第二行小于15的 if itr == 5 and int(ct) < 15: continue #排除最后一行小于15的 if itr == 6 and int(ct) < 15: continue #如果跟给定的日期一致,点击日期 if int(ct) == int(tDay): self.tableElem.get_table_cell_text(txpath,itr,itd)[1].click() iStatus = True break #找到日期后跳出循环 if iStatus: break #日期控件是否有时分秒 if status == '1': dTime = self.getElem.find_element_with_wait("id","dpTime").find_elements_by_tag_name("input") #设定小时 dTime[0].clear() dTime[0].send_keys(tHour) #设定分钟 dTime[2].clear() dTime[2].send_keys(tMin) #设定秒 dTime[4].clear() dTime[4].send_keys(tSen) self.getElem.find_element_wait_and_click("id","dpOkInput") u'''给用户添加时间规则 Parameters: - username:要编辑的用户名称 - timerule:时间规则test值 ''' def edit_user_time_rule(self, username, timerule): self.frameElem.from_frame_to_otherFrame("mainFrame") name = self.cnEn.is_float(username) self.user.operate_edit(name) self.user.click_advanced_option() self.select_time_rule(timerule) self.user.save_button() self.cmf.click_login_msg_button() self.user.click_back_button() u'''选择时间规则 Parameters: - timerule:时间规则test值 ''' def select_time_rule(self, timerule): self.frameElem.from_frame_to_otherFrame("mainFrame") timer = self.cnEn.is_float(timerule) select_elem = self.getElem.find_element_with_wait_EC('id',"fortRuleTimeId") self.selectElem.select_element_by_visible_text(select_elem, timer)
class AlarmPage(): u'''高危运维''' #高危运维默认告警级别 COMMON_ALARM_LEVEL = "commandAlarmLevel" #勾选syslog SYSLOG_CHECK = "alarmTypeSyslogCheck" #勾选邮件 MAIL_CHECK = "alarmTypeMailCheck" #选择邮件接收人添加按钮 COMMAND_RECEIVE_USER = "******" u'''运行状态告警''' #内存百分比 MEM_SELECT = "memoryAlarmSelect" #硬盘百分比 DISK_SELECT = "diskAlarmSelect" #CPU百分比 CPU_SELECT = "cpuAlarmSelect" #运行状态告警默认告警级别 DEF_ALR_LEVEL_SELECT = "defaultAlarmLevelSelect" #勾选syslog RUN_SYSLOG_CHECK = "runStateAlarmTypeSyslogCheck" #勾选邮件 RUN_MAIL_CHECK = "runStateAlarmTypeMailCheck" #选择邮件接收人添加按钮 SYSTEM_STATE_RECEIVE_USER = "******" #周期检测 TEST_SELECT = "testCycleSelect" #事件是否升级开关 SWTICH_BUTTON = "btn_sj" #重复发生事件次数 TIME_SELECT = "repeatTimesSelect" #事件升级告警级别 DEF_UPDATE_SELECT = "defaultAlarmUpdateSelect" u'''认证异常''' #默认告警级别 AUTH_ALARM_LEVEL = "authAlarmLevel" #勾选syslog AUTH_SYSLOG_CHECK = "authAlarmTypeSyslogCheck" #勾选邮件 AUTH_MAIL_CHECK = "authAlarmTypeMailCheck" #选择邮件接收人添加按钮 AUTH_EXCEPTIN_RECEIVE_USER = "******" u'''告警归纳''' #类型检索 FORT_SYSTEM_ALARM_TYPEID = "fortSystemAlarmTypeId" #等级检索 FORT_ALARM_LEVEL = "fortAlarmLevel" #检索按钮 SEARCH_BUTTON = "js_btn" #重置按钮 REST_BUTTON = "resetting" #保存按钮 SAVE_BUTTON = "saveAlarmConfig" #选择邮件接收人检索按钮 RECEIVE_USER_BUTTON = "quick_user" #选择邮件接收页面确定按钮 OK_BUTTON = "okButton" #选择邮件接收页面返回按钮 RETURN_BUTTON = "cancelButton" #勾全选 CHECK_ALL_BUTTON = "user_check_all" #填写邮箱 USER_MAIL = "fortUserEmail" #个人信息维护 MESSAGE = "message" def __init__(self, driver): self.driver = driver self.log = log() self.cmf = commonFun(driver) self.getElem = getElement(driver) self.cnEnde = cnEncode() self.tableElem = tableElement(self.driver) self.selectElem = selectElement(driver) self.dataFile = dataFileName() self.frameElem = frameElement(self.driver) self.user = UserPage(driver) u'''点击保存按钮''' def save_button(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") try: self.getElem.find_element_with_wait_clickable_and_click( 'id', self.SAVE_BUTTON) except Exception as e: print("Save policy error: ") + str(e) u'''点击添加邮件接收人公用方法 parameters : type : 定位方式 value : 值 ''' def click_button_common(self, type, value): var_button = self.getElem.find_element_with_wait_EC(type, value) if var_button.is_displayed(): var_button.click() u'''选择邮件接收人检索按钮''' def click_receive_user(self): try: self.click_button_common('id', self.RECEIVE_USER_BUTTON) except Exception as e: print("Select the mail recipient error : ") + str(e) u'''点击确定按钮''' def ok_button(self): self.frameElem.switch_to_content() try: self.getElem.find_element_wait_and_click_EC('id', self.OK_BUTTON) except Exception as e: print("Determine error: ") + str(e) u'''点击返回按钮''' def return_button(self): try: self.getElem.find_element_with_wait_clickable_and_click( 'id', self.RETURN_BUTTON) except Exception as e: print("return error: ") + str(e) u'''勾选全选按钮''' def check_all_button(self): try: self.click_button_common('id', self.CHECK_ALL_BUTTON) except Exception as e: print("Click checkall button error: ") + str(e) u'''左边框点击告警配置''' def click_left_config_test(self): self.frameElem.from_frame_to_otherFrame("leftFrame") self.getElem.find_element_wait_and_click_EC("id", "url1") u'''左边框点击告警归纳''' def click_left_Induce_test(self): self.frameElem.from_frame_to_otherFrame("leftFrame") self.getElem.find_element_wait_and_click_EC("id", "url0") u'''填写变量内容 parameters: var_text : 变量内容 value : 定位方式值 ''' def set_common_func(self, var_text, value): self.frameElem.from_frame_to_otherFrame("rigthFrame") try: revar_text = self.cnEnde.is_float(var_text) var_elem = self.getElem.find_element_with_wait_EC('id', value) var_elem.clear() var_elem.send_keys(revar_text) except Exception as e: print("set common text error: ") + str(revar_text) + str(e) #取消高危运维syslog,邮件配置 def del_command_config(self): try: self.frameElem.from_frame_to_otherFrame("mainFrame") self.click_left_config_test() self.click_command_alarm_menu() self.syslog_check() self.mail_check() self.save_button() self.frameElem.switch_to_content() self.cmf.click_msg_button(1) except Exception as e: print("del command config: ") + str(e) #取消运行状态告警syslog,邮件配置 def del_default_config(self): try: self.frameElem.from_frame_to_otherFrame("mainFrame") self.click_left_config_test() self.click_default_alarm_menu() self.run_syslog_check() self.run_mail_check() self.change_switch_status() self.save_button() self.frameElem.switch_to_content() self.cmf.click_msg_button(1) except Exception as e: print("del default config: ") + str(e) #取消认证异常syslog,邮件配置 def del_auth_config(self): try: self.frameElem.from_frame_to_otherFrame("mainFrame") self.click_left_config_test() self.auth_default_alarm_menu() self.auth_syslog_check() self.auth_mail_check() self.save_button() self.frameElem.switch_to_content() self.cmf.click_msg_button(1) except Exception as e: print("del auth config: ") + str(e) #取消绕行告警syslog,邮件配置 def del_ip_config(self): try: self.frameElem.from_frame_to_otherFrame("mainFrame") self.click_left_config_test() self.ip_default_alarm_menu() self.ip_syslog_check() self.ip_mail_check() self.del_ip_select() self.save_button() self.frameElem.switch_to_content() self.cmf.click_msg_button(1) except Exception as e: print("del ip config: ") + str(e) #---------------------------------高危运维-------------------------------------------------- #点击高危运维模块 def click_command_alarm_menu(self): try: self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_with_wait_clickable_and_click( 'link', "高危运维") except Exception as e: print("commmand alarm menu error: ") + str(e) u'''高危运维默认告警级别 parameter: commandValue : 告警级别option的value值(5代表等级:5) ''' def command_alarm_level(self, commandValue): return self.user.set_common_select_elem(commandValue, self.COMMON_ALARM_LEVEL) u'''勾选syslog按钮''' def syslog_check(self): try: self.getElem.find_element_with_wait_clickable_and_click( 'id', self.SYSLOG_CHECK) except Exception as e: print("Check syslog error: ") + str(e) u'''勾选mail按钮''' def mail_check(self): try: time.sleep(2) self.getElem.find_element_with_wait_clickable_and_click( 'id', self.MAIL_CHECK) time.sleep(2) except Exception as e: print("mail mail error: ") + str(e) u'''点击邮件添加按钮''' def click_illegal_command_receive_user(self): try: time.sleep(2) self.getElem.find_element_with_wait_clickable_and_click( 'id', self.COMMAND_RECEIVE_USER) except Exception as e: print("click mail recipient error: ") + str(e) #---------------------------------运维状态告警-------------------------------------------------- #点击运行状态告警模块 def click_default_alarm_menu(self): try: self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_with_wait_clickable_and_click( 'link', "运行状态告警") except Exception as e: print("default alarm menu error: ") + str(e) u'''内存设置百分比 parameter: memoryValue : mem百分比option的value值(5代表50%) ''' def memory_alarm_select(self, memoryValue): time.sleep(2) return self.user.set_common_select_elem(memoryValue, self.MEM_SELECT) u'''磁盘设置百分比 parameter: diskValue : disk百分比option的value值(5代表50%) ''' def disk_alarm_select(self, diskValue): time.sleep(1) return self.user.set_common_select_elem(diskValue, self.DISK_SELECT) u'''cpu设置百分比 parameter: cpuValue : cpu百分比option的value值(5代表50%) ''' def cpu_alarm_select(self, cpuValue): time.sleep(1) return self.user.set_common_select_elem(cpuValue, self.CPU_SELECT) u'''检测周期 parameter: testValue : 检测周期option的value值(5代表5秒) ''' def test_cycle_select(self, testValue): time.sleep(2) return self.user.set_common_select_elem(testValue, self.TEST_SELECT) u'''默认告警级别 parameter: defaultValue : 默认告警级别option的value值(5代表级别5) ''' def default_alarm_level_select(self, defaultValue): time.sleep(2) return self.user.set_common_select_elem(defaultValue, self.DEF_ALR_LEVEL_SELECT) u'''勾选syslog按钮''' def run_syslog_check(self): try: time.sleep(2) self.getElem.find_element_with_wait_clickable_and_click( 'id', self.RUN_SYSLOG_CHECK) except Exception as e: print("Check syslog run error: ") + str(e) u'''勾选mail按钮''' def run_mail_check(self): try: time.sleep(2) self.getElem.find_element_with_wait_clickable_and_click( 'id', self.RUN_MAIL_CHECK) except Exception as e: print("Check mail run error: ") + str(e) u'''选择邮件接收人添加按钮''' def system_state_receive_user(self): try: time.sleep(2) self.getElem.find_element_with_wait_clickable_and_click( 'id', self.SYSTEM_STATE_RECEIVE_USER) except Exception as e: print("Select the system mail recipient error: ") + str(e) u'''改变开关状态''' def change_switch_status(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") try: button_elem = self.getElem.find_element_with_wait_EC( "id", self.SWTICH_BUTTON) class_attr = button_elem.get_attribute("class") off_status = "switch_off" on_status = "switch_on" if class_attr == on_status: self.click_default_alarm_menu() self.frameElem.from_frame_to_otherFrame("rigthFrame") button_elem = self.getElem.find_element_with_wait_EC( "id", self.SWTICH_BUTTON) button_elem.click() button_elem.click() else: button_elem.click() except Exception as e: print("Change button status error: ") + str(e) u'''重复事件 parameter: repeatValue : 重复事件option的value值(10代表10次) ''' def repeat_times_select(self, repeatValue): time.sleep(2) return self.user.set_common_select_elem(repeatValue, self.TIME_SELECT) u'''升级事件告警级别 parameter: updateValue : 升级告警级别option的value值(6代表等级6) ''' def defaultA_alarm_update_elect(self, updateValue): time.sleep(2) return self.user.set_common_select_elem(updateValue, self.DEF_UPDATE_SELECT) #---------------------------------认证异常-------------------------------------------------- #点击认证异常模块 def auth_default_alarm_menu(self): try: self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_with_wait_clickable_and_click( 'link', "认证异常") except Exception as e: print("auth alarm menu error: ") + str(e) u'''默认告警级别 parameter: authValue : 告警级别option的value值(5代表等级:5) ''' def auth_alarm_level(self, authValue): return self.user.set_common_select_elem(authValue, self.AUTH_ALARM_LEVEL) u'''勾选syslog按钮''' def auth_syslog_check(self): try: self.getElem.find_element_with_wait_clickable_and_click( 'id', self.AUTH_SYSLOG_CHECK) except Exception as e: print("Check auth syslog error: ") + str(e) u'''勾选mail按钮''' def auth_mail_check(self): try: self.getElem.find_element_with_wait_clickable_and_click( 'id', self.AUTH_MAIL_CHECK) except Exception as e: print("mail auth mail error: ") + str(e) u'''选择邮件接收人添加按钮''' def auth_exception_receive_user(self): try: self.getElem.find_element_with_wait_clickable_and_click( 'id', self.AUTH_EXCEPTIN_RECEIVE_USER) except Exception as e: print("Select the auth mail recipient error: ") + str(e) #---------------------------------告警归纳-------------------------------------------------- u'''点击检索按钮''' def search_button(self): try: self.getElem.find_element_with_wait_clickable_and_click( 'classname', self.SEARCH_BUTTON) time.sleep(1) except Exception as e: print("Retrieval strategy error: ") + str(e) u'''点击重置按钮''' def rest_button(self): try: self.getElem.find_element_with_wait_clickable_and_click( 'id', self.REST_BUTTON) except Exception as e: print("reset error: ") + str(e) u'''类型检索 parameter: text : 告警类型检索的text值 ''' def search_type(self, text): try: searchtext = self.cnEnde.is_float(text) search_type = self.getElem.find_element_with_wait_EC( 'id', self.FORT_SYSTEM_ALARM_TYPEID) self.selectElem.select_element_by_visible_text( search_type, searchtext) except Exception as e: print("search type select error:") + str(e) u'''级别检索 parameter: text : 告警级别检索的text值 ''' def search_level(self, text): try: searchtext = self.cnEnde.is_float(text) search_level = self.getElem.find_element_with_wait_EC( 'id', self.FORT_ALARM_LEVEL) self.selectElem.select_element_by_visible_text( search_level, searchtext) except Exception as e: print("search level select error:") + str(e) #---------------------------------填写邮箱-------------------------------------------------- #点击个人维护 def click_user_message_menu(self): self.frameElem.from_frame_to_otherFrame("topFrame") try: self.getElem.find_element_with_wait_clickable_and_click( 'id', self.MESSAGE) except Exception as e: print("click user message menu error: ") + str(e) #填写邮箱 def set_user_mail(self, usermail): return self.user.set_common_func(usermail, self.USER_MAIL) #点击保存 def click_save_button(self): return self.user.save_button()
class AlarmPage(): u'''高危运维''' #高危运维默认告警级别 COMMON_ALARM_LEVEL = "commandAlarmLevel" #勾选syslog SYSLOG_CHECK = "alarmTypeSyslogCheck" #勾选邮件 MAIL_CHECK = "alarmTypeMailCheck" #选择邮件接收人添加按钮 COMMAND_RECEIVE_USER = "******" u'''运行状态告警''' #内存百分比 MEM_SELECT = "memoryAlarmSelect" #硬盘百分比 DISK_SELECT = "diskAlarmSelect" #CPU百分比 CPU_SELECT = "cpuAlarmSelect" #运行状态告警默认告警级别 DEF_ALR_LEVEL_SELECT = "defaultAlarmLevelSelect" #勾选syslog RUN_SYSLOG_CHECK = "runStateAlarmTypeSyslogCheck" #勾选邮件 RUN_MAIL_CHECK = "runStateAlarmTypeMailCheck" #选择邮件接收人添加按钮 SYSTEM_STATE_RECEIVE_USER = "******" #周期检测 TEST_SELECT = "testCycleSelect" #事件是否升级开关 SWTICH_BUTTON = "btn_sj" #重复发生事件次数 TIME_SELECT = "repeatTimesSelect" #事件升级告警级别 DEF_UPDATE_SELECT = "defaultAlarmUpdateSelect" u'''认证异常''' #默认告警级别 AUTH_ALARM_LEVEL = "authAlarmLevel" #勾选syslog AUTH_SYSLOG_CHECK = "authAlarmTypeSyslogCheck" #勾选邮件 AUTH_MAIL_CHECK = "authAlarmTypeMailCheck" #选择邮件接收人添加按钮 AUTH_EXCEPTIN_RECEIVE_USER = "******" u'''告警归纳''' #类型检索 FORT_SYSTEM_ALARM_TYPEID = "fortSystemAlarmTypeId" #等级检索 FORT_ALARM_LEVEL = "fortAlarmLevel" #检索按钮 SEARCH_BUTTON = "js_btn" #重置按钮 REST_BUTTON = "resetting" #保存按钮 SAVE_BUTTON = "saveAlarmConfig" #选择邮件接收人检索按钮 RECEIVE_USER_BUTTON = "quick_user" #选择邮件接收页面确定按钮 OK_BUTTON = "okButton" #选择邮件接收页面返回按钮 RETURN_BUTTON = "cancelButton" #勾全选 CHECK_ALL_BUTTON = "user_check_all" #填写邮箱 USER_MAIL = "fortUserEmail" #个人信息维护 MESSAGE = "message" def __init__(self,driver): self.driver = driver self.log = log() self.cmf = commonFun(driver) self.getElem = getElement(driver) self.cnEnde = cnEncode() self.tableElem = tableElement(self.driver) self.selectElem = selectElement(driver) self.dataFile = dataFileName() self.frameElem = frameElement(self.driver) self.user = UserPage(driver) u'''点击保存按钮''' def save_button(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") try: self.getElem.find_element_with_wait_clickable_and_click('id',self.SAVE_BUTTON) except Exception as e: print ("Save policy error: ") + str(e) u'''点击添加邮件接收人公用方法 parameters : type : 定位方式 value : 值 ''' def click_button_common(self,type,value): var_button = self.getElem.find_element_with_wait_EC(type,value) if var_button.is_displayed(): var_button.click() u'''选择邮件接收人检索按钮''' def click_receive_user(self): try: self.click_button_common('id',self.RECEIVE_USER_BUTTON) except Exception as e: print ("Select the mail recipient error : ") + str(e) u'''点击确定按钮''' def ok_button(self): self.frameElem.switch_to_content() try: self.getElem.find_element_wait_and_click_EC('id',self.OK_BUTTON) except Exception as e: print ("Determine error: ") + str(e) u'''点击返回按钮''' def return_button(self): try: self.getElem.find_element_with_wait_clickable_and_click('id',self.RETURN_BUTTON) except Exception as e: print ("return error: ") + str(e) u'''勾选全选按钮''' def check_all_button(self): try: self.click_button_common('id',self.CHECK_ALL_BUTTON) except Exception as e: print("Click checkall button error: ") + str(e) u'''左边框点击告警配置''' def click_left_config_test(self): self.frameElem.from_frame_to_otherFrame("leftFrame") self.getElem.find_element_wait_and_click_EC("id", "url1") u'''左边框点击告警归纳''' def click_left_Induce_test(self): self.frameElem.from_frame_to_otherFrame("leftFrame") self.getElem.find_element_wait_and_click_EC("id", "url0") u'''填写变量内容 parameters: var_text : 变量内容 value : 定位方式值 ''' def set_common_func(self,var_text,value): self.frameElem.from_frame_to_otherFrame("rigthFrame") try: revar_text = self.cnEnde.is_float(var_text) var_elem =self.getElem.find_element_with_wait_EC('id',value) var_elem.clear() var_elem.send_keys(revar_text) except Exception as e: print ("set common text error: ") + str(revar_text) + str(e) #取消高危运维syslog,邮件配置 def del_command_config(self): try: self.frameElem.from_frame_to_otherFrame("mainFrame") self.click_left_config_test() self.click_command_alarm_menu() self.syslog_check() self.mail_check() self.save_button() self.frameElem.switch_to_content() self.cmf.click_msg_button(1) except Exception as e: print ("del command config: ") + str(e) #取消运行状态告警syslog,邮件配置 def del_default_config(self): try: self.frameElem.from_frame_to_otherFrame("mainFrame") self.click_left_config_test() self.click_default_alarm_menu() self.run_syslog_check() self.run_mail_check() self.change_switch_status() self.save_button() self.frameElem.switch_to_content() self.cmf.click_msg_button(1) except Exception as e: print ("del default config: ") + str(e) #取消认证异常syslog,邮件配置 def del_auth_config(self): try: self.frameElem.from_frame_to_otherFrame("mainFrame") self.click_left_config_test() self.auth_default_alarm_menu() self.auth_syslog_check() self.auth_mail_check() self.save_button() self.frameElem.switch_to_content() self.cmf.click_msg_button(1) except Exception as e: print ("del auth config: ") + str(e) #取消绕行告警syslog,邮件配置 def del_ip_config(self): try: self.frameElem.from_frame_to_otherFrame("mainFrame") self.click_left_config_test() self.ip_default_alarm_menu() self.ip_syslog_check() self.ip_mail_check() self.del_ip_select() self.save_button() self.frameElem.switch_to_content() self.cmf.click_msg_button(1) except Exception as e: print ("del ip config: ") + str(e) #---------------------------------高危运维-------------------------------------------------- #点击高危运维模块 def click_command_alarm_menu(self): try: self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_with_wait_clickable_and_click('link',"高危运维") except Exception as e: print ("commmand alarm menu error: ") + str(e) u'''高危运维默认告警级别 parameter: commandValue : 告警级别option的value值(5代表等级:5) ''' def command_alarm_level(self,commandValue): return self.user.set_common_select_elem(commandValue,self.COMMON_ALARM_LEVEL) u'''勾选syslog按钮''' def syslog_check(self): try: self.getElem.find_element_with_wait_clickable_and_click('id',self.SYSLOG_CHECK) except Exception as e: print ("Check syslog error: ") + str(e) u'''勾选mail按钮''' def mail_check(self): try: self.getElem.find_element_with_wait_clickable_and_click('id',self.MAIL_CHECK) except Exception as e: print ("mail mail error: ") + str(e) u'''点击邮件添加按钮''' def click_illegal_command_receive_user(self): try: self.getElem.find_element_with_wait_clickable_and_click('id',self.COMMAND_RECEIVE_USER) except Exception as e: print ("click mail recipient error: ") + str(e) #---------------------------------运维状态告警-------------------------------------------------- #点击运行状态告警模块 def click_default_alarm_menu(self): try: self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_with_wait_clickable_and_click('link',"运行状态告警") except Exception as e: print ("default alarm menu error: ") + str(e) u'''内存设置百分比 parameter: memoryValue : mem百分比option的value值(5代表50%) ''' def memory_alarm_select(self,memoryValue): return self.user.set_common_select_elem(memoryValue,self.MEM_SELECT) u'''磁盘设置百分比 parameter: diskValue : disk百分比option的value值(5代表50%) ''' def disk_alarm_select(self,diskValue): return self.user.set_common_select_elem(diskValue,self.DISK_SELECT) u'''cpu设置百分比 parameter: cpuValue : cpu百分比option的value值(5代表50%) ''' def cpu_alarm_select(self,cpuValue): return self.user.set_common_select_elem(cpuValue,self.CPU_SELECT) u'''检测周期 parameter: testValue : 检测周期option的value值(5代表5秒) ''' def test_cycle_select(self,testValue): return self.user.set_common_select_elem(testValue,self.TEST_SELECT) u'''默认告警级别 parameter: defaultValue : 默认告警级别option的value值(5代表级别5) ''' def default_alarm_level_select(self,defaultValue): return self.user.set_common_select_elem(defaultValue,self.DEF_ALR_LEVEL_SELECT) u'''勾选syslog按钮''' def run_syslog_check(self): try: self.getElem.find_element_with_wait_clickable_and_click('id',self.RUN_SYSLOG_CHECK) except Exception as e: print ("Check syslog run error: ") + str(e) u'''勾选mail按钮''' def run_mail_check(self): try: self.getElem.find_element_with_wait_clickable_and_click('id',self.RUN_MAIL_CHECK) except Exception as e: print ("Check mail run error: ") + str(e) u'''选择邮件接收人添加按钮''' def system_state_receive_user(self): try: self.getElem.find_element_with_wait_clickable_and_click('id',self.SYSTEM_STATE_RECEIVE_USER) except Exception as e: print ("Select the system mail recipient error: ") + str(e) u'''改变开关状态''' def change_switch_status(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") try: button_elem = self.getElem.find_element_with_wait_EC("id",self.SWTICH_BUTTON) class_attr = button_elem.get_attribute("class") off_status = "switch_off" on_status = "switch_on" if class_attr == on_status: self.click_default_alarm_menu() self.frameElem.from_frame_to_otherFrame("rigthFrame") button_elem = self.getElem.find_element_with_wait_EC("id",self.SWTICH_BUTTON) button_elem.click() button_elem.click() else: button_elem.click() except Exception as e: print ("Change button status error: ") + str(e) u'''重复事件 parameter: repeatValue : 重复事件option的value值(10代表10次) ''' def repeat_times_select(self,repeatValue): return self.user.set_common_select_elem(repeatValue,self.TIME_SELECT) u'''升级事件告警级别 parameter: updateValue : 升级告警级别option的value值(6代表等级6) ''' def defaultA_alarm_update_elect(self,updateValue): return self.user.set_common_select_elem(updateValue,self.DEF_UPDATE_SELECT) #---------------------------------认证异常-------------------------------------------------- #点击认证异常模块 def auth_default_alarm_menu(self): try: self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_with_wait_clickable_and_click('link',"认证异常") except Exception as e: print ("auth alarm menu error: ") + str(e) u'''默认告警级别 parameter: authValue : 告警级别option的value值(5代表等级:5) ''' def auth_alarm_level(self,authValue): return self.user.set_common_select_elem(authValue,self.AUTH_ALARM_LEVEL) u'''勾选syslog按钮''' def auth_syslog_check(self): try: self.getElem.find_element_with_wait_clickable_and_click('id',self.AUTH_SYSLOG_CHECK) except Exception as e: print ("Check auth syslog error: ") + str(e) u'''勾选mail按钮''' def auth_mail_check(self): try: self.getElem.find_element_with_wait_clickable_and_click('id',self.AUTH_MAIL_CHECK) except Exception as e: print ("mail auth mail error: ") + str(e) u'''选择邮件接收人添加按钮''' def auth_exception_receive_user(self): try: self.getElem.find_element_with_wait_clickable_and_click('id',self.AUTH_EXCEPTIN_RECEIVE_USER) except Exception as e: print ("Select the auth mail recipient error: ") + str(e) #---------------------------------告警归纳-------------------------------------------------- u'''点击检索按钮''' def search_button(self): try: self.getElem.find_element_with_wait_clickable_and_click('classname',self.SEARCH_BUTTON) time.sleep(1) except Exception as e: print ("Retrieval strategy error: ") + str(e) u'''点击重置按钮''' def rest_button(self): try: self.getElem.find_element_with_wait_clickable_and_click('id',self.REST_BUTTON) except Exception as e: print ("reset error: ") + str(e) u'''类型检索 parameter: text : 告警类型检索的text值 ''' def search_type(self,text): try: searchtext = self.cnEnde.is_float(text) search_type = self.getElem.find_element_with_wait_EC('id', self.FORT_SYSTEM_ALARM_TYPEID) self.selectElem.select_element_by_visible_text(search_type, searchtext) except Exception as e: print ("search type select error:") + str(e) u'''级别检索 parameter: text : 告警级别检索的text值 ''' def search_level(self,text): try: searchtext = self.cnEnde.is_float(text) search_level = self.getElem.find_element_with_wait_EC('id', self.FORT_ALARM_LEVEL) self.selectElem.select_element_by_visible_text(search_level, searchtext) except Exception as e: print ("search level select error:") + str(e) #---------------------------------填写邮箱-------------------------------------------------- #点击个人维护 def click_user_message_menu(self): self.frameElem.from_frame_to_otherFrame("topFrame") try: self.getElem.find_element_with_wait_clickable_and_click('id',self.MESSAGE) except Exception as e: print ("click user message menu error: ") + str(e) #填写邮箱 def set_user_mail(self,usermail): return self.user.set_common_func(usermail,self.USER_MAIL) #点击保存 def click_save_button(self): return self.user.save_button()
class Backuprestore(object): def __init__(self, driver): self.driver = driver self.getElem = getElement(driver) self.selectElem = selectElement(driver) self.frameElem = frameElement(driver) self.cmf = commonFun(driver) self.cnEn = cnEncode() self.comsuit = CommonSuiteData(self.driver) self.command = CommandRule(self.driver) self.tableElem = tableElement(driver) self.log = log() self.userElem = UserPage(self.driver) self.role = Role(driver) u'''点击自动备份开关''' def auto_backup_switch(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_click_EC("id", "btn_qh") u'''勾选系统配置''' def check_sys_config(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") values = self.check_common() if values[0] == None: self.getElem.find_element_wait_and_click_EC("id", "configBackUp") if values[1] != None: self.getElem.find_element_wait_and_click_EC("id", "databaseBackUp") u'''勾选实体配置''' def check_entity_config(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") values = self.check_common() if values[0] != None: self.getElem.find_element_wait_and_click_EC("id", "configBackUp") if values[1] == None: self.getElem.find_element_wait_and_click_EC("id", "databaseBackUp") u'''勾选实体配置和系统配置''' def check_all_config(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") values = self.check_common() if values[0] == None: self.getElem.find_element_wait_and_click_EC("id", "configBackUp") if values[1] == None: self.getElem.find_element_wait_and_click_EC("id", "databaseBackUp") u'''勾选实体或者系统配置公共方法''' def check_common(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") selem = self.getElem.find_element_with_wait_EC("id", "configBackUp") value = selem.get_attribute('checked') selemdb = self.getElem.find_element_with_wait_EC("id", "databaseBackUp") valuedb = selemdb.get_attribute('checked') list = [value, valuedb] return list u'''勾选实体或者系统配置 parameter: - stauts:勾选配置信息1代表系统配置2代表实体配置,3代表系统配置和实体配置 ''' def check_config(self, stauts): staut = self.cnEn.is_float(stauts) if staut == '1': self.check_sys_config() elif staut == '2': self.check_entity_config() else: self.check_all_config() u'''选择备份方式 parameter: - stauts:value属性值,1代表一次性执行,2代表周期性执行 ''' def select_backup_mode(self, stauts): staut = self.cnEn.is_float(stauts) self.frameElem.from_frame_to_otherFrame("rigthFrame") selem = self.getElem.find_element_with_wait_EC("id", "backUpType") self.selectElem.select_element_by_value(selem, staut) u'''选择执行小时 parameter: - stauts:value属性值 ''' def select_hour(self, stauts): staut = self.cnEn.is_float(stauts) self.frameElem.from_frame_to_otherFrame("rigthFrame") selem = self.getElem.find_element_with_wait_EC("id", "startHour") self.selectElem.select_element_by_value(selem, staut) u'''填写分钟 parameter: - minute:分钟 ''' def set_minute(self, minute): minu = self.cnEn.is_float(minute) self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_clear_EC("id", "startMinute") self.getElem.find_element_wait_and_sendkeys("id", "startMinute", minu) u'''选择执行方式 parameter: - staut:0代表按天,1代表按周,2代表按月,3代表按年 ''' def select_execu_mode(self, staut): self.frameElem.from_frame_to_otherFrame("rigthFrame") if staut == 0: self.getElem.find_element_wait_and_click_EC("id", "dayradio") elif staut == 1: self.getElem.find_element_wait_and_click_EC("id", "weekradio") elif staut == 2: self.getElem.find_element_wait_and_click_EC("id", "monthRadio") else: self.getElem.find_element_wait_and_click_EC("id", "yearRadio") u'''选择存储位置 parameter: - stauts:value属性值1代表本地备份2代表ftp备份 ''' def select_storage_location(self, stauts): staut = self.cnEn.is_float(stauts) self.frameElem.from_frame_to_otherFrame("rigthFrame") selem = self.getElem.find_element_with_wait_EC("id", "backUpLocation") self.selectElem.select_element_by_value(selem, staut) u'''填写远程路径 parameter: - path:远程路径 ''' def set_remote_path(self, path): pat = self.cnEn.is_float(path) self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_clear_EC("id", "path") self.getElem.find_element_wait_and_sendkeys("id", "path", pat) u'''填写服务器IP parameter: - ip:服务器IP ''' def set_ftpip(self, ip): self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_clear_EC("id", "ip") self.getElem.find_element_wait_and_sendkeys("id", "ip", ip) u'''填写连接用户名 parameter: - minute:连接用户名 ''' def set_name(self, name): nam = self.cnEn.is_float(name) self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_clear_EC("id", "username") self.getElem.find_element_wait_and_sendkeys("id", "username", nam) u'''填写连接口令 parameter: - password:连接口令 ''' def set_password(self, password): pwd = self.cnEn.is_float(password) self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_clear_EC("id", "password") self.getElem.find_element_wait_and_sendkeys("id", "password", pwd) u'''填写确认口令 parameter: - minute:分钟 ''' def set_password_again(self, password): pwd = self.cnEn.is_float(password) self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_clear_EC("id", "passwordAgain") self.getElem.find_element_wait_and_sendkeys("id", "passwordAgain", pwd) u'''点击立刻备份''' def click_backup_immediately(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_click_EC("id", "back_up_now") u'''点击保存''' def click_save(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_click_EC("id", "back_up_save") u'''选择系统备份还原或者查看备份文件 parameter: - staut:0代表系统备份还原,1代表查看备份文件 ''' def select_backup_menu(self, staut): self.frameElem.from_frame_to_otherFrame("rigthFrame") if staut == 0: self.getElem.find_element_wait_and_click_EC("id", "tit1") elif staut == 1: self.getElem.find_element_wait_and_click_EC("id", "tit2") u'''点击操作列操作 Parameters: - filename:文件名称 - value:1代表下载,2代表删除,3代表还原 ''' def click_operat_file(self,filename, value): self.frameElem.from_frame_to_otherFrame("rigthFrame") row = 1 selems = self.driver.find_elements_by_name("file") for selem in selems: idvalue = selem.get_attribute('id') row = row +1 if idvalue == filename: xpath = ".//*[@id='content_rt02']/div/table/tbody/tr[" + str(row) + "]/td[7]/input[" + str(value) + "]" self.getElem.find_element_wait_and_click_EC("xpath", xpath) time.sleep(1) u'''下载上传完成后点击操作列操作 Parameters: - filename:文件名称 - value:1代表下载,2代表删除,3代表还原 ''' def upload_click_operat_file(self,filename, value): self.frameElem.from_frame_to_otherFrame("rigthFrame") row = 1 filenames = ""+filename[:-6] + ""+filename+"" selems = self.driver.find_elements_by_name("file") for selem in selems: idvalue = selem.get_attribute('id') row = row +1 if idvalue == filename or idvalue == filenames: xpath = ".//*[@id='content_rt02']/div/table/tbody/tr[" + str(row) + "]/td[7]/input[" + str(value) + "]" self.getElem.find_element_wait_and_click_EC("xpath", xpath) time.sleep(1) u'''点击还原系统配置''' def click_restore_sys_config(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_click_EC("id", "deleConfig1") u'''点击清空数据库''' def click_reset_database(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_click_EC("id", "resetDataBase1") u'''点击清空数据库''' def click_reset_audit(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_click_EC("id", "delAuditFile1") u'''填写syslogip parameter: - syslogip:syslogip ''' def set_syslogip(self, syslogip): ip = self.cnEn.is_float(syslogip) self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_clear_EC("id", "host") self.getElem.find_element_wait_and_sendkeys("id", "host", ip) u'''填写syslog端口 parameter: - port:syslog端口 ''' def set_port(self, port): sysport = self.cnEn.is_float(port) self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_clear_EC("id", "port") self.getElem.find_element_wait_and_sendkeys("id", "port", sysport) u'''点击syslog保存''' def click_syslog_save(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_click_EC("id", "save_syslog") u'''获取syslogip值''' def get_syslog_port(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") selem = self.getElem.find_element_with_wait_EC("id", "port") value = selem.get_attribute("value") return value u'''获取文件名称''' def get_file_name(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") selem = self.getElem.find_element_with_wait_EC("xpath", ".//*[@id='content_rt02']/div/table/tbody/tr[2]") value = selem.get_attribute('id') return value u'''编辑syslog parameter: - ip:syslogip - port:端口 ''' def set_syslog(self, port, ip='no'): self.comsuit.switch_to_moudle(u'系统配置', u'关联服务') self.command.click_left_rule(1) if ip != 'no': self.set_syslogip(ip) self.set_port(port) self.click_syslog_save() self.frameElem.switch_to_content() self.cmf.click_msg_button(1) u'''检验syslog端口是否为备份之前信息 parameter: - port:端口 - checklog:检验信息 ''' def check_syslog_content(self, port, checklog): self.comsuit.switch_to_moudle(u'系统配置', u'关联服务') self.command.click_left_rule(1) elemText = self.get_syslog_port() strdata3 = self.cnEn.is_float(port) if elemText == strdata3: self.log.log_detail(checklog, True) else: self.log.log_detail(checklog, False) u'''校验用户或者角色信息 Parameters: - namevalue:传入的要被查询名称 - name:表格列的name属性 - checklog:日志信息 return:定位该名称位于第几行 ''' def check_content(self,namevalue, name, checklog): row = self.cmf.find_row_by_name(namevalue, name) if row != 0: self.log.log_detail(checklog, True) else: self.log.log_detail(checklog, False) u'''填写用户信息 parameters: account : 用户账号 name : 用户名称 pwd : 用户密码 agpwd : 确认密码 ''' def set_user_info(self, account, name, pwd, agpwd): self.comsuit.switch_to_moudle(u"运维管理", u"用户") self.frameElem.from_frame_to_otherFrame("mainFrame") self.userElem.add_button() self.userElem.set_user_account(account) self.userElem.set_user_name(name) self.userElem.set_user_pwd(pwd) self.userElem.set_user_enquire_pwd(agpwd) self.userElem.save_button() self.frameElem.switch_to_content() self.cmf.click_login_msg_button() u'''点击用户操作列对应的删除按钮 parameters: - account : 用户账号 ''' def del_user_info(self, account): self.comsuit.switch_to_moudle(u"运维管理", u"用户") self.frameElem.from_frame_to_otherFrame("mainFrame") self.userElem.operate_delete(account) self.frameElem.switch_to_content() self.cmf.click_msg_button(1) self.frameElem.switch_to_content() self.cmf.click_msg_button(1) u'''点击备份还原配置文件的删除 parameters: - filename : 文件名称 - loginfo : 日志信息 ''' def del_backup_file(self, filename, loginfo): self.click_operat_file(filename, 2) self.frameElem.switch_to_content() self.cmf.click_msg_button(1) self.frameElem.switch_to_content() self.cmf.click_msg_button(1) time.sleep(1) self.log.log_detail(loginfo, True) u'''点击角色操作列对应的删除按钮 parameters: - rolename : 角色名称 ''' def del_role_info(self, rolename): self.comsuit.switch_to_moudle(u"角色管理", u"角色定义") self.frameElem.from_frame_to_otherFrame("mainFrame") self.role.delete(rolename) self.frameElem.switch_to_content() self.cmf.click_msg_button(1) u'''执行还原操作 parameters: - filename :执行还原的文件名称 - loginfo :日志信息 - stauts :状态1代表执行操作列按钮2代表进行上传后操作列按钮 ''' def execute_restore(self, filename, loginfo, stauts=1): self.comsuit.switch_to_moudle(u'系统配置', u'备份还原') self.command.click_left_rule(0) self.select_backup_menu(1) if stauts == 1: self.click_operat_file(filename, 3) elif stauts == 2: self.upload_click_operat_file(filename, 3) time.sleep(5) self.frameElem.switch_to_content() self.getElem.find_element_with_wait_EC("classname", "aui_state_highlight") time.sleep(3) self.cmf.click_msg_button(1) self.log.log_detail(loginfo, True) u'''配置备份信息 parameters: - data :数据文件集 - backMsg :保存成功的弹出框信息 - flag :无检查点的测试项标识,如果为True说明通过 ''' def config_backup(self, data, backMsg, flag): self.comsuit.switch_to_moudle(u'系统配置', u'备份还原') self.command.click_left_rule(0) self.check_config(data[12]) self.select_backup_mode(data[4]) self.backup_time(data[5], data[6]) self.select_storage_location(data[7]) self.click_save() time.sleep(3) self.frameElem.switch_to_content() self.cmf.test_win_check_point("xpath", backMsg, data, flag) self.click_backup_immediately() time.sleep(2) self.frameElem.switch_to_content() self.cmf.click_msg_button(1) self.log.log_detail(data[9], True) self.select_backup_menu(1) u'''填写角色信息 Parameters: - rolename :角色名称 - shortname :名称简写 ''' def set_role_info(self, rolename, shortname): self.comsuit.switch_to_moudle(u"角色管理", u"角色定义") self.frameElem.from_frame_to_otherFrame("mainFrame") self.role.add() self.role.edit_rolename(rolename) self.role.edit_shortname(shortname) self.role.select_sysrole() self.role.save_button() self.frameElem.switch_to_content() self.cmf.click_msg_button(1) u'''执行日期 Parameters: - type :t代表今天,c代表clear,q代表确定,默认选择今天 - backuptime :执行日期设定的日期,格式为2016-9-7 11:42:42 ''' def backup_time(self, types, backuptime): self.frameElem.from_frame_to_otherFrame("rigthFrame") # 时间控件的fram的xpath fxpath = "//iframe[@hidefocus='true']" # 日期控件table的xpath路径 txpath = "/html/body/div/div[3]/table" status = self.cnEn.is_float('1') type = self.cnEn.is_float(types) # 转成datetime对象 date = datetime(*xldate_as_tuple(backuptime, 0)) end = date.strftime('%Y-%m-%d %H:%M:%S') self.option_time("backUpTime", fxpath, status, type, txpath, end) u'''操作时间控件 Parameters: - wdateId:日期控件input控件的ID值 - fxpath:日期控件frame的xpath路径 - status: 日期控件是否有时分秒 - txpath:日期控件table的xpath路径 - time:设定的日期,格式为2016-9-7 11:42:42 - type:t代表今天,c代表clear,q代表确定,默认选择今天 ''' def option_time(self,wdateId,fxpath,status='0',type='t',txpath = None,dtime = None): self.getElem.find_element_wait_and_click("id",wdateId) frame = self.driver.find_element_by_xpath(fxpath) self.driver.switch_to_frame(frame) if type == 't': self.getElem.find_element_wait_and_click("id","dpTodayInput") elif type == 'c': self.getElem.find_element_wait_and_click("id","dpClearInput") elif type == 'q': if dtime is not None: list = dtime.split() ymdList = list[0].split("-") hmsList = list[1].split(":") #年 tYear = ymdList[0] #月 tMon = ymdList[1] #日 tDay = ymdList[2] #时 tHour = hmsList[0] #分 tMin = hmsList[1] #秒 tSen = hmsList[2] dTitle = self.getElem.find_element_with_wait("id","dpTitle").find_elements_by_tag_name("input") #设定月 dTitle[0].clear() dTitle[0].send_keys(tMon) #设定年 dTitle[1].clear() dTitle[1].send_keys(tYear) self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_click_EC("id", "backUpTime") self.driver.switch_to_frame(frame) if txpath is not None: iStatus = False for itr in range(7): if itr != 0: for itd in range(7): ct = self.tableElem.get_table_cell_text(txpath,itr,itd)[0] #排除第一行大于7的 if itr == 1 and int(ct) > 7: continue #排除倒数第二行小于15的 if itr == 5 and int(ct) < 15: continue #排除最后一行小于15的 if itr == 6 and int(ct) < 15: continue #如果跟给定的日期一致,点击日期 if int(ct) == int(tDay): self.tableElem.get_table_cell_text(txpath,itr,itd)[1].click() iStatus = True break #找到日期后跳出循环 if iStatus: break #日期控件是否有时分秒 if status == '1': dTime = self.getElem.find_element_with_wait("id","dpTime").find_elements_by_tag_name("input") #设定小时 dTime[0].clear() dTime[0].send_keys(tHour) #设定分钟 dTime[2].clear() dTime[2].send_keys(tMin) #设定秒 dTime[4].clear() dTime[4].send_keys(tSen) self.getElem.find_element_wait_and_click("id","dpOkInput") u'''上传操作 parameters: - filename :执行还原的文件名称 - loginfo :日志信息 ''' def backup_file_upload(self, filename, loginfo): self.frameElem.from_frame_to_otherFrame("rigthFrame") value = "C:\Users\Administrator\Downloads\\" + filename+"" self.getElem.find_element_wait_and_sendkeys("id", "backUpFile", value) time.sleep(2) self.getElem.find_element_wait_and_click_EC("id", "up_file") self.frameElem.switch_to_content() self.cmf.click_msg_button(1) time.sleep(1) self.log.log_detail(loginfo, True)