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

Pur*_*eni 4 robotframework selenium-webdriver

如果条件评估为true,我试图执行多个关键字.

我试着这样做

 *** 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  
Run Code Online (Sandbox Code Playgroud)

运行它时得到的错误是Click Element需要1个参数但得到4.

我知道我可以在测试用例部分设置if语句,如果评估为true,它将运行一个包含我想要的所有东西的关键字,但我想知道是否有办法从关键字部分进行操作.

谢谢.

Bry*_*ley 8

你可以做几件事.第一种是创建一个新的关键字,调用所有其他关键字,然后从中调用Run keyword if.这可能是最易读的解决方案,但代价是必须编写和记录另一个关键字.

另一种选择是使用的组合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 Code Online (Sandbox Code Playgroud)

  • 使用“运行关键字”时,请确保使用大写“AND”(根据文档使用带有参数的关键字时需要) (2认同)