robotframework - 当在机器人框架中找不到元素时,如何在测试期间在控制台中显示消息?
问题描述
我想知道当机器人框架找不到元素时如何在控制台中显示消息:
我试过这个:
S2L.Wait Until Page Contains Element ${checkbox} 10s checkbox not found
它不适用于这个元素,不知道为什么。它适用于任何其他元素,但不适用于我的复选框。
所以现在我有这个:
Wait Until Keyword Succeeds 5 times 2 sec S2L.Click Element ${checkbox}
但是当它失败时,它只说找不到元素,我更愿意编写个性化消息。
欢迎任何帮助。谢谢
解决方案
尽管我确实认为您的问题有所不同,但可以回答您的问题。Run Keyword And Return Status
将捕获错误并继续并提供状态。Run Keyword If
然后允许使用关键字Fail
,它还将在控制台上生成一条消息。
*** Settings ***
Library SeleniumLibrary
Suite Teardown Close All Browsers
*** Test Cases ***
Wait And Click succesfully
Open Browser http://google.com HeadlessChrome
Wait and Click Element name:q This should work
Wait And Click unsuccesfully
Open Browser http://google.com HeadlessChrome
Wait and Click Element name:nobtn This should not work
*** Keywords ***
Wait and Click Element
[Arguments] ${locator} ${message}=None
${status} Run Keyword And Return Status
... Wait Until Keyword Succeeds
... 5 times 2 sec
... Click Element ${locator}
Run Keyword If
... "${status}" == "False"
... Fail ${message}
推荐阅读
- linux - 为 shell 脚本中的每一个单独的输出使用多个参数
- r - BESTmcmc(y1, y2) 中的错误:在 Rstudio 中找不到函数“BESTmcmc”
- bash - 在 .txt 文件中查找字符串 - 没有成功
- javascript - 在第一次单击时,圆圈会突然改变位置并移动 a 或 w
- python-3.x - 如何在python中使用unicode解码字符串?
- asp.net-core-webapi - 在 ASP.NET Core 托管服务中从何处开始监视队列
- bash - 操作系统在哪里获取 $OSTYPE 的值
- ios - iPhone XR 的金属性能
- r - 添加到标量/向量`1`中的每个数字并在该数字之后插入结果
- c# - 使用字典进行散列