本文介绍了如何在Robot Framework中编写if语句的多个条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Robot Framework 中编写 if 条件时遇到问题.

I have trouble writing if conditions in Robot Framework.

我要执行

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

我可以在一个条件下使用这个Run keyword If"关键字,但是对于多个条件,我得到了这个错误:

I can use this "Run keyword If" keyword with one condition, but for more than one conditions, I got this error:

失败:关键字名称不能为空.

我还想使用这些关键字:

And also I would like to use these keywords:

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",而不是 OR 和 AND.

You should use small caps "or" and "and" instead of OR and AND.

还要注意关键字和参数之间的空格/制表符(您至少需要两个空格).

And beware also the spaces/tabs between keywords and arguments (you need at least two spaces).

这是一个代码示例,您的三个关键字都可以正常工作:

Here is a code sample with your three keywords working fine:

这是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

这是我执行它时得到的:

and here is what I get when I execute it:

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

这篇关于如何在Robot Framework中编写if语句的多个条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 12:33