如何在机器人框架中使用从一个关键字到另一个关键字的值

时间:2019-04-02 06:36:10

标签: robotframework

我想使用从关键字1到关键字2的值。尝试过在网上搜索,但无法解决。

Verify that apps are listed
    wait until element is visible  ${AppMenuGrid}   ${Timeout}      "Apps NOT listed. Step execution failed"
    log     "Apps listed"
    ${APPSCOUNT} =   GET ELEMENT COUNT  ${AppMenuGrid}
    log     "Number of apps loaded are ${APPSCOUNT}"
    [Return]  ${APPSCOUNT}

Click on Refresh button
    wait until element is visible  ${Refresh}   ${Timeout}      "Refresh button is not visible"
    click element  ${Refresh}
    log     "click on refresh button successful"

Verify that same apps are listed
    wait until element is visible  ${AppMenuGrid}   ${Timeout}      "Apps list not refreshed. Step execution failed"
    log     "Apps list refreshed"
    ${APPSRECOUNT} =   GET ELEMENT COUNT  ${AppMenuGrid}
    ${Count} =  verify that apps are listed     ${APPSCOUNT}
    log     "Number of apps before refresh ${Count}"
    log     "Number of apps after refresh ${APPSRECOUNT}"
    run keyword if  "${APPSRECOUNT}" == "${Count}"      log     "Number of apps matching after refresh"
    ...         ELSE        fail        "All apps not loaded after refresh"

我想使用“验证清单中列出的应用程序”关键字到“验证清单相同的应用程序”关键字中的AppsCount值(例如.10)。但是在第二个关键字中,APPSCOUNT值始终为空。

3 个答案:

答案 0 :(得分:2)

更改关键字Verify that same apps are listed以接受参数:

Verify that same apps are listed
    [Arguments]    ${expected appscount}
    # the rest of its code

然后,在使用它的情况下,从第一个关键字传递值:

A case
    ${the count}=    Verify that apps are listed
    Verify that same apps are listed    ${the count}

答案 1 :(得分:1)

我同意Todor Minakov的方法,即通过return子句共享价值。这是另一种方法:

机器人框架(如User Guide中所述)具有可变范围的概念:本地(关键字)级别,测试用例级别,测试套件级别和全局。默认情况下,关键字中定义的变量具有局部作用域。

要在两个关键字之间共享变量的值,只需向变量添加测试用例范围,如下所示:

           let Toll: [String: Any] = [
                "tolls": completeBody.data.meta as Any
            ]
            let params: [String: Any] =  [
                "destination": completeBody.data.destination!,
                "distance": completeBody.data.distance!,
                "champion_id": completeBody.data.championId!,
                "meta": Toll
            ]

然后,您可以在同一测试用例中的任何其他关键字内调用Verify that apps are listed wait until element is visible ${AppMenuGrid} ${Timeout} "Apps NOT listed. Step execution failed" log "Apps listed" ${APPSCOUNT} = GET ELEMENT COUNT ${AppMenuGrid} Set Test Variable ${APPSCOUNT} ,它将具有存储的值。

答案 2 :(得分:0)

我尝试了以下方法,并且有效。

在测试用例文件中,我添加了一个名称为$ {APPSCOUNT}的变量,并将变量设置为如下所示的关键字, 验证应用已列出$ {APPSCOUNT}

此后,我可以看到关键字2中关键字1的值。 这是正确的方法吗?