This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
dongxiaoyan-tsg-autotest/02-Keyword/common/Util.robot

91 lines
4.3 KiB
Plaintext
Raw Normal View History

2020-12-15 19:58:08 +08:00
*** 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}