【问题标题】:How to use TRUE and PASS values for the test cases in Robot Framework?如何在 Robot Framework 中为测试用例使用 TRUE 和 PASS 值?
【发布时间】:2017-02-13 09:55:53
【问题描述】:

我是 Robot Framework 的新手,所以我需要帮助我正在尝试执行“RUN KEYWORD IF”,如果我查看他们提供的文档 运行关键字 If | '${状态}' == '通过' |一些操作参数

我怀疑这个 PASS 值。如何在每次尝试时得到这个,我为每个关键字语句得到一个无值。我正在尝试这样做:

*** Settings ***

*** Variables ***
${name}      theon

*** Test Cases ***
Verify
    ${x}=    Set Variable    function
    Run Keyword If    '${x}==PASS'    Log 'True'
    ...    ELSE    Log    'False'

*** Keywords ***
function
    ${return}=    Should Equal    ${name}    theon
    [Return]    ${return}

我收到错误,x 被定义为 NONE 然后我如何在我的关键字是成功或 True 的条件下进行验证。

我还想知道是否可以使用自定义关键字代替“条件”来运行某些关键字。

运行关键字如果||这里的一些 self 关键字返回我 pass 或 true||目标关键字

【问题讨论】:

    标签: robotframework


    【解决方案1】:

    应该等于做什么? 由于它在 RF 中不存在,因此 应该相等 但这只是通过或未通过测试。 请注意所有应该...的行为都是这样的。

    如果 ${name}theon 相等(相同),也许你想要评估然后使用 evaluate ...

    ${return}=    evaluate    '${name}'=='theon'
    

    Evaluate 将返回 True 或 False

    那么这将起作用。

    Run Keyword if    ${x}    Log    True
    

    【讨论】:

    • 我可以这样做吗:||运行关键字 if | ${return} = 评估 '${name}'=='theon' |记录真 || ??...在文档中,他们给出了语法((Run Keyword If '${status}' == 'PASS' Some Action arg))我想使用这个'PASS'以某种方式将我的自定义关键字嵌套在条件中。
    • 为什么要在条件中嵌套关键字?
    • 据我所知嵌套条件在机器人框架中不起作用。
    • 但这会起作用Run Keyword if '${name}'=='theon' Log Name is theon我的回答是为了适应你的例子。
    • 但我仍然不能 100% 确定您的 PASS 是什么。 *** Settings *** *** Variables *** ${name} theon *** Test Cases *** Verify ${x}= function Run Keyword If ${x} Log True ... ELSE Log False Run Keyword If '${name}'=='theon' Log True ... ELSE Log False *** Keywords *** function ${return}= evaluate '${name}'=='theon' [Return] ${return}
    【解决方案2】:

    您可以直接提供“条件”而不是“状态”,然后使用“自定义关键字”执行特定操作

    下面的例子:

    Run Keyword if  ${medicine_expiry_year} > 2000 and ${medicine_expiry_year} < 2016    Send Mail to Company   ${company_mail_id}
    Run Keyword if  ${medicine_expiry_year} == 2016  Report Remaining Months to Store operator  ${month_of_expiry}  
    Run Keyword if  ${medicine_expiry_year} > 2016   Log     "Keep the medicine"
    

    上例中的条件:

    ${medicine_expiry_year} > 2000 and ${medicine_expiry_year} < 2016  
    ${medicine_expiry_year} == 2016
    ${medicine_expiry_year} > 2016
    

    带参数的自定义关键字:

    使用关键字“send Main to Company”向公司发送邮件,邮件 ID 在“${company_mail_id}”中提供

     Send Mail to Company   ${company_mail_id} 
    

    使用关键字“Report the Remaining Months to Store operator”报告 Remaining Months to Store 运算符,使用变量“${month_of_expiry}”提供的到期月份

    Report Remaining Months to Store operator  ${month_of_expiry}   
    

    只需使用关键字记录消息

    Log  "Keep the medicine"
    

    希望这对您有所帮助。

    【讨论】:

      猜你喜欢
      • 2016-01-13
      • 2022-08-20
      • 2019-09-03
      • 2013-04-07
      • 2016-05-05
      • 2014-02-27
      • 2017-09-21
      • 1970-01-01
      • 2018-12-14
      相关资源
      最近更新 更多