*** Settings *** Library Selenium2Library Resource Element.robot Resource Common.robot Variables ../config/myConfig.py Library DateTime Library ../Script/mssqlTest.py *** Keywords *** 登录黑方 Open Browser ${unbackupIP} ${browser} Maximize Browser Window Wait Until Element Is Visible ${login_slogan} 30s 黑方打开失败 输入文本 ${input_userName} ${login_username} 输入文本 ${input_passwd} ${login_passwd} 点击按钮 ${btn_login} Wait Until Element Is Visible ${button_loginmessage} 30s 黑方登录失败 Log 黑方登录成功 创建Sqlserver副本备份策略 Wait Until Element Is Visible ${button_sideNav_cdm} 30s 副本数据管理模块不存在 点击按钮 ${button_sideNav_cdm} Wait Until Element Is Visible ${cdm_sideNav_all} 30s 副本数据管理模块页面异常 # 选中SqlserverCDM代理机 输入文本 ${cdm_inputSuccess2} ${hostname} 点击按钮 xpath=//span[text()='${hostname}'] Wait Until Element Is Visible ${cdm_tab_policy_li} 10s 定时数据保护页面打开异常 # 新建策略 点击按钮 ${cdm_newpolicy} Wait Until Element Is Visible ${mssql_newpolicy_title} 5s 新建备份策略弹窗未打开 Wait Until Element Is Visible ${mssql_newpolicy_type} 5s mssql副本组件未安装 # 点击mssql副本组件 点击按钮 ${mssql_newpolicy_type} Wait Until Element Is Visible ${mssql_newpolicy_goStep1} 5s 连接凭据页面未发现 # 连接凭据 输入文本 ${mssql_newpolicy_goStep1_PolicyName} ${PolicyName} 点击按钮 ${mssql_newpolicy_goStep1_nextStep2_btn} # 实例选择 Wait Until Element Is Visible ${mssql_newpolicy_goStep2} 5s 实例选择页面未发现 点击按钮 ${mssql_newpolicy_goStep2_nextStep3_btn} # 目标数据库 Wait Until Element Is Visible ${mssql_newpolicy_goStep3} 5s 目标数据库页面未发现 点击按钮 ${mssql_newpolicy_goStep3_database_all} # 目标数据库-过滤设置 点击按钮 ${mssql_newpolicy_goStep3_filterBtn_btn} Wait Until Element Is Visible ${mssql_newpolicy_goStep3_baseFilterSel_btn} 5s 过滤设置-数据库过滤页面未发现 Wait Until Element Is Visible ${mssql_newpolicy_goStep3_baseFilterKey_btn} 5s 过滤设置-关键字过滤页面未发现 点击按钮 ${mssql_newpolicy_goStep3_baseFilterKey_btn} Wait Until Element Is Visible ${mssql_newpolicy_goStep3_baseFilterKey_keyFilterCon} 5s 过滤设置-关键字过滤未打开 输入文本 ${mssql_newpolicy_goStep3_baseFilterKey_keyFilterCon} ${keyFilter} 点击按钮 ${mssql_newpolicy_goStep3_baseFilterKey_addkeyFilter} 点击按钮 ${mssql_newpolicy_goStep3_baseFilterKey_addkeyFilterSure_btn} 点击按钮 ${mssql_newpolicy_goStep3_nextStep4_btn} # 任务周期 Wait Until Element Is Visible ${mssql_newpolicy_goStep4} 5s 目标数据库页面未发现 点击按钮 ${mssql_newpolicy_goStep4_AddTaskCycle} 点击按钮 ${mssql_newpolicy_goStep4_AddTaskCycle_sunday} 点击按钮 ${mssql_newpolicy_goStep4_AddTaskCycle_Sure_btn} 点击按钮 ${mssql_newpolicy_goStep4_nextStep5_btn} # 备份集存储 Wait Until Element Is Visible ${mssql_newpolicy_goStep5} 5s 设置存储路径页面未发现 点击按钮 ${mssql_newpolicy_goStep5_nextStep6_btn} # 备份高级选项 Wait Until Element Is Visible ${mssql_newpolicy_goStep6} 5s 设置存储路径页面未发现 点击按钮 ${mssql_newpolicy_goStep6_next_btn} # 添加成功 Wait Until Element Is Visible ${mssql_newpolicy_addsucess} 10s 点击按钮 ${mssql_define_btn} Log 已经创建备份策略:${PolicyName} 执行备份任务并校验 # 选择上面创建的策略并运行 输入文本 ${policy_input_backupNameSearch} ${PolicyName} # 点击查询 点击按钮 ${policy_btn_backContentSearch} Sleep 2s Element Text Should Be ${policy_table_firstname} ${PolicyName} 点击按钮 ${policy_run} Wait Until Element Is Visible ${policy_run_title} 5s 立即执行窗口未打开 Select From List By Label ${policy_run_select} ${policy_run_select_type} Sleep 2s 点击按钮 ${policy_run_executePolicyExecute_btn} Wait Until Element Is Visible ${policy_run_msg} 10s 添加成功窗口未打开 点击按钮 ${mssql_define_btn} 作业校验 ${PolicyName} 作业校验 [Arguments] ${workname} # 切换到作业 点击按钮 ${cdm_tab_work_li} Wait Until Element Is Visible ${cdm_tab_work_export_btn} 10s 作业页面打开异常 # 输入策略查询 输入文本 ${cdm_tab_work_PolicyName} ${workname} 点击按钮 ${cdm_tab_work_search_span} # 确认创建成功了 FOR ${counter} IN RANGE 60 Log ${counter} ${select_text}= Execute Javascript return ${task_select_count} Log 查询到的作业个数:${select_text} IF '${select_text}' >= '2' BREAK Sleep 2s 点击按钮 ${cdm_tab_work_search_span} END Log 作业创建成功,正在运行中 # 等待运行完成 FOR ${index} IN RANGE 300 Log 第${index}次查询作业状态 ${task_run}= Execute Javascript return ${task_status} Log 作业状态:${task_run} Exit For Loop If '${task_run}' == '成功' or '${task_run}' == '失败' Sleep 2s 点击按钮 ${cdm_tab_work_search_span} END Should Be Equal As Strings ${task_run} 成功 任务运行失败 Log 作业策略执行成功 创建恢复任务并校验 # 进入备份集页面 点击按钮 ${cdm_tab_backupset_li} # 按照策略查询备份集 输入文本 ${policy_input_backTabPolicy} ${PolicyName} 点击按钮 ${cdm_tab_backupset_search_span} # 点击操作 点击按钮 id=backupAction_${PolicyName} Wait Until Element Is Visible id=cdmBkset_recovery_${PolicyName} 10s 操作按钮异常 # 恢复 点击按钮 id=cdmBkset_recovery_${PolicyName} Wait Until Element Is Visible ${cdm_tab_recovery_step1} 10s 恢复页面未打开 # 恢复目标 点击按钮 ${cdm_tab_recovery_step1_next_btn} # 实列选择 Wait Until Element Is Visible ${cdm_tab_recovery_step2_next_btn} 10s 实列选择页面异常 点击按钮 ${cdm_tab_recovery_step2_next_btn} # 选择目标数据库 Wait Until Element Is Visible ${cdm_tab_recovery_step3_next_btn} 10s 选择目标数据库页面异常 点击按钮 ${mssql_recovery_goStep3_database_all} 点击按钮 ${cdm_tab_recovery_step3_next_btn} # 高级选项 Wait Until Element Is Visible ${cdm_tab_recovery_step4_title} 10s 高级选项页面异常 输入文本 ${cdm_tab_recovery_step4_recTargetPath} ${recTargetPath} 点击按钮 ${cdm_tab_recovery_step4_next_btn} Wait Until Element Is Visible ${cdm_tab_recovery_step4_finish_title} 10s 确认恢复页面未出现 点击按钮 ${cdm_tab_recovery_step4_finish_btn} Wait Until Element Is Visible ${recovery_run_msg} 10s 添加成功窗口未打开 点击按钮 ${mssql_define_btn} Log 恢复作业已经创建 ${Date}= Get Current Date result_format=%Y-%m-%d %H:%M ${recoveryname}= Catenate SEPARATOR= 恢复策略 ${Date[:-1]} Log ${recoveryname} 作业校验 ${recoveryname} 初始化数据库 # 创建数据库 mssqlTest.Create Database # 创建表 mssqlTest.Create Table # 插入数据 mssqlTest.Insert Data Table # 查询插入的结果 ${select_result}= mssqlTest.Get Insert Res Log 查询到的结果是:${select_result} Set Global Variable ${first_result} ${select_result} 删除表确认该表不存在 # 先确认表是否存在 ${table_status1}= mssqlTest.Check Table Exists Should Be True ${table_status1} 要删除的表不存在 Log TABLE_TEST表存在,开始做删除表操作 mssqlTest.Drop Table # 删除后检查 ${table_status2}= mssqlTest.Check Table Exists Should Not Be True ${table_status2} 删除失败,删除的表还能查询到 Log TABLE_TEST已删除 校验恢复结果 # 先确认表是否存在 ${table_status}= mssqlTest.Check Table Exists Should Be True ${table_status} 要检查的表不存在,请确认恢复结果 Log 表已经恢复成功,开始检查表结果 # 查询插入的结果 ${select_result}= mssqlTest.Get Insert Res Log 查询到的结果是:${select_result} # 将其与之前的结果做对比 Should Be Equal As Strings ${first_result} ${select_result} 恢复前后的结果不匹配 Log 恢复成功,恢复结果与预期一致