(转)Should 断言的基本使用方法
一、基础
RobotFramework带有丰富的系统关键,使用时无需导入,直接使用,为写自动化用例带来了极大的方便;不能停留在知道或者是会得程度,只有熟练使用各关键字,才能提升自动化用例的写作效率。下面将逐个举例介绍RobotFramework提供的断言关键字。
二、实例
为方便讲解,首先创建三个list变量:list_a、list_b、list_c;以及两个scalar变量:string和name。
@{list_a} create list 1 a ${21} 21 12
@{list_b} set variable 1.0 a ${21} 21 21
@{list_c} create list
${string} set variable pengliwen is in hangzhou
${name} set variable plw
备注:以下提供的用例都是断言成功。
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} 21 2
说明:变量${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]}
should not be equal ${list_a} ${list_b}
说明:${list_a[1]}=a,${list_b[1]}=a故两个对象相等;而${list_a}和${list_b}有元素不一致,这两个对象不相等。
04、Should Be Equal As Numbers 与 Should 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 Integers与Should 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 Strings与Should 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 True与Should 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 With与Should not start With
Should start With ${string} peng
Should not start With ${string} h
说明:${string}=”pengliwen is in hangzhou“是以peng开头,而非以h开头;
09、Should End With与Should not End With
Should End With ${string} hangzhou
Should not End With ${string} pengliwen
说明:${string}=”pengliwen is in hangzhou“是以hangzhou结尾,而非以pengliwen结尾;
10、should match与should not match
should match ${name} p??
should not match ${string} h?*
说明:模式匹配和shell中的通配符类似,它区分大小写,'*'匹配0~无穷多个字符,“?”单个字符
${name}=plw,由以p开头的三个字母组成
11、Should Match Regexp与Should not Match Regexp
Should Match Regexp ${name} ^\\w{3}$
Should not Match Regexp ${name} ^\\d{3}$
说明:反斜杠在测试数据是转义字符,因此模式中要使用双重转义;'^'和'$'字符可以用来表示字符串的开头和结尾
${name}=plw,是有三个字母--w{3}组成,而不是由三个数字--d{3}组成。
(转)Should 断言的基本使用方法的更多相关文章
- asscert断言的几种方法
一.什么是断言 执行完测试用例后,最后一步是判断测试结果是通过还是失败,在自动化脚本中一般把这种生成测试结果的方法叫做断言 它用来检查一个条件,如果它为真,则不做任何事,如果它为假,则会跑出Asser ...
- Junit4中的新断言assertThat的使用方法
如果需要是用assertThat需要在项目中引入junit4的jar包.(匹配器和断言方法在junit4的jar包中都能找到,引入就可以了) 下面是常用断言的代码 1 import static or ...
- Jmeter-接口测试参数化后循环断言不同内容的方法
前言 各位小伙伴在做接口自动化有没遇到过这样的问题,CSV文件参数化测试数据后,只能通过人工的的方法去查看结果,不懂写代码去循环断言返回的结果.今天我们来学习一下,不用写代码,就用响应断言,怎么实现循 ...
- node.js自动化测试断言包assert的方法说明
参考以下文档 http://yijiebuyi.com/blog/ca2c0edf447624bd4d527490c9fce369.html http://www.cnblogs.com/softlo ...
- Spring Assert 断言
Assert(断言)的初步理解构思 Web 应用在接受表单提交的数据后都需要对其进行合法性检查,如果表单数据不合法,请求将被驳回.类似的,当我们在编写类的方法时,也常常需要对方法入参进行合 法性检查, ...
- Mock方法介绍
1 现有的单元测试框架单元测试是保证程序正确性的一种有效的测试手段,对于不同的开发语言,通常都能找到相应的单元框架. 借助于这些单测框架的帮助,能够使得我们编写单元测试用例的过程变得便捷而优雅.框架帮 ...
- Spring Assert(方法入参检测工具类-断言)
Web 应用在接受表单提交的数据后都需要对其进行合法性检查,如果表单数据不合法,请求将被驳回.类似的,当我们在编写类的方法时,也常常需要对方法入参进行合 法性检查,如果入参不符合要求,方法将通过抛出异 ...
- java 中的断言assert的使用
一.assertion的意义和用法 J2SE 1.4在语言上提供了一个新特性,就是assertion功能,它是该版本在Java语言方面最大的革新. 从理论上来说,通过 assertion方式可以证明程 ...
- Spring Assert主张 (参议院检测工具的方法-主张)
Web 收到申请表格提交的数据后都需要对其进行合法性检查,假设表单数据是不合法的,该请求将被拒绝.分类似的,当我们写的类方法,该方法还经常需要组合成参 法国检查.假设参议院不符合要求,方法通过抛出异常 ...
随机推荐
- 近期编程问题——epoll failed:bad file descriptor
出现问题:epoll_wait:Bad file descriptor 原因:IO时间的socket描述符在epoll_ctl处理前就关闭了. 解决方法:不要在epoll_ctl之前关闭socket描 ...
- Unreal Engine Plugin management
Be aware to remove any dependencies to any modules related to Editor, or else it will end up with fa ...
- git clone错误
git clone错误 Initialized empty Git repository in ***/.git/ error: The requested URL returned error: 4 ...
- 第九章 硬件抽象层:HAL
这一章介绍HAL,全称为Hardware Abstract Layer,即硬件抽象层,它是建立在Linux驱动之上的一套程序库,程序库并不属于Linux内核,而是属于Linux内核层之上的应用层.为A ...
- Hadoop原理介绍
Hadoop核心之HDFS 架构设计 老嗨 2015-09-18 16:55:00 浏览225 评论0 摘要: 概述:HDFS即Hadoop Distributed File System分布式文 ...
- Material Design使用记录
出现过的问题记录: 1.Crash on Android 6.0 in RippleView.draw() 解决方法: This has very simple solution. Just down ...
- Spring学习笔记(3)——Bean的注入方式
依赖注入 依赖注入支持属性注入.构造函数注入.工厂注入. 属性注入: 属性注入即通过setXxx()方法注入Bean的属性值或依赖对象 属性注入要求Bean提供一个默认的构造函数(无参构造函数),并为 ...
- C#利用摄像头拍照功能实现
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- AC中保存数据与查询数据
//保存数据 hui.ajax(function (ret, err) { }, url, {values: {t:"test",m:"Search",c:&q ...
- C#获得网卡信息 NetworkInterface IPInterfaceProperties
System.Net.NetworkInformation下的 1:NetworkInterface类,提供网络适配器的配置和统计信息. 可以通过它检测本机配置了多少网卡,哪些网络连接可用,获得网卡的 ...