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 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 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)