Robot Framework - 在 运行 关键字后执行多个关键字 if
Robot Framework - performing multiple keywords after running keyword if
我正在尝试在条件评估为真时执行多个关键字。
我试过这样做
*** 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
我在 运行 时得到的错误是点击元素需要 1 个参数但得到 4 个。
我知道我可以在测试用例部分设置 if 语句,如果评估为真,它将 运行 一个包含我想要的所有内容的关键字,但我想知道是否有办法从关键字部分。
谢谢。
你可以做几件事。第一个是创建一个调用所有其他关键字的新关键字,然后从 Run keyword if
调用它。这可能是最易读的解决方案,但代价是必须编写和记录另一个关键字。
另一个选择是使用 Run keyword if
和 Run 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
运行 关键字不接受带参数的关键字,因此您不能使用 this.Option 是为 运行 关键字下面的所有语句创建关键字并调用它。
https://robotframework.googlecode.com/svn/trunk/doc/libraries/BuiltIn.html#Run
--如果执行的关键字需要带参数,则必须使用用户关键字。
我正在尝试在条件评估为真时执行多个关键字。
我试过这样做
*** 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
我在 运行 时得到的错误是点击元素需要 1 个参数但得到 4 个。
我知道我可以在测试用例部分设置 if 语句,如果评估为真,它将 运行 一个包含我想要的所有内容的关键字,但我想知道是否有办法从关键字部分。
谢谢。
你可以做几件事。第一个是创建一个调用所有其他关键字的新关键字,然后从 Run keyword if
调用它。这可能是最易读的解决方案,但代价是必须编写和记录另一个关键字。
另一个选择是使用 Run keyword if
和 Run 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
运行 关键字不接受带参数的关键字,因此您不能使用 this.Option 是为 运行 关键字下面的所有语句创建关键字并调用它。 https://robotframework.googlecode.com/svn/trunk/doc/libraries/BuiltIn.html#Run --如果执行的关键字需要带参数,则必须使用用户关键字。