簡體   English   中英

如何在Robot Framework中編寫if語句的多個條件

[英]How to write multiple conditions of if-statement in Robot Framework

我有麻煩寫作if在機器人的框架條件。

我想執行

Run Keyword If '${color}' == 'Red' OR '${color}' == 'Blue'  OR '${color}' == 'Pink'    Check the quantity

我可以在一個條件下使用這個“ Run keyword If ”關鍵字,但對於多個條件,我收到此錯誤:

失敗:關鍵字名稱不能為空。

我還想使用這些關鍵字:

Run Keyword If '${color} == 'Blue' AND '${Size} == 'Small' AND '${Design}' != '${Simple}'      Check the quantity

Run Keyword Unless '${color}' == 'Black' OR '${Size}' == 'Small' OR '${Design}' == 'Simple'

但我最終得到的錯誤。

您應該使用小型大寫字母“或”和“和”代替OR和AND。

並且還要注意關鍵字和參數之間的空格/制表符(至少需要兩個空格)。

這是一個代碼示例,您的三個關鍵字正常工作:

這是文件ts.txt

  *** test cases ***
  mytest
    ${color} =  set variable  Red
    Run Keyword If  '${color}' == 'Red'  log to console  \nexecuted with single condition
    Run Keyword If  '${color}' == 'Red' or '${color}' == 'Blue' or '${color}' == 'Pink'  log to console  \nexecuted with multiple or

    ${color} =  set variable  Blue
    ${Size} =  set variable  Small
    ${Simple} =  set variable  Simple
    ${Design} =  set variable  Simple
    Run Keyword If  '${color}' == 'Blue' and '${Size}' == 'Small' and '${Design}' != '${Simple}'  log to console  \nexecuted with multiple and

    ${Size} =  set variable  XL
    ${Design} =  set variable  Complicated
    Run Keyword Unless  '${color}' == 'Black' or '${Size}' == 'Small' or '${Design}' == 'Simple'  log to console  \nexecuted with unless and multiple or

這是我執行時得到的:

$ pybot ts.txt
==============================================================================
Ts
==============================================================================
mytest                                                                .
executed with single condition
executed with multiple or
executed with unless and multiple or
mytest                                                                | PASS |
------------------------------------------------------------------------------

只需確保在“和”關鍵字之前和之后放置單個空格。

以下代碼工作正常:

Run Keyword if    '${value1}' \ \ == \ \ '${cost1}' \ and \ \ '${value2}' \ \ == \ \ 'cost2'    LOG    HELLO

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM