简体   繁体   English

Robot Framework - 运行关键字if后执行多个关键字

[英]Robot Framework - performing multiple keywords after running keyword if

I am trying to execute multiple keywords if a condition evaluates as true. 如果条件评估为true,我试图执行多个关键字。

I tried to do something like this 我试着这样做

 *** Test Cases ***
| Example

 *** Keywords ***
| Example
|  | ${title}=  Get Title
|  | Run Keyword If      | '${title}' == 'Some Title' 
|  | ... Click Element   |  xpath=some element 
|  | ... Element Text Should Be  |   xpath=some element   |  some text
|  | ... Else
|  | ... Click Element   | xpath=other element  

The error I get when running this is that the Click Element expects 1 argument but gets 4. 运行它时得到的错误是Click Element需要1个参数但得到4。

I know that I can set the if statement in the Test cases section and if evaluated true it will run a keyword with all the stuff I want but I wonder if there is a way to do it from the Keywords section. 我知道我可以在测试用例部分设置if语句,如果评估为true,它将运行一个包含我想要的所有东西的关键字,但我想知道是否有办法从关键字部分进行操作。

Thanks. 谢谢。

You can do a couple of things. 你可以做几件事。 The first is to create a new keyword that calls all the other keywords, and then call that from Run keyword if . 第一种是创建一个调用所有其他关键字的新关键字,然后从Run keyword if调用它。 This might be the most readable solution, but at the expense of having to write and document another keyword. 这可能是最易读的解决方案,但代价是必须编写和记录另一个关键字。

The other choice is to use a combination of Run keyword if and Run keywords , like so: 另一种选择是使用Run keyword ifRun keywords的组合,如下所示:

| | Run Keyword if | '${title}' == 'Some Title'
| | ... | Run Keywords
| | ... | Click Element | xpath=some element
| | ... | AND | Element Text Should Be  |  xpath=some element | some text
| | ... | ELSE
| | ... | Click Element | xpath=other element

Run keywords does not take keywords with arguments so you cannot use this.Option is to create keyword for all statements below Run keywords and call it. 运行关键字不会带有带参数的关键字,因此您不能使用它。选项是为运行关键字下面的所有语句创建关键字并调用它。 https://robotframework.googlecode.com/svn/trunk/doc/libraries/BuiltIn.html#Run --User keywords must nevertheless be used if the executed keywords need to take arguments. https://robotframework.googlecode.com/svn/trunk/doc/libraries/BuiltIn.html#Run -如果执行的关键字需要参数,则必须使用用户关键字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM