我刚刚开始研究Robot Framework,我正在尝试使用Try Keyword If关键字,但我在网上看到的所有示例都在一行中显示了解决方案,而我在RIDE中有列和行.
如果我在当前页面上有一个ID为"当前状态"的按钮,那么我想转到URL www.xyz.com并执行一些操作.混淆是当我Run Keyword If在RIDE中的测试用例的第一个单元格中写入时,我应该在第二列中写什么?这应该是Page Should Contain?还是Page Should Not Contain?
请告诉我上面缺少的信息.
Bry*_*ley 12
如果您使用的是Run Keyword If,则第二列必须是python表达式而不是另一个关键字.这在关键字文档中有解释.例如(为清晰起见,使用管道分隔格式):
| | Run keyword if | ${answer} == 42 | Go to | http://www.example.com
Run Code Online (Sandbox Code Playgroud)
如果仅在页面具有id为"当前状态"的元素时才要运行关键字,则需要首先确定页面是否包含该元素,然后在表达式中使用该元素.有很多方法可以做到这一点.该文档显示了如何使用"运行关键字并忽略错误",它看起来像这样:
| | ${status} | ${value}= | Run keyword and ignore error | Page should contain | //*[@id='Current Status']
| | Run Keyword if | '${status}' == 'PASS' | Go to | http://www.example.com
Run Code Online (Sandbox Code Playgroud)
还有其他方法可以完成同样的事情.例如,您可以计算页面上包含ID的项目数,并且只有在计数大于零时才运行关键字:
| | # determine if something on the page has an id of 'Current Status'
| | ${count}= | Get matching xpath count | //*[@id='Current Status']
| | # if there is at least one item on the page with that id, go to xyz.com
| | Run keyword if | ${count} > 0 | Go to | http://www.example.com
Run Code Online (Sandbox Code Playgroud)
如果您想执行多个步骤,例如转到页面并进行一些验证,最直接的事情就是创建一个单独的关键字,然后调用它.
...
| | Run keyword if | ${count} > 0 | Do extra validation
*** Keywords ***
| Do extra validation
| | Go to | http://www.example.com
| | Page should contain | Hello, world
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
43416 次 |
| 最近记录: |