summaryrefslogtreecommitdiff
path: root/keyword
diff options
context:
space:
mode:
authordongxiaoyan <[email protected]>2021-06-15 19:37:46 +0800
committerdongxiaoyan <[email protected]>2021-06-15 19:37:46 +0800
commit0847bdd64d47f18ca995a81d3560b4bae9b04e1b (patch)
tree6def734f9ecb7fc2a97196f5e48839ae6c1dd0d6 /keyword
parent3c8341971455d3d1b0981607426cff9674496c0b (diff)
基于UI的tsg集成测试脚本初始化HEADmaster
Diffstat (limited to 'keyword')
-rw-r--r--keyword/common/login_logout.robot82
-rw-r--r--keyword/common/login_logout_switch.robot22
-rw-r--r--keyword/common/page.robot242
-rw-r--r--keyword/profiles/profiles.robot69
4 files changed, 415 insertions, 0 deletions
diff --git a/keyword/common/login_logout.robot b/keyword/common/login_logout.robot
new file mode 100644
index 0000000..8b309e5
--- /dev/null
+++ b/keyword/common/login_logout.robot
@@ -0,0 +1,82 @@
+*** Settings ***
+Library Selenium2Library
+Resource ../../variable/common_variable.txt
+
+*** Keywords ***
+
+Login
+ Open Browser http://${host}/#/login ${browserType}
+ Maximize Browser Window
+ ClearCache
+ input text xpath=//*[@id="app"]/div/div[2]/div/div[2]/div/input ${username}
+ input text xpath=//*[@id="app"]/div/div[2]/div/div[3]/div/input ${password}
+ Click button id=login
+ PasswordPrompt #判断是否有密码过期的提示
+
+ClearCache
+ ${status} Run Keyword And Return Status Page Should Contain After update the version, you need to clear the cache and log in again, otherwise some functions will not be available. #判断页面是否包含该文本
+ run keyword if "${status}"=="True" click element xpath=/html/body/div[2]/div/div[3]/button[2]
+ run keyword if "${status}"=="False" log 不用进行清除缓存
+
+PasswordPrompt
+ [Arguments] ${passwd}=null ${day}=100 ${editpasswd}=no
+ ${status} Run Keyword And Return Status Page Should Contain Does the password need to be changed when the password expires? #判断页面是否包含该文本
+ run keyword if "${status}"=="True" run keywords PasswordPromptTrue ${passwd} ${day} ${editpasswd}
+ run keyword if "${status}"=="False" log 密码未过期
+ Wait Until Element Is Visible id=dashboard 20
+
+PasswordPromptTrue
+ [Arguments] ${passwd} ${day} ${editpasswd}
+ run keyword if "${editpasswd}"=="yes" run keywords sleep 1
+ ... AND click element xpath=/html/body/div[2]/div/div[3]/button[2]
+ ... AND sleep 1
+ ... AND ChangePassword ${passwd} ${day}
+ ... ELSE IF "${editpasswd}"=="no" run keywords sleep 1
+ ... AND click element xpath=/html/body/div[2]/div/div[3]/button[1]
+ ... AND sleep 1
+
+ChangePassword
+ [Arguments] ${passwd} ${day} ${Required-Password-Change}=close
+ #判断是否修改密码
+ run keyword if "${passwd}"!="null" Run Keywords sleep 1
+ ... AND input text xpath=//*[@id="app"]/div/div[3]/div[1]/div/div/div[1]/div/div/div[1]/div/div/div[1]/div[2]/form/div[3]/div/div/input ${passwd}
+ ... AND sleep 1
+ ... AND input text xpath=//*[@id="app"]/div/div[3]/div[1]/div/div/div[1]/div/div/div[1]/div/div/div[1]/div[2]/form/div[4]/div/div/input ${passwd}
+ ... AND sleep 1
+ ${class}= Get Element Attribute xpath=//*[@id="app"]/div/div[3]/div[1]/div/div/div[1]/div/div/div[1]/div/div/div[1]/div[2]/form/div[5]/div/div class #获取Required-Password-Change按钮的class元素的值
+ #通过元素的值判断按钮是开启状态还是关闭状态
+ run keyword if "${Required-Password-Change}"=="open" and "${class}"=="el-switch is-checked" Run Keywords log 按钮为开启状态,不进行操作
+ ... AND sleep 1
+ ... AND input text xpath=//*[@id="app"]/div/div[3]/div[1]/div/div/div[1]/div/div/div[1]/div/div/div[1]/div[2]/form/div[6]/div/div/input ${day}
+ ... AND sleep 1
+ run keyword if "${Required-Password-Change}"=="open" and "${class}"=="el-switch" Run Keywords log 按钮为关闭状态,需要点击开启
+ ... AND sleep 1
+ ... AND input text xpath=//*[@id="app"]/div/div[3]/div[1]/div/div/div[1]/div/div/div[1]/div/div/div[1]/div[2]/form/div[6]/div/div/input ${day}
+ ... AND sleep 1
+ run keyword if "${Required-Password-Change}"=="close" and "${class}"=="el-switch is-checked" Run Keywords log 按钮为开启状态,需要点击关闭
+ ... AND sleep 1
+ ... AND click element xpath=xpath=//*[@id="app"]/div/div[3]/div[1]/div/div/div[1]/div/div/div[1]/div/div/div[1]/div[2]/form/div[5]/div/div
+ run keyword if "${Required-Password-Change}"=="close" and "${class}"=="el-switch" log 按钮为关闭状态,不进行操作
+ sleep 1
+ click element xpath=//*[@id="app"]/div/div[3]/div[1]/div/div/div[1]/div/div/div[1]/div/div/div[2]/button[1]
+
+Logout
+ #Mouse Hover xpath=//*[@id="app"]/div/div[1]/div[2]/div/span/div/span
+ #/html/body/div[1]/div/div[1]/div[2]/div/span[2]/div/span
+ Mouse Hover xpath=//*[@id="user_avator"]/span
+ sleep 0.5
+ click element xpath=//div[@id='SignOut']
+ sleep 2
+ Close All Browsers
+
+UiLoginAndAddLocalIP
+ log UiLoginAndAddLocalIP
+ Login
+ # Run Keyword If ${addTestClentIPFlag}==1 AddLocalIp
+ log UiLoginAndAddLocalIP:${LocahIPName}
+
+
+UiLogoutAndDelLocalIP
+ log UiLogoutAndDelLocalIP
+ # Run Keyword If ${addTestClentIPFlag}==1 DeletePage ${LocahIPName}
+ Logout \ No newline at end of file
diff --git a/keyword/common/login_logout_switch.robot b/keyword/common/login_logout_switch.robot
new file mode 100644
index 0000000..646ac5e
--- /dev/null
+++ b/keyword/common/login_logout_switch.robot
@@ -0,0 +1,22 @@
+*** Settings ***
+Resource ../../variable/common_variable.txt
+Library Collections
+Resource login_logout.robot
+#Resource logout.robot
+#Resource login.robot
+
+
+*** Keywords ***
+LoginAndAddLocalIP
+ [Tags] tsg_adc tsg_bf_api tsg_device tsg_adc_wp adc_api adc_verify adc_log
+ #[Tags] 分步骤之外的全流程 毕方接口 设备相关 分步骤全部 分步骤策略 分步骤功能端验证 分步骤日志验证
+ # 获取主机IP
+ #${ip} Get Host IP
+ #Run Keyword If '${ip}' != '${EMPTY}' Set Global Variable ${testClentIP} ${ip}
+
+ Run Keyword If '${loginType}' == 'ui' UiLoginAndAddLocalIP
+
+
+LogoutAndDelLocalIP
+ [Tags] tsg_adc tsg_bf_api tsg_device tsg_adc_wp adc_api adc_verify adc_log
+ Run Keyword If '${loginType}' == 'ui' UiLogoutAndDelLocalIP
diff --git a/keyword/common/page.robot b/keyword/common/page.robot
new file mode 100644
index 0000000..1888a9e
--- /dev/null
+++ b/keyword/common/page.robot
@@ -0,0 +1,242 @@
+*** Settings ***
+Library yaml
+Library OperatingSystem
+Library Selenium2Library
+Library Collections
+Resource ../../variable/common_variable.txt
+Library ../../customlib/common/type_judgment.py
+
+*** Keywords ***
+YamlLoad
+ [Arguments] ${filepath}
+ [Documentation] 读取yaml文件
+ ... ${filepath}:文件路径
+ ${Yaml}= Get File ${filepath}
+ ${Loaded}= yaml.Safe Load ${Yaml}
+ [Return] ${Loaded}
+
+CreateOrEditPage
+ [Arguments] ${elementList} ${dataList} ${OpenCreateOrEditPage} ${OkOrCance}
+ [Documentation] 完整的打开创建或者修改数据页面,并进行操作(创建数据、修改数据)
+ ... ${elementList}:模板的PageData数据,格式:[{id=responsepages_profileName1,value=testname}]
+ ... ${dataList}:数据文件中的数据,格式[[id=responsepages_profileName1,value=testname]]
+ ... ${OpenCreateOrEditPage}:模板文件中OpenCreateOrEditPage数据
+ ... ${OkOrCance}:模板文件中OkOrCancel的数据
+
+ FOR ${data} IN @{dataList}
+ OperatPage ${elementList} ${data} ${OpenCreateOrEditPage}
+ OkOrCancel ${OkOrCance} ${data}[profileName]
+ END
+ ${deletePosition} Get From Dictionary ${OkOrCance} delete
+ DeleteData ${deletePosition}
+
+OperatPage
+ [Arguments] ${elementList} ${pData} ${OpenCreateOrEditPage}
+ [Documentation] 打开创建或者修改数据页面,输入数据
+ ... ${elementList}:模板的PageData数据,格式:[{id=responsepages_profileName1,value=testname}]
+ ... ${pData}:数据文件中的数据,格式[id=responsepages_profileName1,value=testname]
+ ... ${OpenCreateOrEditPage}:模板文件中OpenCreateOrEditPage数据
+
+ ${openType} Get From Dictionary ${pData} operatingType
+ OpenCreateOREdit ${OpenCreateOrEditPage}[${openType}]
+ FOR ${element} IN @{elementList}
+ ${type} Get From Dictionary ${element} type
+ ${elementId} Get From Dictionary ${element} position
+ ${value} Get From Dictionary ${element} value
+ ${elementValue} Get From Dictionary ${pData} ${value}
+ ${return} ${elementData} Run Keyword And Ignore Error Get From Dictionary ${element} data
+ ${elementData} Run Keyword If "${return}"=="FAIL" or "${elementData}"=="${EMPTY}" set variable null
+ ... ELSE set variable ${elementData}
+ ${return} ${default} Run Keyword And Ignore Error Get From Dictionary ${element} default
+ ${default} Run Keyword If "${return}"=="FAIL" or "${default}"=="${EMPTY}" set variable null
+ ... ELSE set variable ${default}
+ Operation ${type} ${elementId} ${elementValue} ${elementData} ${default}
+ END
+
+OpenCreateOREdit
+ [Arguments] ${menuIdList}
+ [Documentation] 点击新增或修改按钮
+ ... ${menuIdList}:打开目标界面需要点击的所有按钮,顺序输入
+
+ FOR ${menuId} IN @{menuIdList}
+ sleep ${sleep}
+ #Wait Until Element Is Enabled id=${menuId} ${sleep_Wait}
+ click element ${menuId}
+ END
+ sleep ${sleep}
+
+Operation
+ [Arguments] ${type} ${positioning} ${dataValue}=null ${elementData}=null ${default}=null
+ [Documentation] 根据type进行操作
+ ... ${type}:操作类型
+ ... ${positioning}:操作的元素定位信息
+ ... ${dataValue}:输入、或者上传的数据信息
+ ... ${elementData} : 模板中的PageData中的data数据,当数据为嵌套数据时有该字段
+
+ Run Keyword If "${type}" == "input" input text ${positioning} ${dataValue}
+ ... ELSE IF "${type}" == "upload" Choose File ${positioning} ${path}data/scriptfile/${dataValue}
+ ... ELSE IF "${type}" == "combination" run keywords log 嵌套操作
+ ... AND OperatCombinationData ${dataValue} ${elementData} ${positioning}
+ ... ELSE IF "${type}" == "click" click element ${positioning}
+ ... ELSE IF "${type}" == "switch" run keywords log 开关按钮
+ ... AND SwitchButton ${positioning} ${dataValue} ${default}
+ ... ELSE IF "${type}" == "switchCombination" run keywords log 开关按钮,关闭或打开时进行操作
+ ... AND SwitchCombination ${positioning} ${dataValue} ${default} ${elementData}
+ ... ELSE IF "${type}" == "radioButton" log 单选按钮
+ ... AND RadioButton ${dataValue} ${elementData}
+ ... ELSE log 无法识别的类型
+ sleep ${sleep}
+
+OperatCombinationData
+ [Arguments] ${elementValue} ${templateData} ${positioning}
+ [Documentation] 多步骤嵌套动作方法,循环取出数据
+ ... ${elementValue}:数据文件中嵌套操作数据
+ ... ${templateData}:模板文件中嵌套数据data数据
+
+ FOR ${element} IN @{elementValue}
+ click element ${positioning}
+ sleep ${sleep}
+ ${elementList} create list ${element}
+ OperatCombination ${elementList} ${templateData}
+ END
+
+
+OperatCombination
+ [Arguments] ${elementValue} ${templateData}
+ [Documentation] 多步骤嵌套动作方法,递归执行该方法
+ ... ${elementValue}:数据文件中嵌套操作数据
+ ... ${templateData}:模板文件中嵌套数据data数据
+ ${dataValue} Set variable
+ ${dataValueKey} Set variable
+ FOR ${element} IN @{elementValue}
+ log ${element}
+ ${dataType} dataType ${element}
+ ${dataValue} Run keyword if "${dataType}" == "<class 'dict'>" get dictionary keys ${element}
+ log ${dataValue}
+ ${dataValueKey} Run keyword if "${dataType}" == "<class 'dict'>" Set variable ${dataValue}[0]
+ ... ELSE Set Variable ${element}
+ log ${dataValueKey}
+ ${re} CombinationLate ${templateData} ${dataValueKey}
+ ${type} Get From Dictionary ${re} type
+ ${elementId} Get From Dictionary ${re} position
+ ${data} Get From Dictionary ${re} data
+ log ${dataType}
+ ${value} Run keyword if "${dataType}" == "<class 'dict'>" Get From Dictionary ${element} ${dataValueKey}
+ ... ELSE IF "${dataType}" == "<class 'str'>" Set Variable null
+ ... ELSE log 非类型
+ log ${dataType}
+ # ${value} Get From Dictionary ${element} ${dataValueKey}
+ Operation ${type} ${elementId} ${value} ${data}
+ ${listType} dataType ${value}
+ log ${listType}
+ Run keyword if "${listType}" != "<class 'str'>" OperatCombination ${value} ${data}
+ END
+
+CombinationLate
+ [Arguments] ${elementData} ${dataValue}
+ [Documentation] 多步骤嵌套动作对比循环取出模板文件的value同数据文件中的值进行对比,并返回对比成功的key值
+
+ ${re} Set variable
+ FOR ${i} IN @{elementData}
+ ${re} Run keyword if "${i}[value]" == "${dataValue}" Set variable ${i}
+ END
+ [Return] ${re}
+
+SwitchButton
+ [Arguments] ${positioning} ${dataStatus} ${default}
+ [Documentation] 单选按钮操作
+ ... ${positioning}:单选按钮定位信息
+ ... ${dataStatus}:数据中按钮的状态
+ ... ${default}:模板中按钮的默认状态
+ Run Keyword If "${dataStatus}" == "${default}" log 状态相同不进行操作
+ ... ELSE click element ${positioning}
+
+SwitchCombination
+ [Arguments] ${positioning} ${datalist} ${default} ${elementData}
+ [Documentation] 开关按钮组合操作,关闭或打开时进行下一步操作
+ ... ${positioning}: 开关按钮定位信息
+ ... ${datalist}:数据中按钮的状态
+ ... ${default}:模板中按钮的默认状态
+ ... ${elementData}:模板中的PageData中的data数据,按钮状态改变进行下一步操作
+ FOR ${dataStatus} IN @{datalist}
+ ${dataType} dataType ${dataStatus}
+ ${dataValue} Run keyword if "${dataType}" == "<class 'dict'>" get dictionary keys ${dataStatus}
+ log ${dataValue}
+ ${dataValueKey} Run keyword if "${dataType}" == "<class 'dict'>" Set variable ${dataValue}[0]
+ ... ELSE IF Set Variable ${element}
+ ${data} Run keyword if "${dataType}" == "<class 'dict'>" Set variable ${dataStatus}[dataValueKey]
+ Run Keyword If "${dataValueKey}" == "${default}" log 状态相同不进行操作
+ ... ELSE SwitchCombinationOperation ${positioning} ${elementData} ${data}
+ END
+
+SwitchCombinationOperation
+ [Arguments] ${positioning} ${elementData} ${dataValue}
+ [Documentation] 根据开关状态进行下一步操作
+ ... ${positioning}:开关按钮定位信息
+ ... ${elementData}:模板中的PageData中的data数据,按钮状态改变进行下一步操作
+ ... ${dataValue} :数据文件中的操作数据
+ click element ${positioning}
+ sleep ${sleep}
+ ${type} Get From Dictionary ${elementData} type
+ ${elementId} Get From Dictionary ${elementData} position
+ ${data} Get From Dictionary ${elementData} data
+ ${value} Get From Dictionary ${elementData} value
+ Operation ${type} ${elementId} ${dataValue} ${data}
+
+RadioButton
+ [Arguments] ${dataValue} ${elementData}
+ [Documentation] 单选按钮操作
+ ... ${dataValue}:数据文件中单选按钮的名称
+ ... ${elementData}:模板中所有单选按钮的数据
+ FOR ${button} IN @{elementData}
+ ${type} Get From Dictionary ${button} type
+ ${position} Get From Dictionary ${button} position
+ ${value} Get From Dictionary ${button} value
+ Run Keyword If "${dataValue}" == "${value}" run keywords log 点击${value}按钮
+ ... AND Operation ${type} ${position}
+ END
+
+OkOrCancel
+ [Arguments] ${elementList} ${assertName}
+ [Documentation] 提交数据后校验
+ ... ${elementList}: 模板文件中OkOrCancel数据,用于点击ok按钮及创建成功校验
+ ... ${assertName}:断言数据
+ ... ${elementList}格式:[{id=responsepages_profileName1,value=testname}]
+
+ ${okBUutton} Get From Dictionary ${elementList} position
+ ${alerm} Get From Dictionary ${elementList} alerm
+ ${assertPosition} Get From Dictionary ${elementList} assertPosition
+ click element ${okBUutton} #点击OK缇交
+ Wait Until Element Is Enabled ${alerm} ${sleep_Wait}
+ Search ${assertName} name #搜索框的关键字
+ sleep ${sleep}
+ click element ${assertPosition}
+ ${text1} Get Text ${assertPosition} #获取点击后页面文本信息
+ Should Be Equal As Strings ${text1} ${assertName}
+
+Search
+ [Arguments] ${value} ${search}
+ [Documentation]
+ ... ${value}:传入查询的数据
+ ... ${search}:传入搜索框查询的类型
+
+ sleep ${sleep}
+ click element xpath=//*[@id="app"]/div/div[3]/div[2]/div/div[2]/div/div/div[1]/span/div/div/div[2]/div/div/div/input #点击搜索框
+ sleep ${sleep_min}
+ run keyword if "${search}"=="name" run keywords sleep ${sleep_min}
+ ... AND click element xpath=/html/body/div/div[1]/div[1]/ul/li[3]
+ ... AND input text xpath=//*[@id="app"]/div/div[3]/div[2]/div/div[2]/div/div/div[1]/span/div/div/div[2]/div/div[1]/div[3]/div/input ${value}
+ sleep ${sleep}
+ click element xpath=//*[@id="app"]/div/div[3]/div[2]/div/div[2]/div/div/div[1]/span/div/i #点击搜索按钮
+ sleep ${sleep}
+
+DeleteData
+ [Arguments] ${position}
+ [Documentation] 删除测试数据
+ ... ${position}:删除按钮元素定位
+ sleep ${sleep}
+ click element ${position}
+ sleep ${sleep}
+ click element xpath=/html/body/div/div/div[3]/button[2]
+ sleep ${sleep}
+
diff --git a/keyword/profiles/profiles.robot b/keyword/profiles/profiles.robot
new file mode 100644
index 0000000..3953d9f
--- /dev/null
+++ b/keyword/profiles/profiles.robot
@@ -0,0 +1,69 @@
+*** Settings ***
+Library Selenium2Library
+Library Collections
+Resource ../../variable/common_variable.txt
+
+*** Keywords ***
+ResponsePage
+ [Arguments] ${createOrEdit} ${name} ${filePath}
+ [Documentation]
+ ... ${createOrEdit}: 传入 “Create” 或者 “Edit” 来判断新建或者修改
+ ... ${name}:新建页面name输入框里的内容
+ ... ${filePath}:上传文件所在本地的路径
+
+ Run Keyword If "${createOrEdit}" == "Create" Run Keywords sleep 1
+ ... AND click element id=children6 #点击一级目录Settings
+ ... AND sleep ${sleep}
+ ... AND click element id=sidebarProxy_Profiles #点击二级目录Proxy Profiles
+ ... AND Wait Until Element Is Enabled id=responseAdd ${sleep_Wait}
+ ... AND click element id=responseAdd
+ Run Keyword If "${createOrEdit}" == "Edit" Run keywords sleep 1
+ ... AND click element xpath=//*[@id="ly-table1-listcontent"]/div/div[3]/table/tbody/tr[1]
+ ... AND sleep ${sleep}
+ ... AND click element id=resinseEdit
+ sleep ${sleep}
+ input text id=responsepages_profileName1 ${name} #输入name
+ Choose File xpath=//*[@id="policy_Manipulation_create6"]/div[2]/form/div/div/div/div/input ${filePath} #上传文件
+ sleep ${sleep}
+ click element id=responseAddOk1 #点击OK缇交
+ Wait Until Element Is Enabled id=responseAdd ${sleep_Wait}
+ Search ${name} name #搜索框的关键字
+ sleep ${sleep}
+ ${text1} Get Text xpath=//*[@id="ly-table1-listcontent"]/div/div[3]/table/tbody/tr/td[2]/div/div/span #获取点击后页面文本信息
+ Should Be Equal As Strings ${text1} ${name}
+
+
+Search
+ [Arguments] ${value} ${search}
+ [Documentation]
+ ... ${value}:传入查询的数据
+ ... ${search}:传入搜索框查询的类型
+ sleep ${sleep}
+ click element xpath=//*[@id="app"]/div/div[3]/div[2]/div/div[2]/div/div/div[1]/span/div/div/div[2]/div/div/div/input #点击搜索框
+ sleep ${sleep_min}
+ run keyword if "${search}"=="name" run keywords sleep ${sleep_min}
+ ... AND click element xpath=/html/body/div/div[1]/div[1]/ul/li[3]
+ ... AND input text xpath=//*[@id="app"]/div/div[3]/div[2]/div/div[2]/div/div/div[1]/span/div/div/div[2]/div/div[1]/div[3]/div/input ${value}
+ sleep ${sleep}
+ click element xpath=//*[@id="app"]/div/div[3]/div[2]/div/div[2]/div/div/div[1]/span/div/i #点击搜索按钮
+ sleep ${sleep}
+
+Delete
+ click element xpath=//*[@id="ly-table1-listcontent"]/div/div[3]/table/tbody/tr[1]
+ sleep ${sleep}
+ click element id=resinseDel
+ sleep ${sleep}
+ click element xpath=/html/body/div/div/div[3]/button[2]
+ sleep ${sleep}
+
+
+
+
+
+
+
+
+
+
+
+