Robot Framework - 2 - 创建测试库
04- 创建测试库--基础概念
***** 支持的编程语言
- Robot Framework 自身是用 Python 编写的,能使用 Python 扩展测试库。
- 如果在 Jython 运行Robot Framework 的话,那么测试库也可以用 Java 来实现。
- 也可以通过 Python C API 使用 C 语言来实现测试库。
***** 不同的测试库 API
05- 创建测试库Class或者Module
***** 测试库名称
- 如果实现一个库的类的名称跟它所在的模块同名,则 Robot Framework允许引入它的时候去掉模块名。
- 如果模块名和类名不同,使用测试库要同时使用模块名和类名。
- 如果测试库名称真的太长了,推荐通过 WITH NAME语法给测试库添加一个简短的别名。
***** 提供参数给测试库
***** 测试库的范围
- TEST CASE ---- 为每个测试用例创建一个新的实例。
- TEST SUITE ---- 为每个测试集创建一个新的实例。
- GLOBAL ---- 在整个测试执行过程中,只有 1 个实例被创建,被所有测试用例和测试集共享。
***** 声明测试库的版本
示例: LibraryExampleA.py
# -*- coding: utf-8 -*-
###创建测试库Class或者Module
class LibraryExampleA():
ROBOT_LIBRARY_SCOPE = 'TEST SUITE' #测试库的范围
__version__ = '0.1' #声明测试库的版本
def __init__(self):
self._counter = 0
def count(self):
self._counter += 1
print self._counter
def clear_counter(self):
self._counter = 0
## def keyword(self):
## pass
06- 创建测试库--创建静态关键字
***** 关键字名称
***** 关键字参数
***** 带有默认值的参数
***** 可变数量的参数
***** 参数的类型
示例: LibraryExampleB.py
# -*- coding: utf-8 -*- ###创建静态关键字 class LibraryExampleB(): #关键字名称
def hello(self,name):
print "Hello, %s!" % name
def do_nothing(self):
pass
#关键字参数
def no_arguments(self):
print "Keyword got no arguments."
def one_argument(self,arg):
print "Keyword got one argument '%s'." % arg
def multiple_arguments(self,a1, a2, a3):
print "Keyword got three arguments '%s', '%s' and '%s'." % (a1, a2, a3)
#带有默认值的参数
def one_default(self,arg='default'):
print "Argument has value %s" % arg
def multiple_defaults(self,arg1, arg2='default 1', arg3='default 2'):
print "Got arguments %s, %s and %s" % (arg1, arg2, arg3)
#可变数量的参数
def any_arguments(self,*args):
print "Got arguments:"
for arg in args:
print arg
def one_required(self,required, *others):
print "Required: %s\nOthers:" % required
for arg in others:
print arg
def also_defaults(self,req, def1="default 1", def2="default 2", *rest):
print req, def1, def2, rest
#参数的类型
def connect_to_host(self,address, port=25):
port = int(port)
print address, port
07- 创建测试库--与RobotFramework通信
***** 报告关键字的状态
***** 停止测试执行
***** 不管失败继续执行
***** 输出日志信息
***** 警告
***** 输出 HTML 格式的日志
***** 日志级别
***** 返回值
示例: LibraryExampleC.py
# -*- coding: utf-8 -*- ###与RobotFramework通信 import base64 class LibraryExampleC(): #返回值
def return_string(self):
return 'Hello, world!'
def return_object(self,info):
return base64.b64encode(info)
def return_two_values(self):
return 'first value', 'second value'
def return_multiple_values(self):
return ['a', 'list', 'of', 'strings'] #日志例子
def log_example(self):
print 'Hello from a library.'
print '*WARN* Warning from a library.'
print '*INFO* Hello again!'
print 'This will be part of the previous message.'
print '*INFO* This is a new message.'
print '*INFO* This is <b>normal text</b>.'
print '*HTML* This is <b>bold</b>.'
print '*HTML* <a href="http://robotframework.org">Robot Framework</a>'
Robot Framework - 2 - 创建测试库的更多相关文章
- Robot Framework(十四) 扩展RobotFramework框架——创建测试库
4.1创建测试库 Robot Framework的实际测试功能由测试库提供.有许多现有的库,其中一些甚至与核心框架捆绑在一起,但仍然经常需要创建新的库.这个任务并不复杂,因为正如本章所示,Robot ...
- 关于Django启动创建测试库的问题
最近项目迁移到别的机器上进行开发,启动Django的时候,有如下提示: Creating test database for alias 'default' 其实这个可能是在Django启动按钮的设置 ...
- Robot Framework - 4 - 创建和扩展测试库的示例
创建和扩展Library的示例 示例:Check status on Linux OS 创建与使用library的基本步骤: 1--- library实现的内容和实现的方式 ...
- Robot Framework - 5 - 创建测试数据
Creating test data User Guide - Creating test data:http://robotframework.org/robotframework/latest/R ...
- Robot Framework常用的操作库列表
标准库是Robot Framework可以直接导入使用的库,包含以下几类: Builtin:包含经常需要的关键字.自动导入无需import,因此总是可用的 Dialogs:提供了暂停测试执行和从用户的 ...
- Robot Framework - 建立本地测试环境
注意:本文内容是以“在Window7系统中安装本地RobotFrmamework自动化测试环境”为例. Robot Framework简介 HomePage:http://robotframework ...
- Robot Framework - 基础关键字 BuiltIn 库(二)
本篇教程,我们继续接着上篇内容进行讲解,我们本节教程讲解的是Robot Framework 机器人框架中的变量中使用判断.字符串的拼接.Evaluate的用法.调用Python文件.条件分支语句.以及 ...
- Robot Framework - 基础关键字 BuiltIn 库(一)
今天给大家分享的是Robot Framework 机器人框架中 BuiltIn 基础库的使用...BuiltIn 库里面提供了很多基础方法助力于我们在自动化测试领域中做的更好!——本系列教程是教会大家 ...
- 学习Robot Framework必须掌握的库—-BuiltIn库
作为一门表格语言,为了保持简单的结构,RF没有像别的高级语言那样提供类似if else while等内置关键字来实现各种逻辑功能,而是提供给了用户BuiltIn库.如果用户想在测试用例中实现比较复杂的 ...
随机推荐
- spring boot生成的war包运行时出现java.lang.NullPointerException: null
最近写了一个数据库同步的程序,见之前的博客,没有用到spring框架来集成,用的时纯Java代码.然后,项目经理要我把程序合到spring boot框架中,因为涉及到多数据源,时间又比较紧,同意我直接 ...
- Mysql必知必会 第三章 使用Mysql
第三章 使用Mysql SQL语句和大小写 请注意,SQL语句不区分大小写,因此SELECT与select是相同的.同样,写成Select也没有关系.许多SQL开发人员喜欢对所有SQL关键字使用大写, ...
- 设计模式学习心得<外观模式 Facade>
外观模式(Facade Pattern)隐藏系统的复杂性,并向客户端提供了一个客户端可以访问系统的接口.这种类型的设计模式属于结构型模式,它向现有的系统添加一个接口,来隐藏系统的复杂性. 这种模式涉及 ...
- Hishop数据库根据产品ProductID取产品规格
#region 产品规格 public static string GetSku(int ProductId) { DataTable skus =GetSkus(ProductId); // Res ...
- jqgrid content-type datatype
jQuery('#jq2').jqGrid( { url: 'http://localhost:8080/api/RskPriceFactorTest/senario/0/detail', editu ...
- C#事务提交
using (System.Transactions.TransactionScope transcope = new System.Transactions.TransactionScope()) ...
- Chrome自定义滚动条
/*定义滚动条高宽及背景 高宽分别对应横竖滚动条的尺寸*/ ::-webkit-scrollbar { width: 16px; height: 16px; background-color: #F5 ...
- mysql锁机制(Innodb引擎)
InnoDB实现了两种类型的行锁. 共享锁(S):允许一个事务去读一行,阻止其他事务获得相同的数据集的排他锁. 排他锁(X):允许获得排他锁的事务更新数据,但是组织其他事务获得相同数据集的共享锁和排他 ...
- godoc
Godoc-一个Go代码文档化工具 Python - Docstring Java - javadoc
- C++如何获取当前路径下所有文件的文件名
今天我遇到了这样一个任务:要求编写一个程序,统计和这个程序在同一目录下(及其子目录)所有文件的单词数.统计单词数十分倒不是太难,倒是找出同一目录下的所有文件,是我从来没有接触过的.仔细分析,这个问题其 ...