robot_framewok自动化测试---內建库

本文介绍了一个测试框架中的关键函数,包括变量操作、流程控制、断言验证等功能,这些函数为自动化测试提供了强大的支持。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

*** Keywords ***
失败后继续运行
    [Arguments]    ${keyword}    @{args}
    Run Keyword And Continue On Failure    ${keyword}    @{args}


日志
    [Arguments]    @{msg}
    log    @{msg}


注释
    comment


调用方法
    [Arguments]    ${object}    ${method_name}    @{args}
    ${res}    Call Method    ${object}    ${method_name}    @{args}
    [Return]    ${res}


连接
    [Arguments]    ${sep}    @{args}
    [Documentation]    可以使用 SEPARATOR= 指定连接字符,例如:
    ...    连接 SEPARATOR=*** \ \ aaa \ bbb \ ccc
    ...    --------------------------------------------------
    ...    输出结果:aaa***bbb***ccc
    ${res}    Catenate    ${sep}    @{args}
    [Return]    ${res}


继续for循环
    Continue For Loop


条件成立继续for循环
    [Arguments]    ${arg}
    Continue For Loop If    ${arg}


转成二进制
    [Arguments]    ${item}    ${base}=    ${prefix}=    ${length}=
    ${res}    Convert To Binary    ${item}    ${base}    ${prefix}    ${length}
    [Return]    ${res}


转成bool
    [Arguments]    ${item}
    ${res}    Convert To Boolean    ${item}
    [Return]    ${res}


转成hex
    [Arguments]    ${item}    ${base}=    ${prefix}=    ${length}=    ${lowercase}=False
    ${res}    Convert To Hex    ${item}    ${base}    ${prefix}    ${length}    ${lowercase}
    [Return]    ${res}


转成int
    [Arguments]    ${item}    ${base}=
    ${res}    Convert To Integer    ${item}    ${base}
    [Return]    ${res}


转成Number
    [Arguments]    ${item}    ${precision}=
    [Documentation]    precison 参数是保留位数,默认全部保存。
    ...    Convert To Number 13.14 \ #结果:13.14
    ...    Convert To Number 13.14 1 #结果:13.1
    ...    Convert To Number 13.14 0 #结果:13.0
    ...    Convert To Number 13.14 -1 #结果:10.0
    ${res}    Convert To Number    ${item}    ${precision}
    [Return]    ${res}


转成Octal
    [Arguments]    ${item}    ${base}=    ${prefix}=    ${length}=
    ${res}    Convert To Octal    ${item}    ${base}    ${prefix}    ${length}
    [Return]    ${res}


转成String
    [Arguments]    ${item}
    ${res}    Convert To String    ${item}
    [Return]    ${res}


创建List
    [Arguments]    @{items}
    @{list}    Create List    @{items}
    [Return]    @{list}


求值
    [Arguments]    ${expr}    ${modules}=
    [Documentation]    ${status} = 求值 \ 0 < ${result} < 10
    ...
    ...    ${down} = \ 求值 \ int(${result})
    ...
    ...    ${up} = 求值 \ math.ceil(${result}) \ math
    ...
    ...    ${random} = 求值 random.randint(0, sys.maxint) \ random,sys
    ${res}    Evaluate    ${expr}    ${modules}
    [Return]    ${res}


退出For循环
    Exit For Loop


条件成立退出For循环
    [Arguments]    ${arg}
    Exit For Loop If    ${arg}


失败
    [Arguments]    ${msg}=    @{tag}
    [Documentation]    使带有选择标签的测试失败,并给出失败信息,例如:
    ...    失败 "选择失败的case" "aaa" "bbb" "ccc"
    ...    ------------------------------------
    ...    则带有 aaa bbb ccc 标签的测试案例都会失败,并附有 "选择失败的case" 信息
    Fail    ${msg}    @{tag}


致命错误
    [Arguments]    ${msg}=
    [Documentation]    停止所有测试案例执行
    Fatal Error    ${msg}


查找次数
    [Arguments]    ${item1}    ${item2}
    [Documentation]    从item1里面查找item2 出现的次数
    ${res}    Get Count    ${item1}    ${item2}
    [Return]    ${res}


获取长度
    [Arguments]    ${item}
    ${res}    Get Length    ${item}
    [Return]    ${res}


获取Lib实例
    [Arguments]    ${name}
    ${res}    Get Library Instance    ${name}
    [Return]    ${res}


获取时间
    [Arguments]    ${format}=timestamp    ${time_}=NOW
    [Documentation]    ${time}= 获取时间
    ...
    ...    ${secs}= 获取时间 epoch
    ...
    ...    ${year}= 获取时间 return year
    ...
    ...    ${yyyy}= ${mm} ${dd} Get Time year,month,day
    ...
    ...    @{time}= Get Time year month day hour min sec
    ...
    ...    ${y} ${s}= Get Time seconds and year
    ...    ---------------------------------------------------------------------
    ...    ${time} = '2006-03-29 15:06:21'
    ...
    ...    ${secs} = 1143637581
    ...
    ...    ${year} = '2006'
    ...
    ...    ${yyyy} = '2006', ${mm} = '03', ${dd} = '29'
    ...
    ...    @{time} = ['2006', '03', '29', '15', '06', '21']
    ...
    ...    ${y} = '2006'
    ...
    ...    ${s} = '21'
    ${res}    Get Time    ${format}    ${time_}


获取变量值
    [Arguments]    ${name}    ${default}=
    [Documentation]    ${x}= 获取变量值 ${a} default
    ...
    ...    ${y}= 获取变量值 ${a} ${b}
    ...
    ...    ${z}= 获取变量值 ${z}
    ...    -----------------------------------------------
    ...    ${x} gets value of ${a} if ${a} exists and string "default" otherwise
    ...
    ...    ${y} gets value of ${a} if ${a} exists and value of ${b} otherwise
    ...
    ...    ${z} is set to Python `None` if it does not exist previously
    ${res}    Get Variable Value    ${name}    ${default}
    [Return]    ${res}


获取变量
    [Documentation]    返回当前测试案例范围内所有可用变量的字典
    @{vars}    Get Variables
    [Return]    @{vars}


导入库
    [Arguments]    ${name}    @{args}
    [Documentation]    导入给定名字的库和可选的操作参数:
    ...
    ...    当测试案例运行的时候,这个功能允许动态的导入Library.
    ...
    ...    导入库 MyLibrary
    ...
    ...    导入库 ${CURDIR}/../Library.py arg1 named=args
    ...
    ...    导入库 ${LIBRARIES}/Lib.java arg WITH NAME JavaLib
    Import Library    ${name}    @{args}


导入资源
    [Arguments]    ${path}
    [Documentation]    导入给出路径的资源文件:
    ...
    ...    导入资源 ${CURDIR}/resource.txt
    ...
    ...    导入资源 ${CURDIR}/../resources/resource.html
    Import Resource    ${path}


导入变量
    [Arguments]    ${path}    @{args}
    [Documentation]    导入给出路径的变量文件,并给出可选参数。
    ...
    ...    导入变量 ${CURDIR}/variables.py
    ...
    ...    导入变量 ${CURDIR}/../vars/env.py arg1 arg2
    Import Variables    ${path}    @{args}


关键字应该存在
    [Arguments]    ${name}    ${msg}=
    [Documentation]    在当前运行测试案例范围内,关键字应该存在,否则测试失败。
    Keyword Should Exist    ${name}    ${msg}


长度应该是
    [Arguments]    ${item}    ${length}    ${msg}=
    Length Should Be    ${item}    ${length}    ${msg}


多个日志
    [Arguments]    @{msg}
    Log Many    @{msg}


输出变量
    [Arguments]    ${lvl}=INFO
    [Documentation]    输出当前所有范围内给定级别的日志
    Log Variables    ${lvl}


不操作
    [Documentation]    什么都不做
    No Operation


执行通过
    [Arguments]    ${msg}    @{tags}
    [Documentation]    需要参数: 信息,标签
    ...
    ...    作用:使带给定标签的测试案例通过,并添加描述信息。
    Pass Execution    ${msg}    @{tags}


条件成立执行通过
    [Arguments]    ${condition}    ${msg}    @{tags}
    [Documentation]    条件成立时,使带指定标签的案例测试通过,并给出信息。
    Pass Execution If    ${condition}    ${msg}    @{tags}


正则规避
    [Arguments]    @{patterns}
    [Documentation]    这个功能可以使关键字在模式中正常匹配,而不会当做关键字去执行。
    @{regx}    Regexp Escape    @{patterns}
    [Return]    @{regx}


删除标签
    [Arguments]    @{tags}
    [Documentation]    例子:
    ...    删除标签 mytag something-* ?ython
    Remove Tags    @{tags}


重复关键字
    [Arguments]    ${times}    ${name}    @{args}
    [Documentation]    指定关键字重复执行多少次:
    ...
    ...    重复关键字 5 Goto Previous Page
    ...
    ...    重复关键字 ${var} Some Keyword arg1 arg2
    Repeat Keyword    ${times}    ${name}    @{args}


替换变量
    [Arguments]    ${text}
    Replace Variables    ${text}


从关键字返回
    [Arguments]    @{return_values}
    [Documentation]    从未关闭的关键字中返回值。
    @{kwd}    Return From Keyword    @{return_values}
    [Return]    @{kwd}


Find Index
    [Arguments]    ${element}    @{items}
    ${index} =    Set Variable    ${0}
    : FOR    ${item}    IN    @{items}
    \    Return From Keyword If    '${item}' == '${element}'    ${index}
    \    ${index} =    Set Variable    ${index + 1}
    Return From Keyword    ${-1}    # Also [Return] would work here.


条件成立从关键字返回
    [Arguments]    ${condition}    @{return_values}
    @{val}    Return From Keyword If    ${condition}    @{return_values}
    [Return]    @{val}


运行关键字
    [Arguments]    ${name}    @{args}
    [Documentation]    执行给定的关键和相关参数。
    Run Keyword    ${name}    @{args}


运行关键字期望错误
    [Arguments]    ${expected_error}    ${name}    @{args}
    Run Keyword And Expect Error    ${expected_error}    ${name}    @{args}


运行关键字忽略错误
    [Arguments]    ${name}    @{args}
    Run Keyword And Ignore Error    ${name}    @{args}


运行关键字返回状态
    [Arguments]    ${name}    @{args}
    ${stat}    Run Keyword And Return Status    ${name}    @{args}
    [Return]    ${stat}


条件成立运行关键字
    [Arguments]    ${condition}    ${kwd}    @{args}
    Run Keyword If    ${condition}    ${kwd}    @{args}


所有最高级案例通过运行关键字


所有案例通过运行关键字
    [Arguments]    ${name}    @{args}
    Run Keyword If All Tests Passed    ${name}    @{args}


任意最高级案例失败运行关键字
    [Arguments]    ${name}    @{args}
    Run Keyword If Any Critical Tests Failed    ${name}    @{args}


任意案例失败运行关键字
    [Arguments]    ${name}    @{args}
    Run Keyword If Any Tests Failed    ${name}    @{args}


案例失败运行关键字
    [Arguments]    ${name}    @{args}
    Run Keyword If Test Failed    ${name}    @{args}


案例通过运行关键字
    [Arguments]    ${name}    @{args}
    Run Keyword If Test Passed    ${name}    @{args}


超时运行关键字
    [Arguments]    ${name}    @{args}
    Run Keyword If Timeout Occurred    ${name}    @{args}


条件失败运行关键字
    [Arguments]    ${condition}    ${name}    @{args}
    Run Keyword Unless    ${condition}    ${name}    @{args}


运行多个关键字
    [Arguments]    @{args}
    [Documentation]    运行多个关键字 \ Initalize database \ \ \ | \ \ \ \ Start Server \ \ | \ \ \ Clear Logs \
    Run Keywords    @{args}


设置全局变量
    [Arguments]    ${var}    ${val}
    [Documentation]    设置全局变量 \ \ myvar \ \ \ value
    Set Global Variable    ${var}    ${val}


设置库搜索命令
    [Arguments]    @{libs}
    Set Library Search Order    @{libs}


设置日志级别
    [Arguments]    ${lvl}
    Set Log Level    ${lvl}


设置测试套件文档
    [Arguments]    ${doc}    ${append}=False    ${top}=False
    Set Suite Documentation    ${doc}    ${append}    ${top}


设置测试套件标题
    [Arguments]    ${name}    ${value}    ${append}=False    ${top}=False
    Set Suite Metadata    ${name}    ${value}    ${append}    ${top}


设置测试套件变量
    [Arguments]    ${name}    @{values}
    Set Suite Variable    ${name}    @{values}


设置标签
    [Arguments]    @{tags}
    Set Tags    @{tags}


设置测试案例文档
    [Arguments]    ${doc}    ${append}=False
    Set Test Documentation    ${doc}    ${append}


设置测试案例信息
    [Arguments]    ${msg}    ${append}=False
    Set Test Message    ${msg}    ${append}


设置测试案例变量
    [Arguments]    ${name}    @{values}
    Set Test Variable    ${name}    @{values}


设置变量
    [Arguments]    ${values}
    ${var}    Set Variable    ${values}
    [Return]    ${var}


条件成立设置变量
    [Arguments]    ${condition}    @{values}
    ${var}    Set Variable IF    ${condition}    @{values}
    [Return]    ${var}


应该为空
    [Arguments]    ${item}    ${msg}=
    Should Be Empty    ${item}    ${msg}


应该相等
    [Arguments]    ${first}    ${second}    ${msg}=    ${values}=True
    Should Be Equal    ${first}    ${second}    ${msg}    ${values}


转成整数后应该相等
    [Arguments]    ${first}    ${second}    ${msg}=    ${values}=True    ${base}=
    [Documentation]    转成整型后应该相等 \ \ 42 \ ${42} \ 'Error message'
    Should Be Equal As Integers    ${first}    ${second}    ${msg}    ${values}    ${base}


转成数字之后应该相等
    [Arguments]    ${first}    ${second}    ${msg}=    ${values}=Ture    ${precision}=6
    Should Be Equal As Numbers    ${first}    ${second}    ${msg}    ${values}    ${precision}


转成字符串后应该相等
    [Arguments]    ${first}    ${second}    ${msg}=    ${values}=True
    Should Be Equal As Strings    ${first}    ${second}    ${msg}    ${values}


应该为真
    [Arguments]    ${condition}    ${msg}
    Should Be True    ${condition}    ${msg}


应该包含
    [Arguments]    ${item1}    ${item2}    ${msg}=    ${values}=True
    Should Contain    ${item1}    ${item2}    ${msg}    ${values}


应该包含x次
    [Arguments]    ${item1}    ${item2}    ${count}    ${msg}=
    Should Contain X Times    ${item1}    ${item2}    ${count}    ${msg}


结尾应该是
    [Arguments]    ${str1}    ${str2}    ${msg}=    ${values}=True
    [Documentation]    如果str1不是以str2结尾,测试案例失败。
    Should End With    ${str1}    ${str2}    ${msg}    ${values}


应该匹配
    [Arguments]    ${string}    ${pattern}    ${msg}=    ${values}=True
    Should Match    ${string}    ${pattern}    ${msg}    ${values}


应该匹配正则
    [Arguments]    ${string}    ${pattern}    ${msg}=    ${values}=True
    Should Match Regexp    ${string}    ${pattern}    ${msg}    ${values}


应该不为空
    [Arguments]    ${item}    ${msg}=
    Should Not Be Empty    ${item}    ${msg}


应该不相等
    [Arguments]    ${first}    ${second}    ${msg}=    ${values}=True
    Should Not Be Equal    ${first}    ${second}    ${msg}    ${values}


转成整数后应该不相等
    [Arguments]    ${first}    ${second}    ${msg}=    ${values}=True    ${base}=
    Should Not Be Equal As Integers    ${first}    ${second}    ${msg}    ${values}


转成数字后应该不相等
    [Arguments]    ${first}    ${second}    ${msg}=    ${values}=Ture    ${precision}=6
    Should Not Be Equal As Numbers    ${first}    ${second}    ${msg}    ${values}


转成字符串后应该不相等
    [Arguments]    ${first}    ${second}    ${msg}=    ${values}=True
    Should Not Be Equal As Strings    ${first}    ${second}    ${msg}    ${values}


应该为假
    [Arguments]    ${condition}    ${msg}=
    Should Not Be True    ${condition}    ${msg}


不应该包含
    [Arguments]    ${item1}    ${item2}    ${msg}=    ${values}=True
    Should Not Contain    ${item1}    ${item2}    ${msg}    ${values}


结尾应该不是
    [Arguments]    ${str1}    ${str2}    ${msg}=    ${values}=True
    Should Not End With    ${str1}    ${str2}    ${msg}    ${values}


不应该匹配
    [Arguments]    ${string}    ${pattern}    ${msg}=    ${values}=True
    Should Not Match    ${string}    ${pattern}    ${msg}    ${values}


不应该匹配正则
    [Arguments]    ${string}    ${pattern}    ${msg}=    ${values}=True
    Should Not Match Regexp    ${string}    ${pattern}    ${msg}    ${values}


开头不应该是
    [Arguments]    ${string}    ${pattern}    ${msg}=    ${values}=True
    Should Not Start With    ${string}    ${pattern}    ${msg}    ${values}


开头应该是
    [Arguments]    ${string}    ${pattern}    ${msg}=    ${values}=True
    Should Start With    ${string}    ${pattern}    ${msg}    ${values}


睡眠
    [Arguments]    ${time}    ${reason}=
    [Documentation]    睡眠 42
    ...
    ...    睡眠 1.5
    ...
    ...    睡眠 2 minutes 10 seconds
    ...
    ...    睡眠 10s \ 'Wait for a reply'
    Sleep    ${time}    ${reason}


变量应该存在
    [Arguments]    ${name}    ${msg}=
    Variable Should Exist    ${name}    ${msg}


变量应该不存在
    [Arguments]    ${name}    ${msg}=
    Variable Should Not Exist    ${name}    ${msg}


等待关键字成功
    [Arguments]    ${timeout}    ${retry_interval}    ${name}    @{args}
    Wait Until Keyword Succeeds    ${timeout}    ${retry_interval}    ${name}    @{args}
根据你提供的批处理文件内容以及错误信息,问题出在合并测试报告时,原因是合并的输出包含不同的根测试套件。 在你的批处理文件中,你分别执行了三个测试套件,并将它们的输出分别保存为`output1.xml`、`output2.xml`和`output3.xml`。然后你使用`rebot`命令合并这些输出文件生成最终的测试报告。 然而,错误信息提示无法合并包含不同根测试套件的输出。具体来说,原始测试套件是'Goodlistsuite',而被合并的是'Singalgoodcombi'。 要解决这个问题,你需要确保合并的输出文件具有相同的根测试套件。可以通过以下方式进行修改: 1. 检查测试套件文件中的根测试套件名称,确保它们的名称相同。 2. 确保`Goodlistsuite.robot`、`Singalgoodcombi.robot`和`Goodgroupsuite.robot`文件中的根测试套件名称相同。 3. 在执行`robot`命令时,使用`--name`选项为每个测试套件指定一个相同的根测试套件名称。 例如: ```bat @echo off set ROBOT_REPORT_DIR=reports robot --outputdir %ROBOT_REPORT_DIR% --variablefile "variables.py" --name "MyRootSuite" --test test_* --output output1.xml "Goodmanage\Goodlistsuite.robot" robot --outputdir %ROBOT_REPORT_DIR% --variablefile "variables.py" --name "MyRootSuite" --test test_* --output output2.xml "Goodmanage\Singalgoodcombi.robot" robot --outputdir %ROBOT_REPORT_DIR% --variablefile "variables.py" --name "MyRootSuite" --test test_* --output output3.xml "Goodmanage\Goodgroupsuite.robot" rebot --outputdir %ROBOT_REPORT_DIR% --output final_report.html --merge %ROBOT_REPORT_DIR%\output1.xml %ROBOT_REPORT_DIR%\output2.xml %ROBOT_REPORT_DIR%\output3.xml ``` 请确保在执行`robot`命令时,将`--name`选项的值设置为相同的根测试套件名称。然后使用`rebot`命令合并输出文件生成最终的测试报告。这样应该可以解决合并输出文件时出现不同根测试套件的问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值