(转)Should 断言的基本使用方法

摘要:
下面将逐个举例介绍RobotFramework提供的断言关键字。@{list_a}createlist1a${21}2112@{list_b}setvariable1.0a${21}2121@{list_c}createlist${string}setvariablepengliwenisinhangzhou${name}setvariableplw备注:以下提供的用例都是断言成功。

一、基础

RobotFramework带有丰富的系统关键,使用时无需导入,直接使用,为写自动化用例带来了极大的方便;不能停留在知道或者是会得程度,只有熟练使用各关键字,才能提升自动化用例的写作效率。下面将逐个举例介绍RobotFramework提供的断言关键字。

二、实例

为方便讲解,首先创建三个list变量:list_a、list_b、list_c;以及两个scalar变量:string和name。

@{list_a}create list1a${21}2112
@{list_b}set variable1.0a${21}2121
@{list_c}create list
${string}set variablepengliwen is in hangzhou
${name}set variableplw

备注:以下提供的用例都是断言成功。

01、should contain、 should not contain 与should contain x times

should contain${list_b}1.0
should not contain${list_b}1
should contain x times${list_b}212

说明:变量${list_b}包含对象1.0而不包含对象1,且对象21在变量${list_b}出现了两次。

02、should be empty与 should not be empty

should be empty${list_c}
should not be empty${list_a}

说明:变量${list_c}没有赋值,所以为空;相反,变量${list_a}有赋初始值,故为非空。

03、should be equal 与should not be equal

should be equal${list_a[1]}${list_b[1]}
shouldnot be equal${list_a}${list_b}

说明:${list_a[1]}=a${list_b[1]}=a故两个对象相等;而${list_a}和${list_b}有元素不一致,这两个对象不相等。

04、Should Be Equal As NumbersShould not Be Equal As Numbers

Should Be Equal As Numbers${list_b[0]}1.0000
Should not Be Equal As Numbers${list_b[0]}1.1

说明:${list_b[0]}=1,忽略精度,故与1.0000相等;而即使是忽略精度,1与1.1还是不相等的;

05、Should Be Equal As IntegersShould not Be Equal As Integers

Should Be Equal As Integers${list_a[3]}${list_b[3]}
Should not Be Equal As Integers${list_a[4]}${list_b[4]}

说明:${list_a[3]}=21,${list_b[3]}=21,而系统默认为字符串格式的“21”,故需要转化为整数类型,转化为整数后两个对象相等;

${list_a[4]}=12,${list_b[4]}=21,即使转化为整数后两个对象依旧是不相等;

06、Should Be Equal As StringsShould not Be Equal As Strings

Should Be Equal As Strings${list_a[2]}${list_b[2]}
Should not Be Equal As Strings${list_a[0]}${list_b[0]}

说明:${list_a[2]}=${21},${list_b[2]}=${21},而均为数值型的21,故需要转化为字符串类型,转化为字符串后两个对象相等;

07、Should Be TrueShould not Be True

Should Be True${list_a[0]} < 10
Should not Be True${list_a[0]} < 1

说明:${list_a[0]}=1(字符串类型),其ASCII值比字符串10的ASCII值小;

08、Should start WithShould not start With
Should start With${string}peng
Should not start With${string}h

说明:${string}=”pengliwen is in hangzhou“是以peng开头,而非以h开头;

09、Should End WithShould not End With

Should End With${string}hangzhou
Should not End With${string}pengliwen

说明:${string}=”pengliwen is in hangzhou“是以hangzhou结尾,而非以pengliwen结尾

10、should matchshould not match

should match${name}p??
should not match${string}h?*

说明:模式匹配和shell中的通配符类似,它区分大小写,'*'匹配0~无穷多个字符,单个字符

${name}=plw,由以p开头的三个字母组成

11、Should Match RegexpShould not Match Regexp

Should Match Regexp${name}^\w{3}$
Should not Match Regexp${name}^\d{3}$

说明:反斜杠在测试数据是转义字符,因此模式中要使用双重转义;'^''$'字符可以用来表示字符串的开头和结尾

${name}=plw,是有三个字母--w{3}组成,而不是由三个数字--d{3}组成。

免责声明:文章转载自《(转)Should 断言的基本使用方法》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇django学习-29.表单提交方式之一:post请求(注册/登录/改密)fatfs源码阅读下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

[zz]Linux中的/etc/profile文件

【一、让/etc/profile文件修改后立即生效】 方法1:让/etc/profile文件修改后立即生效 ,可以使用如下命令:# .  /etc/profile注意: . 和 /etc/profile 有空格方法2:让/etc/profile文件修改后立即生效 ,可以使用如下命令:# source /etc/profile附:Linux中source命令...

VUE清除组件内部定时器

  定时器如果不手动清除,只会在离开当前页面或者F5刷新后才会清除。由于vue项目是SPA应用,离开当前组件后并不会清除定时器,所以需要我们手动去清除定时器。但当我们将清除定时器clearInterval或clearTimeout写入组件的生命周期destroyed内部时并不能清除定时器,直接写window.clearXXX也并不是很好使。网上查了好久,有...

erlang 入门(1)

erl- 命令以.结尾- %为注释- 变量必须大写开头 X = 12.- [1,3.4,true] is a list and {person, 25, "Jason"} is a tuple. - tuple赋值orpattern match{ip, IP} = {ip, "192.168.0.1"}.{Atom, IP} = {ip, "192.168...

C# 编码规范、命名规则

1  规范目的 ……………………………………………………… 3 2  适用范围 ……………………………………………………… 3 3  代码注释 ……………………………………………………… 3   3.1    代码注释约定............................................ 3   3.2    模块头部注释规范.......

postman_03_引用随机变量($guid,$timestamp,$randomInt)_and_参数引用外部文件

在接口测试中,有些接口的请求参数具有唯一性,比如注册接口,注册一个账号后就不能重复注册了。为了能重复执行这个接口,可以在请求前清理测试数据,也可以把请求的参数设置成一个可变的值(每次不一样),这样就可以每次都能注册成功了。 使用动态变量 postamn 提供可在请求中使用的动态变量: {{$guid}} :v4样式的         {{$guid}} ...

Tensorflow 变量的共享

    https://github.com/chenghuige/tensorflow-exp/blob/master/examples/sparse-tensor-classification/     tensorflow-exp/example/sparse-tensor-classification/train-validate.py 当你需要...