Merge branch 'develop' of https://git.mesalab.cn/dongxiaoyan/tsg_autotest.git into develop
This commit is contained in:
92
02-Keyword/common/ApiHttpRequest.robot
Normal file
92
02-Keyword/common/ApiHttpRequest.robot
Normal file
@@ -0,0 +1,92 @@
|
||||
*** Settings ***
|
||||
Library Collections
|
||||
Library RequestsLibrary
|
||||
Resource ../../03-Variable/BifangApiVariable.txt
|
||||
|
||||
*** Variables ***
|
||||
|
||||
*** Keywords ***
|
||||
GetRequestBase
|
||||
[Arguments] ${host} ${api} ${header} ${data}
|
||||
[Documentation] [Get方法封装:第一层,]
|
||||
Create Session api ${host} headers=${header}
|
||||
${apiurl}= Run Keyword If '${data}' != '${EMPTY}' Set Variable ${api}?${data}
|
||||
... ELSE Set Variable ${api}
|
||||
${remoteResponse} Get Request api ${apiurl}
|
||||
[Return] ${remoteResponse.content}
|
||||
|
||||
GetRequestResposeCode
|
||||
[Arguments] ${host} ${api} ${header} ${data}
|
||||
[Documentation] [Get方法封装:第二层,]
|
||||
${response} GetRequestBase ${host} ${api} ${header} ${data}
|
||||
${response} to json ${response}
|
||||
${code} get from dictionary ${response} code
|
||||
[Return] ${code}
|
||||
|
||||
GetRequestResposeData
|
||||
[Arguments] ${host} ${api} ${header} ${data} ${returnKey}
|
||||
[Documentation] [Get方法封装:第二层,]
|
||||
${response} GetRequestBase ${host} ${api} ${header} ${data}
|
||||
${response} to json ${response}
|
||||
${returnValue} get from dictionary ${response} ${returnKey}
|
||||
[Return] ${returnValue}
|
||||
|
||||
PostHttpRequestBase
|
||||
[Arguments] ${host} ${api} ${header} ${body}
|
||||
${header} Create Dictionary Content-Type=application/json Authorization=${token}
|
||||
Create Session api ${host} headers=${header}
|
||||
${remoteResponse} Post Request api ${api} data=${body}
|
||||
[Return] ${remoteResponse.content}
|
||||
|
||||
PostRequestResposeCode
|
||||
[Arguments] ${host} ${api} ${header} ${data}
|
||||
[Documentation] [Get方法封装:第二层,]
|
||||
${response} PostRequestBase ${host} ${api} ${header} ${data}
|
||||
${response} to json ${response}
|
||||
${code} get from dictionary ${response} code
|
||||
[Return] ${code}
|
||||
|
||||
PostRequestResposeData
|
||||
[Arguments] ${host} ${api} ${header} ${data} ${returnKey}
|
||||
[Documentation] [Get方法封装:第二层,]
|
||||
${response} PostRequestBase ${host} ${api} ${header} ${data}
|
||||
${response} to json ${response}
|
||||
${returnValue} get from dictionary ${response} ${returnKey}
|
||||
[Return] ${returnValue}
|
||||
|
||||
PutRequestBase
|
||||
[Arguments] ${requestUri} ${data}
|
||||
${headers} set variable {"Authorization":"${token}","Content-Type":"application/json"}
|
||||
create session api http://${host}:${port} ${headers}
|
||||
${response}= Put Request api ${requestUri} data=${data}
|
||||
log return data =${response}
|
||||
Should Be Equal As Strings ${response.status_code} 200
|
||||
${response} to json ${response.content}
|
||||
[Return] ${response}
|
||||
DeleteRequestBase
|
||||
[Arguments] ${url} ${data}
|
||||
${header} Create Dictionary Content-Type=application/json Authorization=${token}
|
||||
Create Session api http://${host}:${port} headers=${header}
|
||||
${remoteResponse} Delete Request api ${url} data=${data} headers=${header}
|
||||
${response} to json ${remoteResponse.content}
|
||||
Should Be Equal As Strings ${remoteResponse.status_code} 200
|
||||
[Return] ${response}
|
||||
|
||||
UpFileRequest
|
||||
[Arguments] ${url} ${data} ${files} ${fileDesc}
|
||||
${header} Set To Dictionary ${fileDesc} Authorization=${token}
|
||||
Create Session api http://${host}:${port} headers=${header}
|
||||
${remoteResponse} Post Request api ${url} data=${data} files=${files} headers=${header}
|
||||
${response} to json ${remoteResponse.content}
|
||||
Should Be Equal As Strings ${remoteResponse.status_code} 200
|
||||
[Return] ${response}
|
||||
|
||||
PutFileRequest
|
||||
[Arguments] ${url} ${data} ${files} ${fileDesc}
|
||||
${header} Set To Dictionary ${fileDesc} Authorization=${token}
|
||||
Create Session api http://${host}:${port} headers=${header}
|
||||
${remoteResponse} Put Request api ${url} params=${data} files=${files} headers=${header}
|
||||
${response} to json ${remoteResponse.content}
|
||||
Should Be Equal As Strings ${remoteResponse.status_code} 200
|
||||
[Return] ${response}
|
||||
|
||||
86
02-Keyword/common/ApiRestHttpRequest.robot
Normal file
86
02-Keyword/common/ApiRestHttpRequest.robot
Normal file
@@ -0,0 +1,86 @@
|
||||
*** Settings ***
|
||||
Library Collections
|
||||
Library RequestsLibrary
|
||||
Library REST http://${host}:${port}
|
||||
Resource ../../03-Variable/BifangApiVariable.txt
|
||||
|
||||
*** Keywords ***
|
||||
GetRequestBase
|
||||
[Arguments] ${header} ${apistr} ${body}
|
||||
Set Headers ${header}
|
||||
&{httpResponse} Get ${apistr}?${body}
|
||||
#Output response body
|
||||
Object response body
|
||||
#Integer $.code 200
|
||||
#Array $.data.policyList
|
||||
${response} Set Variable ${httpResponse.body}
|
||||
[Return] ${response}
|
||||
GetRequestBase
|
||||
[Arguments] ${api} ${header}
|
||||
[Documentation] [Get方法封装:第一层,]
|
||||
${response} BaseGetRequest ${apistr} ${body}
|
||||
${remoteResponse} Get Request api ${api}
|
||||
${response} to json ${remoteResponse.content}
|
||||
[Return] ${response}
|
||||
GetRequest
|
||||
[Arguments] ${url}
|
||||
[Documentation] [Get方法封装:第一层,]
|
||||
${header} Create Dictionary Content-Type=application/json Authorization=${token}
|
||||
Create Session api http://${host}:${port} headers=${header}
|
||||
${remoteResponse} Get Request api ${url} headers=${header}
|
||||
${response} to json ${remoteResponse.content}
|
||||
Should Be Equal As Strings ${remoteResponse.status_code} 200
|
||||
[Return] ${response}
|
||||
|
||||
PostRequest
|
||||
[Arguments] ${url} ${data}
|
||||
${header} Create Dictionary Content-Type=application/json Authorization=${token}
|
||||
Create Session api http://${host}:${port} headers=${header}
|
||||
${remoteResponse} Post Request api ${url} data=${data} headers=${header}
|
||||
${response} to json ${remoteResponse.content}
|
||||
Should Be Equal As Strings ${remoteResponse.status_code} 200
|
||||
[Return] ${response}
|
||||
|
||||
PutRequest
|
||||
[Arguments] ${requestUri} ${data}
|
||||
${headers} set variable {"Authorization":"${token}","Content-Type":"application/json"}
|
||||
create session api http://${host}:${port} ${headers}
|
||||
${response}= Put Request api ${requestUri} data=${data}
|
||||
log return data =${response}
|
||||
Should Be Equal As Strings ${response.status_code} 200
|
||||
${response} to json ${response.content}
|
||||
[Return] ${response}
|
||||
DeleteRequest
|
||||
[Arguments] ${url} ${data}
|
||||
${header} Create Dictionary Content-Type=application/json Authorization=${token}
|
||||
Create Session api http://${host}:${port} headers=${header}
|
||||
${remoteResponse} Delete Request api ${url} data=${data} headers=${header}
|
||||
${response} to json ${remoteResponse.content}
|
||||
Should Be Equal As Strings ${remoteResponse.status_code} 200
|
||||
[Return] ${response}
|
||||
|
||||
UpFileRequest
|
||||
[Arguments] ${url} ${data} ${files} ${fileDesc}
|
||||
${header} Set To Dictionary ${fileDesc} Authorization=${token}
|
||||
Create Session api http://${host}:${port} headers=${header}
|
||||
${remoteResponse} Post Request api ${url} data=${data} files=${files} headers=${header}
|
||||
${response} to json ${remoteResponse.content}
|
||||
Should Be Equal As Strings ${remoteResponse.status_code} 200
|
||||
[Return] ${response}
|
||||
|
||||
PutFileRequest
|
||||
[Arguments] ${url} ${data} ${files} ${fileDesc}
|
||||
${header} Set To Dictionary ${fileDesc} Authorization=${token}
|
||||
Create Session api http://${host}:${port} headers=${header}
|
||||
${remoteResponse} Put Request api ${url} params=${data} files=${files} headers=${header}
|
||||
${response} to json ${remoteResponse.content}
|
||||
Should Be Equal As Strings ${remoteResponse.status_code} 200
|
||||
[Return] ${response}
|
||||
|
||||
*** Test Cases ***
|
||||
Test-GetRequestBase
|
||||
${api} Set Variable /v2/policy/compile?pageSize=20&pageNo=1&policyType=tsg_security
|
||||
${header} Create Dictionary Content-Type=application/json Authorization=${token}
|
||||
${response} GetRequestBase ${api} ${header}
|
||||
log ${response}
|
||||
|
||||
89
02-Keyword/common/Test_ApiHttpRequest.robot
Normal file
89
02-Keyword/common/Test_ApiHttpRequest.robot
Normal file
@@ -0,0 +1,89 @@
|
||||
*** Settings ***
|
||||
Test Teardown DeletePolicyAndGroupObject ${policyIds} ${objectIds}
|
||||
Resource ../../03-Variable/BifangApiVariable.txt
|
||||
Resource ../../02-Keyword/tsg_bfapi/PolicyObject.robot
|
||||
|
||||
*** Variables ***
|
||||
${host} Set Variable http://${host}:${port}
|
||||
${api} Set Variable /v2/policy/compile
|
||||
${header} Create Dictionary Content-Type=application/json Authorization=${token}
|
||||
*** Test Cases ***
|
||||
Test-GetRequestBase
|
||||
${host} Set Variable http://${host}:${port}
|
||||
${api} Set Variable /v2/policy/compile
|
||||
${data} Set Variable pageSize=20&pageNo=1&policyType=tsg_security
|
||||
${header} Create Dictionary Content-Type=application/json Authorization=${token}
|
||||
${response} GetRequestBase ${host} ${api} ${header} ${data}
|
||||
${responsejson} to json ${response}
|
||||
${code} get from dictionary ${responsejson} code
|
||||
${msg} get from dictionary ${responsejson} msg
|
||||
${success} get from dictionary ${responsejson} success
|
||||
${data} get from dictionary ${responsejson} data
|
||||
${list} get from dictionary ${data} list
|
||||
${policyId} get from dictionary ${list}[0] policyId
|
||||
${length} Get Length ${list}
|
||||
#:FOR ${element} IN ${list}
|
||||
#\ log ${element}
|
||||
:FOR ${i} IN RANGE ${length}
|
||||
\ ${policyId} get from dictionary ${list}[${i}] policyId
|
||||
\ log ${policyId}
|
||||
log ${response}
|
||||
|
||||
Test-GetRequestResposeCode
|
||||
${host} Set Variable http://${host}:${port}
|
||||
${api} Set Variable /v2/policy/compile?pageSize=20&pageNo=1&policyType=tsg_security
|
||||
${header} Create Dictionary Content-Type=application/json Authorization=${token}
|
||||
${code} GetRequestResposeCode ${host} ${api} ${header} ${EMPTY}
|
||||
Should Be Equal As Strings ${code} 200
|
||||
log ${code}
|
||||
|
||||
Test-GetRequestResposeData
|
||||
${host} Set Variable http://${host}:${port}
|
||||
${api} Set Variable /v2/policy/compile?pageSize=20&pageNo=1&policyType=tsg_security
|
||||
${header} Create Dictionary Content-Type=application/json Authorization=${token}
|
||||
${code} GetRequestResposeData ${host} ${api} ${header} ${EMPTY} code
|
||||
Should Be Equal As Strings ${code} 200
|
||||
log ${code}
|
||||
|
||||
Test-PostRequestBase
|
||||
${host} Set Variable http://${host}:${port}
|
||||
${api} Set Variable /v2/policy/compile
|
||||
${body} Set Variable {"opAction":"add","returnData":1,"refuseCode":true,"policyList":{"policyId":"","policyName":"dxytest","policyType":"tsg_security","action":"intercept","userTags":"3","doBlacklist":0,"doLog":1,"policyDesc":"Intercept","effectiveRange":{"tag_sets":[[{"tag":"data_center","value":["Nur-sultan"],"ids":[2]}]]},"userRegion":{"protocol":"SSL","keyring":1,"decryption":1,"decrypt_mirror":{"enable":1,"mirror_profile":1}},"source":[{"objectId":197,"protocolField":"TSG_SECURITY_SOURCE_ADDR"}],"destination":[{"objectId":222,"protocolField":"TSG_SECURITY_DESTINATION_ADDR"}],"filterList":[],"appIdObjects":[44],"appSelectorObjects":[],"isValid":1,"scheduleId":[1]}}
|
||||
${header} Create Dictionary Content-Type=application/json Authorization=${token}
|
||||
${response} PostRequestBase ${host} ${api} ${header} ${body}
|
||||
${responsejson} to json ${response}
|
||||
${code} get from dictionary ${responsejson} code
|
||||
${msg} get from dictionary ${responsejson} msg
|
||||
${success} get from dictionary ${responsejson} success
|
||||
${datastr} get from dictionary ${responsejson} data
|
||||
${list} get from dictionary ${datastr} policyList
|
||||
${policyId} get from dictionary ${list}[0] policyId
|
||||
#${policyIds1} set Variable {"policyType":"tsg_security","policyIds":[${policyId}]}
|
||||
${policyIds} Create List {"policyType":"tsg_security","policyIds":[${policyId}]}
|
||||
${length} Get Length ${list}
|
||||
#:FOR ${element} IN ${list}
|
||||
#\ log ${element}
|
||||
:FOR ${i} IN RANGE ${length}
|
||||
\ ${policyId} get from dictionary ${list}[${i}] policyId
|
||||
\ log ${policyId}
|
||||
|
||||
#DeleteRequestBase /v1/policy/compile {"policyType":"tsg_security","policyIds":[${policyId}]}
|
||||
log ${response}
|
||||
|
||||
Test-PostRequestResposeCode
|
||||
${host} Set Variable http://${host}:${port}
|
||||
${api} Set Variable /v2/policy/compile
|
||||
${data} Set Variable {"opAction":"add","returnData":1,"refuseCode":true,"policyList":{"policyId":"","policyName":"dxytest","policyType":"tsg_security","action":"intercept","userTags":"3","doBlacklist":0,"doLog":1,"policyDesc":"Intercept","effectiveRange":{"tag_sets":[[{"tag":"data_center","value":["Nur-sultan"],"ids":[2]}]]},"userRegion":{"protocol":"SSL","keyring":1,"decryption":1,"decrypt_mirror":{"enable":1,"mirror_profile":1}},"source":[{"objectId":197,"protocolField":"TSG_SECURITY_SOURCE_ADDR"}],"destination":[{"objectId":222,"protocolField":"TSG_SECURITY_DESTINATION_ADDR"}],"filterList":[],"appIdObjects":[44],"appSelectorObjects":[],"isValid":1,"scheduleId":[1]}}
|
||||
${header} Create Dictionary Content-Type=application/json Authorization=${token}
|
||||
${code} PostRequestResposeCode ${host} ${api} ${header} ${data}
|
||||
Should Be Equal As Strings ${code} 200
|
||||
log ${code}
|
||||
|
||||
Test-PostRequestResposeData
|
||||
${host} Set Variable http://${host}:${port}
|
||||
${api} Set Variable /v2/policy/compile
|
||||
${data} Set Variable {"opAction":"add","returnData":1,"refuseCode":true,"policyList":{"policyId":"","policyName":"dxytest","policyType":"tsg_security","action":"intercept","userTags":"3","doBlacklist":0,"doLog":1,"policyDesc":"Intercept","effectiveRange":{"tag_sets":[[{"tag":"data_center","value":["Nur-sultan"],"ids":[2]}]]},"userRegion":{"protocol":"SSL","keyring":1,"decryption":1,"decrypt_mirror":{"enable":1,"mirror_profile":1}},"source":[{"objectId":197,"protocolField":"TSG_SECURITY_SOURCE_ADDR"}],"destination":[{"objectId":222,"protocolField":"TSG_SECURITY_DESTINATION_ADDR"}],"filterList":[],"appIdObjects":[44],"appSelectorObjects":[],"isValid":1,"scheduleId":[1]}}
|
||||
${header} Create Dictionary Content-Type=application/json Authorization=${token}
|
||||
${code} PostRequestResposeData ${host} ${api} ${header} ${data} code
|
||||
Should Be Equal As Strings ${code} 200
|
||||
log ${code}
|
||||
74
02-Keyword/common/Test_Util.robot
Normal file
74
02-Keyword/common/Test_Util.robot
Normal file
@@ -0,0 +1,74 @@
|
||||
*** Settings ***
|
||||
Resource ../../03-Variable/BifangApiVariable.txt
|
||||
Resource Util.robot
|
||||
Variables ../../05-Other/variable/my3.py
|
||||
Variables ../../05-Other/variable/my.py
|
||||
Variables ../../05-Other/variable/my1.py
|
||||
Variables ../../05-Other/variable/my2.py
|
||||
|
||||
*** Variables ***
|
||||
@{list1} a b c d
|
||||
&{dict} name=cary age=21
|
||||
@{list2} ${1} e ${3.14}
|
||||
*** Test Cases ***
|
||||
Test-GetLastLastNTimeSEndTime
|
||||
[Tags] test
|
||||
${startime} ${endtime} GetLastNTimeSEndTime 3
|
||||
log ${startime}
|
||||
log ${endtime}
|
||||
|
||||
Test-SystemCommandReturnCompare
|
||||
[Tags] test
|
||||
${rescode} SystemCommandReturnCompare ipconfig ${EMPTY} ${EMPTY}
|
||||
Should Be Equal As Strings ${rescode} 200
|
||||
|
||||
${instring} create list 子网掩码 255.255.252.0 IPv4 地址 192.168.32.18
|
||||
${notinstring} create list 255.255.252.11 192.168.32.19
|
||||
${rescode} SystemCommandReturnCompare ipconfig ${instring} ${notinstring}
|
||||
Should Be Equal As Strings ${rescode} 200
|
||||
|
||||
${instring} create list IPv4 地址 . . . . . . . . . . . . : 192.168.32.18
|
||||
#子网掩码 . . . . . . . . . . . . : 255.255.252.0
|
||||
${notinstring} create list 子网掩码 . . . . . . . . . . . . : 255.255.252.0 IPv4 地址 . . . . . . . . . . . . : 192.168.32.18
|
||||
${rescode} SystemCommandReturnCompare ipconfig ${instring} ${notinstring}
|
||||
Should Be Equal As Strings ${rescode} 200
|
||||
|
||||
Test-GetRandomIP
|
||||
[Tags] test
|
||||
${ip} GetRandomIP ipv4
|
||||
log ${ip}
|
||||
${ip} GetRandomIP ipv6
|
||||
log ${ip}
|
||||
|
||||
Test-Variable
|
||||
[Tags] test
|
||||
log ${myname}
|
||||
log ${MY_VAR}
|
||||
log ${VARIABLE}
|
||||
log ${ANOTHER_VARIABLE}
|
||||
log ${INTEGER}
|
||||
log ${STRINGS}
|
||||
log ${NUMBERS}
|
||||
log ${MAPPING}
|
||||
|
||||
log pass
|
||||
|
||||
log ${list1}
|
||||
log ${dict}
|
||||
log ${list2}
|
||||
|
||||
Test-my
|
||||
log ${AREA1}
|
||||
log ${AREA2}
|
||||
log ${get_area}
|
||||
log ${RANDOM_INT}
|
||||
|
||||
Test-my3
|
||||
log PASsssssssssssssssssssss
|
||||
log ${VARIABLE}
|
||||
log ${ANOTHER VARIABLE}
|
||||
log ${INTEGER}
|
||||
log ${STRINGS}
|
||||
log ${NUMBERS}
|
||||
log ${MAPPING}
|
||||
log ${DXY}
|
||||
90
02-Keyword/common/Util.robot
Normal file
90
02-Keyword/common/Util.robot
Normal file
@@ -0,0 +1,90 @@
|
||||
*** Settings ***
|
||||
Resource ../../03-Variable/BifangApiVariable.txt
|
||||
Library DateTime
|
||||
Library String
|
||||
Library ipandstring
|
||||
Library OperatingSystem
|
||||
|
||||
*** Keywords ***
|
||||
SystemCommandReturnCompare
|
||||
#执行命令并比对命令返回结果 需要执行的系统命令 命令返回结果要包含的字符串列表 命令返回结果不能包含的字符串列表
|
||||
[Arguments] ${commandstr} ${stringlist} ${stringlistnotin}
|
||||
[Documentation] 命令执行结果包含某些字符串和排除某些字符串,二者都可以为空
|
||||
... ${commandstr}执行的命令
|
||||
... ${stringlist}命令执行结果需包含字符粗
|
||||
... ${stringlistnotin} 命令结果需排除字符串
|
||||
... 返回命令执行结果状态码:成功200,
|
||||
log toSystemCommand_SystemCommandTest
|
||||
${commandreturn} OperatingSystem.Run ${commandstr}
|
||||
#Append To File ${path}/write_file.txt ${commandstr}
|
||||
#Append To File ${path}/write_file.txt %%%%%%%%%%%%%%newbat
|
||||
#Append To File ${path}/write_file.txt ${commandreturn}
|
||||
#${commandreturn} Set Variable abcdeConnection was reset
|
||||
${listlenth}= Get Length ${stringlist}
|
||||
FOR ${var} IN RANGE ${listlenth}
|
||||
log ${var}
|
||||
Should Contain ${commandreturn} ${stringlist}[${var}]
|
||||
END
|
||||
${listnotin}= Get Length ${stringlistnotin}
|
||||
FOR ${varn} IN RANGE ${listnotin}
|
||||
log ${varn}
|
||||
Should Not Contain ${commandreturn} ${stringlistnotin}[${varn}]
|
||||
END
|
||||
${rescode} Set Variable 200
|
||||
log ${rescode}
|
||||
[Return] ${rescode}
|
||||
|
||||
GetLastNTimeSEndTime
|
||||
[Arguments] ${day}
|
||||
[Documentation] ${day}当前时间往前几天的时间放范围
|
||||
... 获取最近N长时间的开始结束时间,时间格式为:YYY-MM-DD H24:mm:ss
|
||||
${endtime} Get Time
|
||||
${starttime}= Add Time To Date ${endtime} -${day} days
|
||||
${starttime} Get Substring ${starttime} 0 19
|
||||
[Return] ${starttime} ${endtime}
|
||||
|
||||
GetLimitRandomString
|
||||
[Arguments] ${length} ${content}
|
||||
[Documentation] 根据参数指定长度和内容获取字符串,字符串长度为参数要求,内容也限于参数内容
|
||||
... ${length}获取字符串的长度:例如:1024
|
||||
... ${content}获取字符串的内容限制例如:ABCDEFGHIGKLMNOPQRSTUVWXYZabcdefghigklmnopqrstuvwxyz0123456789~!@#$%^&*()_+{}|<>?`,./;'[]\
|
||||
${content} Run Keyword If '${content}' != '${EMPTY}' Set Variable ABCDEFGHIGKLMNOPQRSTUVWXYZabcdefghigklmnopqrstuvwxyz0123456789~!@#$%^&*()_+{}|<>?`,./;'[]\
|
||||
... ELSE Set Variable ${content}
|
||||
${returnstr} getstring ${length} ${content}
|
||||
[Return] ${returnstr}
|
||||
|
||||
GetRandomString
|
||||
[Arguments] ${length}
|
||||
[Documentation] 获取包含英文字符,数字和特殊符号的随机字符串
|
||||
... ${length}获取字符串的长度:例如:1024
|
||||
... ${content}获取字符串的内容限制例如:ABCDEFGHIGKLMNOPQRSTUVWXYZabcdefghigklmnopqrstuvwxyz0123456789~!@#$%^&*()_+{}|<>?`,./;'[]\
|
||||
${returnstr} GetLimitRandomString ${length} ABCDEFGHIGKLMNOPQRSTUVWXYZabcdefghigklmnopqrstuvwxyz0123456789~!@#$%^&*()_+{}|<>?`,./;'[]\
|
||||
[Return] ${returnstr}
|
||||
|
||||
GetEnglistString
|
||||
[Arguments] ${length}
|
||||
[Documentation] 获取指定长度的英文字符串
|
||||
... ${length}获取字符串的长度
|
||||
${returnstr} GetLimitRandomString ${length} ABCDEFGHIGKLMNOPQRSTUVWXYZabcdefghigklmnopqrstuvwxyz
|
||||
[Return] ${returnstr}
|
||||
|
||||
GetChinaString
|
||||
[Arguments] ${length} ${content}
|
||||
[Documentation] 获取指定长度的中午字符窜
|
||||
... ${length}获取字符串的长度
|
||||
... ${content}获取字符串的内容限制
|
||||
${returnstr} GetLimitRandomString ${length} 我是汉字学中文讲汉语说中国话时时尚是进步
|
||||
[Return] ${returnstr}
|
||||
|
||||
GetRandomIP
|
||||
[Arguments] ${iptype}
|
||||
[Documentation] 获取随机IP
|
||||
... ${iptype}ip类型:ipv4/ipv6
|
||||
# iPv4 需要三个参数 分别表ip的前三位 ,-1代表不指定
|
||||
${returnstr} Run Keyword If '${iptype}' == 'ipv4' ipv4 -1 -1 -1
|
||||
... ELSE ipv6
|
||||
#${returnstr} ipv4 -1 -1 -1
|
||||
#${returnstr} ipv6
|
||||
[Return] ${returnstr}
|
||||
|
||||
|
||||
132
02-Keyword/common/readme.robot
Normal file
132
02-Keyword/common/readme.robot
Normal file
@@ -0,0 +1,132 @@
|
||||
*** Settings ***
|
||||
Library Collections
|
||||
|
||||
*** Test Cases ***
|
||||
#https://www.cnblogs.com/fnng/p/3901391.html
|
||||
#引用变量文件:https://www.cnblogs.com/chengchengla1990/p/9895244.html
|
||||
#关于标签:接口的一律贴bifang标签,全流程的贴adc和bifang或ui,UI的贴ui
|
||||
Common-test
|
||||
[Tags] Common-test
|
||||
Comment :1、log
|
||||
Comment log 关键字就是编程语言里的“print”一样,可以打印任何你想打印的内容。
|
||||
log 123
|
||||
|
||||
Comment 2、定义变量
|
||||
Comment 通过“Set variable”关键字来定义变量
|
||||
${a} Set Variable Hello Word!
|
||||
|
||||
Comment 3、连接对象
|
||||
Comment “Catenate”关键字可以连接多个信息
|
||||
${hi} Catenate Hellow Word! What Do You Do!
|
||||
Comment 加上“SEPARATOR=”可以对多个连接的信息进行分割。
|
||||
${hi} Catenate SEPARATOR=-- Hellow Word! What Do You Do!
|
||||
Comment 4、定义列表
|
||||
Comment 通过“Create List”关键字可以定义列表。每个字符串前面加 u,是为了统一编码问题,将字符串转为 Unicode 编码。
|
||||
${abc} Create List a b c
|
||||
log ${abc}
|
||||
|
||||
Comment 如果通过“@{}”去定义列表的话,可以通过“log many”关键字进行打印
|
||||
@{abc} Create List a b c
|
||||
log many ${abc}
|
||||
|
||||
Comment 5、时间的操作
|
||||
Comment Robot Framework 中提供了“get time”关键字用来获取当前时间。
|
||||
${time} Get Time
|
||||
log ${time}
|
||||
|
||||
Comment 6、设置休眠时间
|
||||
Comment “sleep”关键字用来设置休眠一定时间,sleep 关键字默认以“秒”为单位。
|
||||
${time} Get Time
|
||||
log ${time}
|
||||
sleep 5
|
||||
${time} Get Time
|
||||
log ${time}
|
||||
|
||||
Comment 7、if语句
|
||||
Comment 通过“run keyword if”关键字可以编写 if 分支语句。
|
||||
${a} Set Variable 100
|
||||
Run Keyword If ${a}>=90 log 优秀
|
||||
... ELSE IF ${a}>=70 log 优秀
|
||||
... ELSE IF ${a}>=60 log 及格
|
||||
... ELSE log 不及格
|
||||
|
||||
Comment 首先定义一个变量 a 等于 59 。
|
||||
Comment If 判断 a 大于等于 90 ,满足条件 log 输出 “优秀 ”;
|
||||
Comment 不满足上面的条件,接着 else if 判断 a 大于等于 70 ,满足条件 log 输出 “良好”;
|
||||
Comment 不满足上面的条件,接着 else if 判断 a 大于等于 60 ,满足条件 log 输出 “及格”;
|
||||
Comment 上面的条件都不满足,else log 输出“不及格”。
|
||||
Comment 注:注意 ELSE IF 和 ELSE 前面的三个点点点(...)。注意ELSE IF和ELSE要是大写。
|
||||
|
||||
Comment 8、for 循环
|
||||
Comment 在 Robot Framework 中编写循环通过“:for”。通过“:for”定义 for 循环;in range 用于指定循环的范围。
|
||||
Comment 例子1,这个例子为执行 10 次循环
|
||||
:FOR ${i} IN RANGE 10
|
||||
\ log ${i}
|
||||
|
||||
Comment 注意:in range 定义为 10,它的范围是 0~9
|
||||
|
||||
Comment 例 2,遍历列表
|
||||
Comment “create list” 关键字用来定义列表(a,b,c),“@{}”用来存放列表。通过过“:for”循环来来遍历@{abc}列表中的字符。
|
||||
@{abc} Create List a b c
|
||||
:FOR ${i} IN @{abc}
|
||||
\ log ${i}
|
||||
|
||||
Comment 例 3,循环中的判断
|
||||
Comment 通过“Exit For Loop If”关键字时行 for 循环内的判断,当满足 Exit For Loop If 条件后,循环结束。
|
||||
@{abc} Create List a b c
|
||||
:FOR ${i} IN @{abc}
|
||||
\ Exit For Loop If '${i}'=='b'
|
||||
\ log ${i}
|
||||
log ${i}
|
||||
|
||||
Comment 从执行结果看到当循环到字符 b 时,Exit For Loop If 条件成立,结束循环;通过 log 打印当前的字符 b。
|
||||
|
||||
Comment 9、强大的 Evaluate
|
||||
Comment 因为通过它可以使用 Python 语言中所提供的方法
|
||||
Comment 例 1,生成随即数
|
||||
#import random
|
||||
#random.randint(1,5)
|
||||
|
||||
Comment 使用Evaluate关键字之后可使用Python中的类和方法
|
||||
|
||||
${d} Evaluate random.randint(1,5) random
|
||||
log ${d}
|
||||
|
||||
Comment 例 2,执行本地程序
|
||||
Comment #Evaluate os.system('python c:/helloword.py') os
|
||||
|
||||
|
||||
Comment 通过调用 Python 所提供的 os 模块中的 system()方法可以执行本地 Python 文件。至于在.py 文件中
|
||||
Comment Python 可以做任何想做的事。
|
||||
Comment 对于 system()方法来说,它也不单单可执行 Python 文件,任何在 cmd 命令提示符下可运行文件和命
|
||||
Comment 令,它都可以执行。
|
||||
Comment 不过,一般情况下不建议通过 system()方法去执行外部程序。这样做其实就脱离了 Robot Framework,
|
||||
Comment 也就是说不管 Robot Framework 什么事了。我们尽量把要做的事情通过 Python 封装成关键字给 Robot
|
||||
Comment Framework 使用。
|
||||
|
||||
Comment 10、导入库
|
||||
Comment (1)“Import Library”等同于 Python 语言中的 import。Robot Framework 会遍历 Python 安装目录下的相关目录查找“Selenium2Library”模块
|
||||
Comment Import Library Selenium2Libary
|
||||
|
||||
Comment (2)调用 Python 文件
|
||||
Comment 首先创建 test.py 文件
|
||||
Comment coding=utf-8
|
||||
Comment def add(a,b):
|
||||
Comment return a+b
|
||||
Comment if __name__ == "__main__":
|
||||
Comment a = add(4,5)
|
||||
Comment print a
|
||||
|
||||
Comment 通过“Evaluate”转化成为 int 类型后,再调用 add 就得到了想要的结果。
|
||||
Import Library E:/test.py
|
||||
${a} Evaluate int(4)
|
||||
${a} Evaluate int(5)
|
||||
${add} add ${a} ${b}
|
||||
log ${add}
|
||||
|
||||
Comment 11、注释
|
||||
Comment Robot Framework 中添加注释也非常简单。
|
||||
Comment (1)“Comment”关键字用于设置脚本中的注释。
|
||||
Comment (2)也可以像 Python 一样使用“#”号进行注释
|
||||
Comment 这是注释
|
||||
#这是注释
|
||||
61
02-Keyword/tsg_bfapi/policy/ApiPolicyRequest.robot
Normal file
61
02-Keyword/tsg_bfapi/policy/ApiPolicyRequest.robot
Normal file
@@ -0,0 +1,61 @@
|
||||
*** Settings ***
|
||||
Library Collections
|
||||
Library RequestsLibrary
|
||||
Resource ../../../03-Variable/BifangApiVariable.txt
|
||||
Resource ../../common/ApiHttpRequest.robot
|
||||
Variables ../../../05-Other/variable/policy/apipolicyrequesttest.py
|
||||
|
||||
*** Variables ***
|
||||
${policyapiv2} /v2/policy/compile
|
||||
${objectapiv1} /v1/policy/object
|
||||
${hosturl} http://${host}:${port}
|
||||
${header} Create Dictionary Content-Type=application/json Authorization=${token}
|
||||
*** Keywords ***
|
||||
GetRequestResposeCodePrivate
|
||||
[Arguments] ${data}
|
||||
[Documentation] [Get方法封装:第二层,]
|
||||
${header} Create Dictionary Content-Type=application/json Authorization=${token}
|
||||
${response} GetRequestBase http://${hosturl}:${port} ${policyapiv2} ${header} ${data}
|
||||
${response} to json ${response}
|
||||
${code} get from dictionary ${response} code
|
||||
[Return] ${code}
|
||||
|
||||
GetPolicyData
|
||||
[Arguments] ${host} ${api} ${header} ${data} ${returnKey}
|
||||
[Documentation] [Get方法封装:第二层,]
|
||||
${response} GetRequestBase ${hosturl} ${policyapiv2} ${header} ${data}
|
||||
${response} to json ${response}
|
||||
${returnValue} get from dictionary ${response} ${returnKey}
|
||||
[Return] ${returnValue}
|
||||
|
||||
AddPolicyData
|
||||
[Arguments] ${data} ${returnKey}
|
||||
[Documentation] [Get方法封装:第二层,]
|
||||
${response} PostRequestBase ${hosturl} ${policyapiv2} ${header} ${data}
|
||||
${response} to json ${response}
|
||||
${returnValue} get from dictionary ${response} ${returnKey}
|
||||
[Return] ${returnValue}
|
||||
|
||||
AddObjectData
|
||||
[Arguments] ${data} ${returnKey}
|
||||
[Documentation] [Get方法封装:第二层,]
|
||||
${response} PostHttpRequestBase ${hosturl} ${objectapiv1} ${header} ${data}
|
||||
${response} to json ${response}
|
||||
${returnValue} get from dictionary ${response} ${returnKey}
|
||||
[Return] ${returnValue}
|
||||
|
||||
AddPolicyBase
|
||||
[Arguments] ${host} ${api} ${header} ${body}
|
||||
${header} Create Dictionary Content-Type=application/json Authorization=${token}
|
||||
Create Session api ${hosturl} headers=${header}
|
||||
${remoteResponse} Post Request api ${api} data=${body}
|
||||
[Return] ${remoteResponse.content}
|
||||
|
||||
AddPolicyCode
|
||||
[Arguments] ${host} ${api} ${header} ${data}
|
||||
[Documentation] [Get方法封装:第二层,]
|
||||
${response} PostRequestBase ${hosturl} ${api} ${header} ${data}
|
||||
${response} to json ${response}
|
||||
${code} get from dictionary ${response} code
|
||||
[Return] ${code}
|
||||
|
||||
38
02-Keyword/tsg_bfapi/policy/Test_ApiPolicyRequest.robot
Normal file
38
02-Keyword/tsg_bfapi/policy/Test_ApiPolicyRequest.robot
Normal file
@@ -0,0 +1,38 @@
|
||||
*** Settings ***
|
||||
Test Teardown DeletePolicyAndGroupObject ${policyIds} ${objectIds}
|
||||
Resource ../../common/ApiHttpRequest.robot
|
||||
Resource ../../common/Util.robot
|
||||
Resource ApiPolicyRequest.robot
|
||||
Variables ../../../05-Other/variable/policy/apipolicyrequesttest.py
|
||||
Resource ../../tsg_bfapi/PolicyObject.robot
|
||||
|
||||
*** Variables ***
|
||||
|
||||
*** Test Cases ***
|
||||
Test-GetRequestResposeCodePrivate
|
||||
[Tags] test
|
||||
${data} Set Variable pageSize=20&pageNo=1&policyType=tsg_security
|
||||
${code} GetRequestResposeCodePrivate ${data}
|
||||
Should Be Equal As Strings ${code} 200
|
||||
log ${code}
|
||||
|
||||
Test-AddPolicyData
|
||||
[Tags] test
|
||||
log ${IP_OBJ}
|
||||
${returnKey} Set Variable data
|
||||
${header} Create Dictionary Content-Type=application/json Authorization=${token}
|
||||
${ipid} AddObjectData ${Test-AddPolicyData_IP_OBJ} ${returnKey}
|
||||
log ${FQDN_OBJ}
|
||||
${fqdnid} AddObjectData ${FQDN_OBJ}
|
||||
log ${SECURITY_POLICY}
|
||||
${POLICY} Replace String ${SECURITY_POLICY} IP_OBJ ${ipid}
|
||||
${POLICY} Replace String ${SECURITY_POLICY} FQDN_OBJ ${fqdnid}
|
||||
${policyid} AddPolicyData ${POLICY}
|
||||
|
||||
Test-GetRandomIP
|
||||
[Tags] test
|
||||
${ip} GetRandomIP ipv4
|
||||
log ${ip}
|
||||
${ip} GetRandomIP ipv6
|
||||
log ${ip}
|
||||
|
||||
BIN
05-Other/variable/__pycache__/my.cpython-36.pyc
Normal file
BIN
05-Other/variable/__pycache__/my.cpython-36.pyc
Normal file
Binary file not shown.
BIN
05-Other/variable/__pycache__/my2.cpython-36.pyc
Normal file
BIN
05-Other/variable/__pycache__/my2.cpython-36.pyc
Normal file
Binary file not shown.
BIN
05-Other/variable/__pycache__/my3.cpython-36.pyc
Normal file
BIN
05-Other/variable/__pycache__/my3.cpython-36.pyc
Normal file
Binary file not shown.
8
05-Other/variable/my.py
Normal file
8
05-Other/variable/my.py
Normal file
@@ -0,0 +1,8 @@
|
||||
MY_VAR = 'my value'
|
||||
my_name='test'
|
||||
VARIABLE = "An example string"
|
||||
ANOTHER_VARIABLE = "This is pretty easy!"
|
||||
INTEGER = 42
|
||||
STRINGS = ["one", "two", "kolme", "four"]
|
||||
NUMBERS = [1, INTEGER, 3.14]
|
||||
MAPPING = {"one": 1, "two": 2, "three": 3}
|
||||
11
05-Other/variable/my1.py
Normal file
11
05-Other/variable/my1.py
Normal file
@@ -0,0 +1,11 @@
|
||||
import os
|
||||
import radom
|
||||
import time
|
||||
|
||||
USER = os.getlogin()
|
||||
RANDOM_INT = random.randint(1,10)
|
||||
CURRENT_TIME = time.asctime()
|
||||
if time.localtime()[3] > 12:
|
||||
AFTERNOON = True
|
||||
else
|
||||
AFTERNOON = False
|
||||
11
05-Other/variable/my2.py
Normal file
11
05-Other/variable/my2.py
Normal file
@@ -0,0 +1,11 @@
|
||||
import math
|
||||
|
||||
_all_ = ['AREA1','AREA2']
|
||||
def get_area(diameter):
|
||||
radius = diameter/2
|
||||
area = math.pi*radius*radius
|
||||
return area
|
||||
|
||||
AREA1 = get_area(1)
|
||||
AREA2 = get_area(2)
|
||||
|
||||
10
05-Other/variable/my3.py
Normal file
10
05-Other/variable/my3.py
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
def get_variables1():
|
||||
variables = {"VARIABLE":"An example string",
|
||||
"ANOTHER VARIABLE":"This is pretty easy!",
|
||||
"INTEGER":66,
|
||||
"STRINGS":["one","two","kolme","four"],
|
||||
"NUMBERS":[1,66,3.1415926],
|
||||
"MAPPING":'{"one":1,"two":2,"three":3}',
|
||||
"DXY":'{"one":1,"two":2,"three":${VARIABLE}}'}
|
||||
return variables
|
||||
9
05-Other/variable/policy/apipolicyrequesttest.py
Normal file
9
05-Other/variable/policy/apipolicyrequesttest.py
Normal file
@@ -0,0 +1,9 @@
|
||||
def get_variables():
|
||||
variables = {"IP_OBJ":'{"opAction":"add","refuseCode":true,"returnData":1,"objectList":{"objectType":"ip","objectSubType":"endpoint","isValid":1,"isInitialize":0,"isExclusion":0,"objectName":"autotest","objectDesc":"autotest","subObjectIds":[],"addItemList":[{"ip":"192.168.32.69","ipIf":false,"portIf":false,"port":"1-65535","itemId":"","clientIp1":"192.168.32.69","clientIp2":"192.168.32.69","clientPort1":"1","clientPort2":"65535","clientIpFormat":"range","clientPortFormat":"range","addrType":4,"direction":0,"temporaryItemId":1606647164},{"ip":"1.1.1.1","ipIf":false,"portIf":false,"port":"0-65535","itemId":"","clientIp1":"1.1.1.1","clientIp2":"1.1.1.1","clientPort1":"","clientPort2":"","clientIpFormat":"range","clientPortFormat":"range","addrType":4,"direction":0,"temporaryItemId":1606647177}],"updateItemList":[],"deleteItemIds":[],"iconColor":"#31739C"}}',
|
||||
"FQDN_OBJ":'"{"opAction":"add","returnData":1,"objectList":{"objectType":"fqdn","objectSubType":"fqdn","isValid":1,"isInitialize":0,"isExclusion":0,"objectName":"autotest","objectDesc":"","subObjectIds":[],"addItemList":[{"keywordArray":["$www.test.com"],"t":1606647302921,"itemId":"","isHexbin":0,"state":2},{"keywordArray":["*autotest.com"],"t":1606647302921,"isHexbin":0,"state":2}],"updateItemList":[],"deleteItemIds":[],"objectId":""}}"',
|
||||
"SECURITY_POLICY":'{"opAction":"add","refuseCode":true,"policyList":{"policyId":"","policyName":"autotest","policyType":"tsg_security","action":"intercept","userTags":"","doBlacklist":0,"doLog":1,"policyDesc":"dxytest","effectiveRange":{"tag_sets":[[]]},"userRegion":{"protocol":"SSL","keyring":1,"decryption":1,"decrypt_mirror":{"enable":1,"mirror_profile":25}},"source":[{"objectId":IP_OBJ,"protocolField":"TSG_SECURITY_SOURCE_ADDR"}],"destination":[{"objectId":IP_OBJ,"protocolField":"TSG_SECURITY_DESTINATION_ADDR"}],"filterList":[{"filter":[{"objectId":FQDN_OBJ,"protocolField":"TSG_FIELD_SSL_SNI"}]}],"appIdObjects":[44],"appSelectorObjects":[],"isValid":1,"scheduleId":[]}}',
|
||||
"STRINGS":["one","two","kolme","four"],
|
||||
"NUMBERS":[1,66,3.1415926],
|
||||
"MAPPING":'{"one":1,"two":2,"three":3}',
|
||||
"DXY":'{"one":1,"two":2,"three":${VARIABLE}}'}
|
||||
return variables
|
||||
Reference in New Issue
Block a user