【问题标题】:Can not create variable in [setup] robot framework无法在 [setup] 机器人框架中创建变量
【发布时间】:2021-03-01 21:28:40
【问题描述】:

我正在尝试在测试设置中创建一个变量,但它出错了

*** Test Cases ***    
Set Volume Normalisation Level
[Setup]     Run Keywords     ${is_exist}=    Get Exist Element

            ...         AND             Pass Execution If   "${is_exist}" == "True"    Element is not exist
[Template]  Set Volume Normalisation Level
    value=25    actual_value=25
    value=50    actual_value=50
    value=75    actual_value=75
    value=100    actual_value=100
*** Keywords ***
Get Exist Element
    ${present}=    Run Keyword And Return Status    Page Should Contain Element   xpath://div[text()="Normalization"]
    Return From Keyword     ${present}

Set Volume Normalisation Level
    [Arguments]  ${value}  ${actual_value}
    Drag Vol Norm Slider To  ${value}
    Sleep  .5
    Vol Norm Slider Value Should Be  ${actual_value}

=> 变量 ${is_exist} 未找到。

虽然我尝试使用设置测试变量,但它不适用于关键字

*** Test Cases ***    
[Setup]     Run Keywords    Set Test Variable    ${is_exist}    Get Exist Element
            ...         AND             Pass Execution If   "${is_exist}" == "True"    Element is not exist

=> ${is_exist} 获取字符串值:获取现有元素 如何在测试设置中创建变量从关键字获取值

【问题讨论】:

    标签: robotframework


    【解决方案1】:

    最简单的方法是创建一个新的用户关键字,而不是使用Run Keywords。以您为例:

    *** Keywords ***
    My Test Setup Keyword
        ${is_exist}=    Get Exist Element
        Pass Execution If   "${is_exist}" == "True"    Element is not exist
    
    *** Test Cases ***
    Set Volume Normalisation Level
        [Setup]    My Test Setup Keyword
        # Rest of the test case
    

    【讨论】:

    • 太棒了。这是最简单的方法!顺便说一句,如果 SETUP 中的关键字返回 false,我的目的是忽略 TEMPLATE 和 TEARDOWN。我尝试在 Template 和 Teardown 中运行关键字 Get Exist Element。有效。有没有更好的办法?非常感谢!
    • @HieuNguyen 在设置中这样做是我认为的最佳方式。这是在测试运行之前做出决定和准备的正确场所。
    猜你喜欢
    • 2020-12-07
    • 2020-01-22
    • 2019-02-18
    • 2021-02-06
    • 2016-05-11
    • 1970-01-01
    • 2021-11-23
    • 1970-01-01
    • 2015-10-09
    相关资源
    最近更新 更多