RobotFramework自动化测试框架系统关键字之断言
一、基础
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}组成。
RobotFramework自动化测试框架系统关键字之断言的更多相关文章
- RobotFramework自动化测试框架-移动手机自动化测试AppiumLibrary介绍
在使用AppiumLibrary库时,需要预先安装好Appium自动化工具,Appium官网地址为:http://appium.io/ Appium的GitHub地址为:https://github. ...
- RobotFramework自动化测试框架-DatabaseLibrary库的使用(对数据库的操作)
在自动化过程中,我们经常需要连接不同的数据库,并且对数据库进行很多不同的操作,RobotFramework中,提供了DatabaseLibrary这个库来操作数据库,我们可以按照官网中的说明来安装Da ...
- RobotFramework自动化测试框架-使用Python编写自定义的RobotFramework Lib
使用Python构建Lib工程 可以用来开发Python Lib的IDE工具有很多,常见的有Pycharm,Eclipse with PyDev插件等,而且在RobotFramework官网中也已经提 ...
- RobotFramework自动化测试框架(1)- RobotFramework简介
对于RobotFramework自动化测试框架,我这里会从三个单元进行阐述,希望能对你有帮助. RobotFramework简介 RobotFramework是什么? Robotframework 是 ...
- RobotFramework自动化测试框架-Selenium Web自动化(二)关于在RobotFramework中如何使用Selenium很全的总结(上)
好久没有继续分享关于自动化测试相关的东西了,自动化在现今的测试领域已经越来越重要了,大部分公司在测试岗位招聘中都需要会相关的自动化测试知识.而 RobotFramework自动化测试框架 是自动化测试 ...
- RobotFramework自动化测试框架-Selenium Web自动化(三)关于在RobotFramework中如何使用Selenium很全的总结(下)
本文紧接着RobotFramework自动化测试框架-Selenium Web自动化(二)关于在RobotFramework中如何使用Selenium很全的总结(上)继续分享RobotFramewor ...
- RobotFramework自动化测试框架-MongoDBLibrary库的使用
笔者接着 RobotFramework自动化测试框架-DatabaseLibrary库的使用(对数据库的操作) 继续分享robotframework 对数据库中的MongoDB的详细操作. Mongo ...
- 老李分享:qtp自动化测试框架赏析-关键字自动化测试框架
老李分享:qtp自动化测试框架赏析-关键字自动化测试框架 QTP从2005年继winrunner,robot逐渐退出历史舞台之后,占领主流自动化测试工具市场已经10年之久.当初为了提高在自动化测试 ...
- RobotFramework自动化测试框架-Selenium Web自动化(-)-Open Browser和Close Browser
Selenium出来已经有很多年了,从最初的Selenium1到后来的Selenium2,也变得越来越成熟,而且也已经被很多公司广泛使用.Selenium发展的过程中,分了很多模块,这里我们主要介绍W ...
随机推荐
- Java实现十进制数转十六进制数
Now~Let's begin our second question~ 如何利用Java语言将十进制数字转换成十六进制数字呢? 我第一次编码出来的效果是酱紫的~ /** * */ package c ...
- 链接oracle数据库 生成表对应的javabean
package com.databi.utils; import java.io.File; import java.io.FileOutputStream; import java.io.IOExc ...
- 51Nod 1256 求乘法逆元--扩展欧几里德
#include<stdio.h> int exgcd(int a,int b,int &x,int &y) { ) { x=; y=; return a; } int r ...
- bzoj3127/3697 [Usaco2013 Open]Yin and Yang
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=3127 http://www.lydsy.com/JudgeOnline/problem.ph ...
- bzoj 5028: 小Z的加油店——带修改的区间gcd
Description 小Z经营一家加油店.小Z加油的方式非常奇怪.他有一排瓶子,每个瓶子有一个容量vi.每次别人来加油,他会让 别人选连续一段的瓶子.他可以用这些瓶子装汽油,但他只有三种操作: 1. ...
- SHOI 2007 仙人掌图(BZOJ 1023)
1023: [SHOI2008]cactus仙人掌图 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 2564 Solved: 1062 Descrip ...
- 关于k Line Chart (k线图)
K Line Chart python实现k线图的代码,之前找过matplotlib中文文档但是画k线图的finance方法已经弃用了.所以自己在网上搜寻一下加上改编,很好的实现出k线图, 代码如下: ...
- poj 2406 Power Strings(kmp循环节)
题目链接:http://poj.org/problem?id=2406 题目大意:如果n%(n-next[n])==0,则存在重复连续子串,长度为n-next[n]. 例如: a b ...
- python3,循环,方法练习2
1:编写for循环,利用索引遍历出每一个字符 msg = 'hello egon 666' msg = 'hello egon 666' i = 0 for i in range(0, len(msg ...
- Vmware中安装和卸载Linux 16.04.3
1.先去这个链接 https://www.ubuntu.com/download ,下载ubuntu镜像,也就是下图的download选项 2.下载后到虚拟机里创建一个新的虚拟机,然后按照博客 htt ...