class testCommand(object): def __init__(self, driver): self.driver = driver self.log = log() self.cmf = commonFun(driver) self.frameElem = frameElement(driver) self.testrole = testRole(driver) self.command = CommandRule(driver) self.sso = testSso(driver) self.comsuit = CommonSuiteData(driver) u'''获取测试数据 Parameters: - sheetname:sheet名称 return:表格数据 ''' def get_table_data(self, sheetname): dataFile = dataFileName() comrulPath = dataFile.get_command_test_data_url() comrulData = dataFile.get_data(comrulPath, sheetname) return comrulData u'''添加命令规则''' def add_command_rule_001(self): #日志开始记录 self.log.log_start("add_command_rule") #获取添加命令规则测试数据 comrulData = self.get_table_data("add_command_rule") #保存成功的弹出框 comrulMsg = self.testrole.popup() #无检查点的测试项标识,如果为True说明通过 flag = False for dataRow in range(len(comrulData)): data = comrulData[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: self.command.click_add_button() self.command.select_command_type((data[2])) self.command.set_command(data[3]) self.command.click_add_command_button() self.command.set_test_command(data[4]) self.command.click_test_command_button() self.cmf.click_login_msg_button() if int(data[2]) == 2: self.command.click_approver_command() self.command.check_all_user() self.command.click_add_users_button() self.command.check_all_user() self.command.click_add_resource_button() self.command.check_all_resource() self.command.click_save_command() self.frameElem.switch_to_content() self.cmf.test_win_check_point("xpath", comrulMsg, data, flag) self.command.click_back_command() except Exception as e: print("add_command_rule fail:" + str(e)) self.log.log_end("add_command_rule") u'''编辑命令规则''' def mod_command_rule_002(self): #日志开始记录 self.log.log_start("mod_command_rule") #获取编辑命令规则测试数据 comrulData = self.get_table_data("mod_command_rule") #保存成功的弹出框 comrulMsg = self.testrole.popup() #无检查点的测试项标识,如果为True说明通过 flag = False for dataRow in range(len(comrulData)): data = comrulData[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: self.command.click_action_public_command(data[2], data[3]) self.command.set_command(data[4]) self.command.click_add_command_button() self.command.click_save_command() self.frameElem.switch_to_content() self.cmf.test_win_check_point("xpath", comrulMsg, data, flag) self.command.click_back_command() except Exception as e: print("mod_command_rule fail:" + str(e)) self.log.log_end("mod_command_rule") u'''操作命令规则''' def option_command_rule_003(self): #日志开始记录 self.log.log_start("option_command_rule") #获取操作命令规则测试数据 comrulData = self.get_table_data("option_command_rule") #保存成功的弹出框 comrulMsg = self.testrole.popup() #无检查点的测试项标识,如果为True说明通过 flag = False for dataRow in range(len(comrulData)): data = comrulData[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: if dataRow == 1: self.command.click_del_command() elif dataRow == 2: self.command.click_deploy_command() elif dataRow == 3 or dataRow == 4: self.command.click_action_public_command( data[2], data[3]) elif dataRow == 5 or dataRow == 6: time.sleep(5) self.command.click_action_public_command( data[2], data[3]) self.command.set_row_command(data[4]) self.command.check_sure_button() self.frameElem.switch_to_content() self.cmf.test_win_check_point("xpath", comrulMsg, data, flag) time.sleep(3) self.command.click_cancel_button() continue self.frameElem.switch_to_content() self.cmf.test_win_check_point("xpath", comrulMsg, data, flag) except Exception as e: print("option_command_rule fail:" + str(e)) self.log.log_end("option_command_rule") u'''校验命令规则''' def check_command_rule_004(self): #日志开始记录 self.log.log_start("check_command_rule") #获取校验命令规则测试数据 comrulData = self.get_table_data("check_command_rule") #保存成功的弹出框 comrulMsg = self.testrole.popup() self.command.click_add_button() #无检查点的测试项标识,如果为True说明通过 flag = False for dataRow in range(len(comrulData)): data = comrulData[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: if data[2] != "no": self.command.select_command_type((data[2])) if data[3] != "no": self.command.set_command(data[3]) self.command.click_add_command_button() if data[4] != "no": self.command.set_test_command(data[4]) self.command.click_test_command_button() if dataRow == 4: self.command.click_save_command() elif dataRow == 5: self.command.click_add_users_button() self.command.check_all_user() self.command.click_save_command() elif dataRow == 6: self.command.click_add_resource_button() self.command.check_all_resource() self.command.click_save_command() elif dataRow == 7: self.command.click_approver_command() self.command.check_all_user() self.command.clear_command() self.command.click_save_command() self.frameElem.switch_to_content() self.cmf.test_win_check_point("xpath", comrulMsg, data, flag) except Exception as e: print("check_command_rule fail:" + str(e)) self.command.click_back_command() self.log.log_end("check_command_rule") u'''命令审批''' def command_approval_005(self): self.frameElem.from_frame_to_otherFrame("topFrame") self.cmf.select_role_by_text(u"运维操作员") #日志开始记录 self.log.log_start("command_approval") #获取命令审批测试数据 comrulData = self.get_table_data("command_approval") for dataRow in range(len(comrulData)): data = comrulData[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: self.command.sso_command(data) handles = self.driver.window_handles if dataRow == 2: self.command.command_by_message_approval( data[6], data[7], data[8]) self.cmf.click_login_msg_button() self.driver.switch_to.window(handles[1]) self.driver.close() self.driver.switch_to.window(handles[0]) #关闭浏览器 self.log.log_detail(data[0], True) except Exception as e: print("command_approval fail:" + str(e)) self.log.log_end("command_approval") u'''删除命令规则''' def del_command_rule_006(self): # self.comsuit.sys_switch_to_dep() # self.comsuit.switch_to_moudle(u"运维管理", u"规则定义") #日志开始记录 self.log.log_start("del_command_rule") #获取删除命令规则测试数据 comrulData = self.get_table_data("del_command_rule") #保存成功的弹出框 comrulMsg = self.testrole.popup() #无检查点的测试项标识,如果为True说明通过 flag = False for dataRow in range(len(comrulData)): data = comrulData[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: self.command.click_action_public_command(data[2], data[3]) self.command.click_del_command() self.frameElem.switch_to_content() self.cmf.test_win_check_point("xpath", comrulMsg, data, flag) self.cmf.click_login_msg_button() except Exception as e: print("del_command_rule fail:" + str(e)) self.log.log_end("del_command_rule")
class testCommand(object): def __init__(self,driver): self.driver = driver self.log = log() self.cmf = commonFun(driver) self.frameElem = frameElement(driver) self.testrole = testRole(driver) self.command = CommandRule(driver) self.sso = testSso(driver) self.comsuit = CommonSuiteData(driver) u'''获取测试数据 Parameters: - sheetname:sheet名称 return:表格数据 ''' def get_table_data(self, sheetname): dataFile = dataFileName() comrulPath = dataFile.get_command_test_data_url() comrulData = dataFile.get_data(comrulPath, sheetname) return comrulData u'''添加命令规则''' def add_command_rule_001(self): #日志开始记录 self.log.log_start("add_command_rule") #获取添加命令规则测试数据 comrulData = self.get_table_data("add_command_rule") #保存成功的弹出框 comrulMsg = self.testrole.popup() #无检查点的测试项标识,如果为True说明通过 flag = False for dataRow in range(len(comrulData)): data = comrulData[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: self.command.click_add_button() self.command.select_command_type((data[2])) self.command.set_command(data[3]) self.command.click_add_command_button() self.command.set_test_command(data[4]) self.command.click_test_command_button() self.cmf.click_login_msg_button() if int(data[2]) == 2: self.command.click_approver_command() self.command.check_all_user() self.command.click_add_users_button() self.command.check_all_user() self.command.click_add_resource_button() self.command.check_all_resource() self.command.click_save_command() self.frameElem.switch_to_content() self.cmf.test_win_check_point("xpath", comrulMsg, data, flag) self.command.click_back_command() except Exception as e: print ("add_command_rule fail:" + str(e)) self.log.log_end("add_command_rule") u'''编辑命令规则''' def mod_command_rule_002(self): #日志开始记录 self.log.log_start("mod_command_rule") #获取编辑命令规则测试数据 comrulData = self.get_table_data("mod_command_rule") #保存成功的弹出框 comrulMsg = self.testrole.popup() #无检查点的测试项标识,如果为True说明通过 flag = False for dataRow in range(len(comrulData)): data = comrulData[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: self.command.click_action_public_command(data[2], data[3]) self.command.set_command(data[4]) self.command.click_add_command_button() self.command.click_save_command() self.frameElem.switch_to_content() self.cmf.test_win_check_point("xpath", comrulMsg, data, flag) self.command.click_back_command() except Exception as e: print ("mod_command_rule fail:" + str(e)) self.log.log_end("mod_command_rule") u'''操作命令规则''' def option_command_rule_003(self): #日志开始记录 self.log.log_start("option_command_rule") #获取操作命令规则测试数据 comrulData = self.get_table_data("option_command_rule") #保存成功的弹出框 comrulMsg = self.testrole.popup() #无检查点的测试项标识,如果为True说明通过 flag = False for dataRow in range(len(comrulData)): data = comrulData[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: if dataRow == 1: self.command.click_del_command() elif dataRow == 2: self.command.click_deploy_command() elif dataRow == 3 or dataRow == 4: self.command.click_action_public_command(data[2], data[3]) elif dataRow == 5 or dataRow == 6: time.sleep(5) self.command.click_action_public_command(data[2], data[3]) self.command.set_row_command(data[4]) self.command.check_sure_button() self.frameElem.switch_to_content() self.cmf.test_win_check_point("xpath", comrulMsg, data, flag) time.sleep(3) self.command.click_cancel_button() continue self.frameElem.switch_to_content() self.cmf.test_win_check_point("xpath", comrulMsg, data, flag) except Exception as e: print ("option_command_rule fail:" + str(e)) self.log.log_end("option_command_rule") u'''校验命令规则''' def check_command_rule_004(self): #日志开始记录 self.log.log_start("check_command_rule") #获取校验命令规则测试数据 comrulData = self.get_table_data("check_command_rule") #保存成功的弹出框 comrulMsg = self.testrole.popup() self.command.click_add_button() #无检查点的测试项标识,如果为True说明通过 flag = False for dataRow in range(len(comrulData)): data = comrulData[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: if data[2] != "no": self.command.select_command_type((data[2])) if data[3] != "no": self.command.set_command(data[3]) self.command.click_add_command_button() if data[4] != "no": self.command.set_test_command(data[4]) self.command.click_test_command_button() if dataRow == 4: self.command.click_save_command() elif dataRow == 5: self.command.click_add_users_button() self.command.check_all_user() self.command.click_save_command() elif dataRow == 6: self.command.click_add_resource_button() self.command.check_all_resource() self.command.click_save_command() elif dataRow == 7: self.command.click_approver_command() self.command.check_all_user() self.command.clear_command() self.command.click_save_command() self.frameElem.switch_to_content() self.cmf.test_win_check_point("xpath", comrulMsg, data, flag) except Exception as e: print ("check_command_rule fail:" + str(e)) self.command.click_back_command() self.log.log_end("check_command_rule") u'''命令审批''' def command_approval_005(self): self.frameElem.from_frame_to_otherFrame("topFrame") self.cmf.select_role_by_text(u"运维操作员") #日志开始记录 self.log.log_start("command_approval") #获取命令审批测试数据 comrulData = self.get_table_data("command_approval") for dataRow in range(len(comrulData)): data = comrulData[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: self.command.sso_command(data) handles = self.driver.window_handles if dataRow == 2: self.command.command_by_message_approval(data[6], data[7], data[8]) self.cmf.click_login_msg_button() self.driver.switch_to.window(handles[1]) self.driver.close() self.driver.switch_to.window(handles[0]) #关闭浏览器 self.log.log_detail(data[0], True) except Exception as e: print ("command_approval fail:" + str(e)) self.log.log_end("command_approval") u'''删除命令规则''' def del_command_rule_006(self): # self.comsuit.sys_switch_to_dep() # self.comsuit.switch_to_moudle(u"运维管理", u"规则定义") #日志开始记录 self.log.log_start("del_command_rule") #获取删除命令规则测试数据 comrulData = self.get_table_data("del_command_rule") #保存成功的弹出框 comrulMsg = self.testrole.popup() #无检查点的测试项标识,如果为True说明通过 flag = False for dataRow in range(len(comrulData)): data = comrulData[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: self.command.click_action_public_command(data[2], data[3]) self.command.click_del_command() self.frameElem.switch_to_content() self.cmf.test_win_check_point("xpath", comrulMsg, data, flag) self.cmf.click_login_msg_button() except Exception as e: print ("del_command_rule fail:" + str(e)) self.log.log_end("del_command_rule")
class RetimeRule(object): def __init__(self, driver): self.driver = driver self.getElem = getElement(driver) self.selectElem = selectElement(driver) self.frameElem = frameElement(driver) self.cnEn = cnEncode() self.acproval = Accapproval(driver) self.command = CommandRule(driver) self.log = log() u'''点击删除''' def click_bulkdel_retime(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_click_EC( "id", "delete_rule_time_resource") u'''选择默认动作 Parameters: - staut:0代表禁止登录,1代表允许登录 ''' def select_default_type(self, state): try: valu = self.cnEn.is_float(state) self.frameElem.from_frame_to_otherFrame("rigthFrame") selem = self.getElem.find_element_with_wait_EC("id", "defaultType") self.selectElem.select_element_by_value(selem, valu) except Exception: print("Select default action failure") u'''点击运行状态''' def click_running_state(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_click_EC("id", "ruleState") u'''填写每月开始日期 Parameters: - starttime:每月的开始时间 ''' def set_month_start_time(self, starttime): valu = self.cnEn.is_float(starttime) self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_clear_EC("id", "fortMonthStartTime") self.getElem.find_element_wait_and_sendkeys("id", "fortMonthStartTime", valu) u'''填写每月结束日期 Parameters: - endtime:每月的结束时间 ''' def set_month_end_time(self, endtime): valu = self.cnEn.is_float(endtime) self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_clear_EC("id", "fortMonthEndTime") self.getElem.find_element_wait_and_sendkeys("id", "fortMonthEndTime", valu) u'''选择每周开始日期 Parameters: - starttime:每周的开始时间 ''' def set_week_start_time(self, starttime): valu = self.cnEn.is_float(starttime) self.frameElem.from_frame_to_otherFrame("rigthFrame") selem = self.getElem.find_element_with_wait_EC("id", "fortWeekStartTime") self.selectElem.select_element_by_value(selem, valu) u'''选择每周结束日期 Parameters: - endtime:每周的结束时间 ''' def set_week_end_time(self, endtime): valu = self.cnEn.is_float(endtime) self.frameElem.from_frame_to_otherFrame("rigthFrame") selem = self.getElem.find_element_with_wait_EC("id", "fortWeekEndTime") self.selectElem.select_element_by_value(selem, valu) u'''填写每天开始时间 Parameters: - starttime:每天的开始时间 ''' def set_day_start_time(self, starttime): valu = self.cnEn.is_float(starttime) self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_clear_EC("id", "fortDayStartTime") self.getElem.find_element_wait_and_sendkeys("id", "fortDayStartTime", valu) u'''填写每天结束时间 Parameters: - endtime:每天的结束时间 ''' def set_day_end_time(self, endtime): valu = self.cnEn.is_float(endtime) self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_clear_EC("id", "fortDayEndTime") self.getElem.find_element_wait_and_sendkeys("id", "fortDayEndTime", valu) u'''选择动作 Parameters: - staut:0代表禁止登录,1代表允许登录 ''' def select_action(self, state): valu = self.cnEn.is_float(state) self.frameElem.from_frame_to_otherFrame("rigthFrame") if valu == '1': self.getElem.find_element_wait_and_click_EC("id", "ruleTypePass") elif valu == '0': self.getElem.find_element_wait_and_click_EC("id", "ruleTypeDeny") u'''点击保存''' def click_save_retime(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_click_EC("id", "save_rule_time") u'''填写检索的资源名称 Parameters: - rename:资源名称 ''' def set_query_rename(self, rename): resname = self.cnEn.is_float(rename) self.frameElem.from_frame_to_otherFrame("artIframe") self.getElem.find_element_wait_and_clear_EC("id", "fortResourceName") self.getElem.find_element_wait_and_sendkeys("id", "fortResourceName", resname) u'''勾选某个资源 Parameters: - rename:资源名称 ''' def check_resource(self, rename): self.frameElem.from_frame_to_otherFrame("artIframe") self.set_query_rename(rename) self.command.click_check_resource() self.getElem.find_element_wait_and_click_EC("id", "resource_check_all") self.command.check_sure_button() u'''点击操作的公共方法 parameter: - value:序号 - statu:代表点击的操作,1代表勾选复选框;2代表上移;3代表下移;4代表插入;5代表编辑 ''' def click_option_method(self, value, status): self.frameElem.from_frame_to_otherFrame("rigthFrame") valu = self.cnEn.is_float(value) statu = self.cnEn.is_float(status) # 获取table对象 tableelem = self.getElem.find_element_with_wait_EC( "id", "content_table") # 获取table对象下的所有tr trelems = tableelem.find_elements_by_tag_name("tr") # 位于第几行 line = 0 # 循环所有tr for trelem in trelems: line += 1 # 找到tr下所有td对象 tds = trelem.find_elements_by_tag_name("td") # 获取td[2]的文本 tdtext = tds[1].text if tdtext == valu: #勾选复选框 if statu == '1': xpath = ".//*[@id='content_table']/tbody/tr[" + str( line) + "]/td[1]/input[1]" #上移 elif statu == '2': xpath = ".//*[@id='content_table']/tbody/tr[" + str( line) + "]/td[8]/a[1]" #下移 elif statu == '3': xpath = ".//*[@id='content_table']/tbody/tr[" + str( line) + "]/td[8]/a[2]" #插入 elif statu == '4': xpath = ".//*[@id='content_table']/tbody/tr[" + str( line) + "]/td[8]/a[3]" #编辑 elif statu == '5': xpath = ".//*[@id='content_table']/tbody/tr[" + str( line) + "]/td[8]/a[4]" self.getElem.find_element_wait_and_click_EC("xpath", xpath) break u'''校验资源时间规则结果 parameter: - data:数据集 ''' def check_resource_time_rule(self, data): self.frameElem.from_frame_to_otherFrame("rigthFrame") row = self.acproval.select_resoure_sso(data[1]) xpath = "//*[@id='content_table']/tbody/tr[" + str( row * 2) + "]/td/div/table/tbody/tr/td[2]/a[1]/img" isExsit = self.getElem.is_element_exsit("xpath", xpath) if isExsit == True: self.log.log_detail(data[0], True) else: self.log.log_detail(data[0], True)
class RetimeRule(object): def __init__(self, driver): self.driver = driver self.getElem = getElement(driver) self.selectElem = selectElement(driver) self.frameElem = frameElement(driver) self.cnEn = cnEncode() self.acproval = Accapproval(driver) self.command = CommandRule(driver) self.log = log() u'''点击删除''' def click_bulkdel_retime(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_click_EC("id", "delete_rule_time_resource") u'''选择默认动作 Parameters: - staut:0代表禁止登录,1代表允许登录 ''' def select_default_type(self, state): try: valu = self.cnEn.is_float(state) self.frameElem.from_frame_to_otherFrame("rigthFrame") selem = self.getElem.find_element_with_wait_EC("id", "defaultType") self.selectElem.select_element_by_value(selem, valu) except Exception: print("Select default action failure") u'''点击运行状态''' def click_running_state(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_click_EC("id", "ruleState") u'''填写每月开始日期 Parameters: - starttime:每月的开始时间 ''' def set_month_start_time(self, starttime): valu = self.cnEn.is_float(starttime) self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_clear_EC("id", "fortMonthStartTime") self.getElem.find_element_wait_and_sendkeys("id", "fortMonthStartTime", valu) u'''填写每月结束日期 Parameters: - endtime:每月的结束时间 ''' def set_month_end_time(self, endtime): valu = self.cnEn.is_float(endtime) self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_clear_EC("id", "fortMonthEndTime") self.getElem.find_element_wait_and_sendkeys("id", "fortMonthEndTime", valu) u'''选择每周开始日期 Parameters: - starttime:每周的开始时间 ''' def set_week_start_time(self, starttime): valu = self.cnEn.is_float(starttime) self.frameElem.from_frame_to_otherFrame("rigthFrame") selem = self.getElem.find_element_with_wait_EC("id", "fortWeekStartTime") self.selectElem.select_element_by_value(selem, valu) u'''选择每周结束日期 Parameters: - endtime:每周的结束时间 ''' def set_week_end_time(self, endtime): valu = self.cnEn.is_float(endtime) self.frameElem.from_frame_to_otherFrame("rigthFrame") selem = self.getElem.find_element_with_wait_EC("id", "fortWeekEndTime") self.selectElem.select_element_by_value(selem, valu) u'''填写每天开始时间 Parameters: - starttime:每天的开始时间 ''' def set_day_start_time(self, starttime): valu = self.cnEn.is_float(starttime) self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_clear_EC("id", "fortDayStartTime") self.getElem.find_element_wait_and_sendkeys("id", "fortDayStartTime", valu) u'''填写每天结束时间 Parameters: - endtime:每天的结束时间 ''' def set_day_end_time(self, endtime): valu = self.cnEn.is_float(endtime) self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_clear_EC("id", "fortDayEndTime") self.getElem.find_element_wait_and_sendkeys("id", "fortDayEndTime", valu) u'''选择动作 Parameters: - staut:0代表禁止登录,1代表允许登录 ''' def select_action(self, state): valu = self.cnEn.is_float(state) self.frameElem.from_frame_to_otherFrame("rigthFrame") if valu == '1': self.getElem.find_element_wait_and_click_EC("id", "ruleTypePass") elif valu == '0': self.getElem.find_element_wait_and_click_EC("id", "ruleTypeDeny") u'''点击保存''' def click_save_retime(self): self.frameElem.from_frame_to_otherFrame("rigthFrame") self.getElem.find_element_wait_and_click_EC("id", "save_rule_time") u'''填写检索的资源名称 Parameters: - rename:资源名称 ''' def set_query_rename(self, rename): resname = self.cnEn.is_float(rename) self.frameElem.from_frame_to_otherFrame("artIframe") self.getElem.find_element_wait_and_clear_EC("id", "fortResourceName") self.getElem.find_element_wait_and_sendkeys("id", "fortResourceName", resname) u'''勾选某个资源 Parameters: - rename:资源名称 ''' def check_resource(self, rename): self.frameElem.from_frame_to_otherFrame("artIframe") self.set_query_rename(rename) self.command.click_check_resource() self.getElem.find_element_wait_and_click_EC("id", "resource_check_all") self.command.check_sure_button() u'''点击操作的公共方法 parameter: - value:序号 - statu:代表点击的操作,1代表勾选复选框;2代表上移;3代表下移;4代表插入;5代表编辑 ''' def click_option_method(self, value, status): self.frameElem.from_frame_to_otherFrame("rigthFrame") valu = self.cnEn.is_float(value) statu = self.cnEn.is_float(status) # 获取table对象 tableelem = self.getElem.find_element_with_wait_EC("id", "content_table") # 获取table对象下的所有tr trelems = tableelem.find_elements_by_tag_name("tr") # 位于第几行 line = 0 # 循环所有tr for trelem in trelems: line += 1 # 找到tr下所有td对象 tds = trelem.find_elements_by_tag_name("td") # 获取td[2]的文本 tdtext = tds[1].text if tdtext == valu: #勾选复选框 if statu == '1': xpath = ".//*[@id='content_table']/tbody/tr[" + str(line) + "]/td[1]/input[1]" #上移 elif statu == '2': xpath = ".//*[@id='content_table']/tbody/tr[" + str(line) + "]/td[8]/a[1]" #下移 elif statu == '3': xpath = ".//*[@id='content_table']/tbody/tr[" + str(line) + "]/td[8]/a[2]" #插入 elif statu == '4': xpath = ".//*[@id='content_table']/tbody/tr[" + str(line) + "]/td[8]/a[3]" #编辑 elif statu == '5': xpath = ".//*[@id='content_table']/tbody/tr[" + str(line) + "]/td[8]/a[4]" self.getElem.find_element_wait_and_click_EC("xpath", xpath) break u'''校验资源时间规则结果 parameter: - data:数据集 ''' def check_resource_time_rule(self, data): self.frameElem.from_frame_to_otherFrame("rigthFrame") row = self.acproval.select_resoure_sso(data[1]) xpath = "//*[@id='content_table']/tbody/tr[" + str(row*2) + "]/td/div/table/tbody/tr/td[2]/a[1]/img" isExsit = self.getElem.is_element_exsit("xpath", xpath) if isExsit == True: self.log.log_detail(data[0], True) else: self.log.log_detail(data[0], True)
class testRetime(object): def __init__(self, driver): self.driver = driver self.log = log() self.cmf = commonFun(driver) self.frameElem = frameElement(driver) self.testrole = testRole(driver) self.command = CommandRule(driver) self.comsuit = CommonSuiteData(driver) self.timerule = TimeRule(driver) self.retime = RetimeRule(driver) u'''获取测试数据 Parameters: - sheetname:sheet名称 return:表格数据 ''' def get_table_data(self, sheetname): dataFile = dataFileName() retrulePath = dataFile.get_retime_test_data_url() retruleData = dataFile.get_data(retrulePath, sheetname) return retruleData u'''添加资源时间规则''' def add_retime_rule_001(self): #日志开始记录 self.log.log_start("add_retime_rule") #获取添加资源时间规则测试数据 retruleData = self.get_table_data("add_retime_rule") #保存成功的弹出框 comrulMsg = self.testrole.popup() #无检查点的测试项标识,如果为True说明通过 flag = False for dataRow in range(len(retruleData)): data = retruleData[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: self.command.click_add_button() if dataRow == 3: self.retime.click_running_state() self.timerule.start_date(data[2]) self.timerule.date_of_termination(data[4], data[5]) self.retime.set_month_start_time(data[6]) self.retime.set_month_end_time(data[7]) self.retime.set_week_start_time(data[8]) self.retime.set_week_end_time(data[9]) self.retime.set_day_start_time(data[10]) self.retime.set_day_end_time(data[11]) self.retime.select_action(data[12]) self.command.click_add_users_button() self.command.check_all_user() self.command.click_add_resource_button() self.retime.check_resource(data[13]) self.retime.click_save_retime() self.frameElem.switch_to_content() self.cmf.test_win_check_point("xpath", comrulMsg, data, flag) self.command.click_back_command() except Exception as e: print("add_retime_rule fail:" + str(e)) self.log.log_end("add_retime_rule") u'''编辑资源时间规则''' def mod_retime_rule_002(self): #日志开始记录 self.log.log_start("mod_retime_rule") #获取编辑资源时间规则测试数据 retruleData = self.get_table_data("mod_retime_rule") #保存成功的弹出框 comrulMsg = self.testrole.popup() #无检查点的测试项标识,如果为True说明通过 flag = False for dataRow in range(len(retruleData)): data = retruleData[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: self.retime.click_option_method(data[2], data[3]) self.retime.select_action(data[4]) self.retime.click_save_retime() self.frameElem.switch_to_content() self.cmf.test_win_check_point("xpath", comrulMsg, data, flag) self.command.click_back_command() except Exception as e: print("mod_retime_rule fail:" + str(e)) self.log.log_end("mod_retime_rule") u'''资源时间规则结果''' def add_retime_rule_result_003(self): self.frameElem.from_frame_to_otherFrame("topFrame") self.cmf.select_role_by_text(u"运维操作员") #日志开始记录 self.log.log_start("add_retime_rule_result") #获取资源时间审批测试数据 retruleData = self.get_table_data("add_retime_rule_result") for dataRow in range(len(retruleData)): data = retruleData[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: self.retime.check_resource_time_rule(data) except Exception as e: print("add_retime_rule_result fail:" + str(e)) self.log.log_end("add_retime_rule_result") u'''操作资源时间规则''' def option_retime_rule_004(self): self.comsuit.sys_switch_to_dep() self.comsuit.switch_to_moudle(u"运维管理", u"规则定义") self.command.click_left_rule(3) #日志开始记录 self.log.log_start("option_retime_rule") #获取操作资源时间规则测试数据 retruleData = self.get_table_data("option_retime_rule") #保存成功的弹出框 comrulMsg = self.testrole.popup() #无检查点的测试项标识,如果为True说明通过 flag = False for dataRow in range(len(retruleData)): data = retruleData[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: if dataRow == 1: self.retime.click_bulkdel_retime() elif dataRow == 2 or dataRow == 3: self.retime.click_option_method(data[2], data[3]) elif dataRow == 4 or dataRow == 5: time.sleep(5) self.retime.click_option_method(data[2], data[3]) self.command.set_row_command(data[4]) self.command.check_sure_button() self.frameElem.switch_to_content() self.cmf.test_win_check_point("xpath", comrulMsg, data, flag) time.sleep(3) self.command.click_cancel_button() continue self.frameElem.switch_to_content() self.cmf.test_win_check_point("xpath", comrulMsg, data, flag) except Exception as e: print("option_retime_rule fail:" + str(e)) self.log.log_end("option_retime_rule") u'''校验资源时间规则''' def check_retime_rule_005(self): #日志开始记录 self.log.log_start("check_retime_rule") #获取校验资源时间规则测试数据 retruleData = self.get_table_data("check_retime_rule") #保存成功的弹出框 comrulMsg = self.testrole.popup() self.command.click_add_button() #无检查点的测试项标识,如果为True说明通过 flag = False for dataRow in range(len(retruleData)): data = retruleData[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: if 2 <= dataRow <= 4: if dataRow != 4: self.timerule.start_date(data[2], data[3]) else: self.timerule.start_date(data[2]) if dataRow != 2: self.timerule.date_of_termination(data[4], data[5]) elif 5 <= dataRow <= 11: if dataRow == 5: self.timerule.date_of_termination(data[4], data[5]) self.retime.set_month_start_time(data[6]) self.retime.set_month_end_time(data[7]) if dataRow == 11: self.retime.set_day_start_time(data[8]) elif 12 <= dataRow <= 17: self.retime.set_day_start_time(data[8]) self.retime.set_day_end_time(data[9]) elif dataRow == 18: self.command.click_add_users_button() self.command.check_all_user() self.retime.click_save_retime() self.frameElem.switch_to_content() self.cmf.test_win_check_point("xpath", comrulMsg, data, flag) except Exception as e: print("check_retime_rule fail:" + str(e)) self.command.click_back_command() self.log.log_end("check_retime_rule") u'''删除资源时间规则''' def del_retime_rule_006(self): #日志开始记录 self.log.log_start("del_retime_rule") #获取删除资源时间规则测试数据 retruleData = self.get_table_data("del_retime_rule") #保存成功的弹出框 comrulMsg = self.testrole.popup() #无检查点的测试项标识,如果为True说明通过 flag = False for dataRow in range(len(retruleData)): data = retruleData[dataRow] try: #如果不是第一行标题,则读取数据 if dataRow != 0: self.retime.click_option_method(data[2], data[3]) self.retime.click_bulkdel_retime() self.frameElem.switch_to_content() self.cmf.test_win_check_point("xpath", comrulMsg, data, flag) self.cmf.click_login_msg_button() except Exception as e: print("del_retime_rule fail:" + str(e)) self.log.log_end("del_retime_rule")