robot framework 怎么验证搜索无记录,页面元素不存在

假设你要验证搜索无记录,页面元素不存在,假设我搜索的文本为你好

页面展示为如下

搜索:你好

假设页面搜索有结果:

你好  class=vtext

你好1  class=vtext

你好2  class=vtext

 

搜索:你好

假设页面搜索无数据:

ps:空白

方法一,这种适合简单逻辑,断言之后,再进行其他操作,不需要判断状态正确或错误需要进行分支操作。

下面是反例子容易写错,下面的status的值永远都是none,不管正确与否

想要正确使用返回状态应该使用关键字Run Keyword And Return Status

方法二,同样用到关键字Run Keyword And Return Status,这次换了另外一个关键字 Element Should Be Visible

css=.vtext 取的是查询出来有数据这一列的class,不存在的话就返回false

总结

${status}=    Run Keyword And Return Status    Page Should Contain   XXX                                  ---------页面包含XXX文本,如果页面文本是唯一的,可以用这个关键字

${status1}=    Run Keyword And Return Status    Element Should Be Visible    css=.login              -----------如果文本不是唯一的,可以定位它的属性,可以用这个关键字加location

${situation2}=    Run Keyword And Return Status    Textfield Value Should Be    css=.tit    XXX      -------------如果需要判断文本,然而需要精确搜索,而不是contain关系

posted @ 2017-08-03 16:10  鸭血  阅读(2357)  评论(0编辑  收藏  举报