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库.如果用户想在测试用例中实现比较复杂的 ...
随机推荐
- android 自定义title
package com.xiangyu.su; import android.app.Activity; import android.os.Bundle; import android.view.V ...
- docker构建镜像
Docker 提供了两种构建镜像的方法: docker commit 命令Dockerfile 构建文件 示例: Dockerfile FROM golang:1.7.5 #基础镜像 RUN apt- ...
- 茶杯头开枪ahk代码
;说明这个工具是为了茶杯头写的,F1表示换枪攻击,F3表示不换枪攻击,F2表示停止攻击. $F1::loop{ GetKeyState, state, F2, Pif state = D{break ...
- PHP不借助第三个变量交换值
总结一下: //方法一: $a = "abc"; $b= "def"; $a = $a^$b; $b = $b^$a; $a = $a^$b; //方法二: l ...
- ajax 与jsp servlet
jQuery的Ajax实现异步传输List.Map_GOOD 分类: JAVA WEB前端2013-08-29 18:35 6296人阅读 评论(0) 收藏 举报 javajquerylistjson ...
- HttpServerUtility常用方法
//HttpServerUtility是一个工具类,为了在后台处理请求方便获取到一些常用的类型,Asp.net将很多常用的东西封装到这里. // 获取服务器的计算机名称. public string ...
- 虹软人脸检测和识别C# - API
using System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Drawing2D ...
- 关于在spring boot里使用Thymeleaf模板的application.properties配置
spring.thymeleaf.cache=false spring.thymeleaf.encoding=utf- spring.thymeleaf.mode=HTML5 spring.thyme ...
- MyBatis generator配置 overwrite 文件覆盖失效
工具:IDEA.jdk1.8.mysql 底部有解决方法! pom.xml配置 <plugins> <!--Mybatis自动代码插入--> <plugin> &l ...
- 数据结构与STL容器
1.静态数组 静态数组就是大小固定不能扩展的数组,如C中普通数组.C++11中array. 2.动态数组 动态数组的空间大小在需要的时候可以进行再分配,其代表为vector.由于数组的特点,在位置0插 ...