Robot Framework - 4 - 创建和扩展测试库的示例
创建和扩展Library的示例
示例:Check status on Linux OS
创建与使用library的基本步骤:
1--- library实现的内容和方式
2--- library的编写
# -*- coding: utf-8 -*- import re
from SSHLibrary import SSHLibrary class LibraryCheckLinuxOS:
"""This is an example for creating a library .""" ROBOT_LIBRARY_SCOPE = 'TEST SUITE' #测试库的范围
__version__ = '0.1' #声明测试库的版本 def creat_ssh_connection(self,ipaddress,port,user,login):
'''
根据输入的IP、端口、用户名及密码,建立相应的SSH连接. Example : | creat ssh connection | 10.68.75.111 | 22 | mcadmin | testsc |
'''
self.mc = SSHLibrary()
self.mc.open_connection(ipaddress,port)
self.mc.login(user,login) def check_disk(self,quota=80):
'''
检查磁盘的空间是否满足特定的要求。默认已使用空间要求小于80%. Example : | check disk | 80 |
'''
self.mc.start_command("df -h")
diskstatus = self.mc.read_command_output()
match_one = re.findall(r"\d+\%",diskstatus,re.M)
match_two = ' '.join(match_one)
matchobj = re.findall(r"\d+",match_two)
if int(max(matchobj)) < int(quota):
print "The disk status is OK !"
else:
raise UserWarning("There's something wrong with your disk.") def check_rpm(self,rpmname):
'''
检查特定的安装包是否安装.
Example:
| check rpm | name |
'''
self.mc.start_command("rpm -qa|grep %s" % rpmname)
checkstatus = self.mc.read_command_output()
if checkstatus == rpmname:
print "The %s is installed !" % rpmname
else:
raise UserWarning("There's something wrong with your rpm.") def check_service(self,servicename):
'''
检查特定服务的状态.
Example:
| check service | name |
'''
self.mc.start_command("service %s status" % servicename)
checkstatus = self.mc.read_command_output()
match = re.findall(r"running",checkstatus,re.M)
if len(match) > 0:
print "The service status is OK !"
else:
raise UserWarning("The service status is not running.") def check_process(self,processname):
'''
检查特定进程的状态.
Example:
| check process | name |
'''
self.mc.start_command("ps -ef | grep %s" % processname)
checkstatus = self.mc.read_command_output()
match = re.findall(r"%s" % processname,checkstatus,re.M)
if len(match) >= 2 :
print "The process status is OK !"
else:
raise UserWarning("The %s is not running." % processname) def check_memory(self,value=80):
'''
检查内存的使用状态.
Example:
| check memory | value |
'''
self.mc.start_command("free -m")
checkstatus = self.mc.read_command_output()
match = re.findall(r"\d+",checkstatus,re.M)
quota =(float(match[1])/float(match[0]))*100
if int(quota) <= int(value):
print "The memory is OK !"
else:
raise UserWarning("Please check the status of memory" ) ##from SSHLibrary import SSHLibrary
##
## def check_memory(self,ipaddress,user,login):
## mc = SSHLibrary()
## mc.open_connection(ipaddress)
## mc.login(user,login)
## mc.start_command('free -m')
## return mc.read_command_output() ##class LibraryCheckLinuxOS:
##
## ROBOT_LIBRARY_SCOPE = 'TEST SUITE' #测试库的范围
## __version__ = '0.1' #声明测试库的版本
##
## def creat_ssh_connection(self,ipaddress,port,user,login):
## self.mc = SSHLibrary()
## self.mc.open_connection(ipaddress,port)
## self.mc.login(user,login)
##
## def check_loadavg(self):
## self.mc.start_command('cat /proc/loadavg')
## print self.mc.read_command_output()
##
## def check_memory(self):
## self.mc.start_command('free -m')
## print self.mc.read_command_output()
##
## def check_disk(self):
## self.mc.start_command('df -h')
## print self.mc.read_command_output() ## 检查Linux OS的磁盘空间
## $ df -h
## Filesystem Size Used Avail Use% Mounted on
## /dev/mapper/VG00-sysimg
## 19G 2.7G 16G 15% /
## /dev/sda1 99M 19M 75M 21% /boot
## tmpfs 2.0G 20K 2.0G 1% /dev/shm
## /dev/mapper/vg01-mmsc_var
## 35G 435M 33G 2% /var/mnt/mmsc_var
## /dev/mapper/vg03-ldap
## 985M 114M 821M 13% /var/mnt/local/ldap
## /dev/mapper/vg02-clusterlvol.001
## 2.0G 37M 1.8G 2% /var/mnt/cluster_lvol ## 检查Linux OS的内存状态
## $ free -m
## total used free shared buffers cached
## Mem: 3949 1911 2037 0 336 1245
## -/+ buffers/cache: 329 3619
## Swap: 0 0 0 ## 检查Linux OS是否安装了特定的程序包
## $ rpm -qa |grep SS_MMSC-5.0.6
## SS_MMSC-5.0.6-30 ## 检查Linux OS特定进程的状态
## # ps -ef |grep xkrmanmx
## mcadmin 19215 19200 1 11:16 ? 00:00:05 xkrmanmx
## root 21723 17643 0 11:24 pts/0 00:00:00 grep xkrmanmx
实现如下功能:
- 检查Linux OS是否安装了特定的程序包
- 检查Linux OS特定的服务启动状态
- 检查Linux OS特定进程的状态
- 检查Linux OS内存使用状态
3--- library的编译
4 --- Test Case的编写与调试
5 --- 扩展已存在的测试库的方式
Robot Framework - 4 - 创建和扩展测试库的示例的更多相关文章
- Robot Framework(5)- 使用测试库
如果你还想从头学起Robot Framework,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1770899.html 前言 在RF 测 ...
- Robot Framework(五)使用测试库
使用测试库 测试库包含那些最低级别的关键字,通常称为 库关键字,实际上与被测系统交互.所有测试用例总是使用某些库中的关键字,通常是通过更高级别的用户关键字.本节介绍如何使用测试库以及如何使用它们提供的 ...
- Robot Framework(8)- Collections 测试库常用的关键字列表
如果你还想从头学起Robot Framework,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1770899.html 前言 所有关键字 ...
- Robot Framework(6)- BuiltIn 测试库常用的关键字列表
如果你还想从头学起Robot Framework,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1770899.html 前言 所有关键字 ...
- Robot Framework(7)- DateTime 测试库常用的关键字列表
如果你还想从头学起Robot Framework,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1770899.html 前言 所有关键字 ...
- robot framework笔记(三):扩展SeleniumLibrary库 (自定义关键字)
(一)自定义和浏览器相关的关键字 以下代码GitHub 版本库地址: https://github.com/blairwind/blog_rf SeleniumLibrary的扩展文档中提供了3种增加 ...
- Robot Framework - 2 - 创建测试库
04- 创建测试库--基础概念 Robot Framework 实际的测试能力是由测试库提供的. ***** 支持的编程语言 Robot Framework 自身是用 Python 编写的,能使用 P ...
- RobotFramework自动化测试框架(3)- RobotFramework扩展测试库、资源文件、变量文件
扩展测试库 扩展测试库可使用python或java语言编写.后直接导入需要使用的测试用例文件即可. 具体的实现和操作,后续补充.请参考官网. 资源文件 在资源文件中定义用户关键字,它提供了共享机制,即 ...
- Robot Framework - 5 - 创建测试数据
Creating test data User Guide - Creating test data:http://robotframework.org/robotframework/latest/R ...
随机推荐
- C51汇编典型代码&一些org-mode技巧
C51汇编典型代码&一些org-mode技巧 文档存放 具体内容可见存放的数据. 下面主要介绍关键代码. ASM 部分 1;; LCD数据发送========================= ...
- go的语法
概述 有接触go语言,工作中用的比较少,偶尔做个小项目,最近看到的一个项目也从go迁移到java. 但是对go还是恋恋不忘,它语法比较简洁,库也比较多,编译速度快,等等优点,让我忘不了. 对go的语法 ...
- PHP 利用PHPExcel 文件导入(也可保存到本地或者服务器)、导出
首先需要去官网http://www.php.cn/xiazai/leiku/1491,下载后只需要Classes目录下的文件即可. 1.PHPExcel导出方法实现过程 1 2 3 4 5 6 7 8 ...
- Android自动化之Monkey环境搭建(一)
从事测试行业两年了,一直很喜欢研究新技术,但是最近有点慵懒.正好公司新出了产品,督促我学习monkey用来测其稳定性. 网上搜索了很久,内容总是很零散,通常需要找几篇文章才能搭好环境.特写此文,一篇文 ...
- HTTP之响应消息Response
一般情况下,服务器接收并处理客户端发过来的请求后会返回一个HTTP的响应消息. HTTP响应也由四个部分组成,分别是:状态行.消息报头.空行和响应正文. 例子 HTTP/1.1 200 OK Date ...
- C#事务提交
using (System.Transactions.TransactionScope transcope = new System.Transactions.TransactionScope()) ...
- sha1withRSA算法
RAS_USE_PRIVATE_ENCRYPT(3021300906052b0e03021a05000414 + SHA1(DATA))
- Python3.7 Scrapy crawl 运行出错解决方法
安装的是Python3.7,装上依赖包和scrapy后运行爬虫命令出错 File "D:\Python37\lib\site-packages\scrapy\extensions\telne ...
- vue框架中的日期组件转换为yyy-mm-dd格式
最近在用vue框架写一个app,这个是用到的日期格式转换,把下面的标准格式转换为字符串连接格式
- 2019.03.09 bzoj4491: 我也不知道题目名字是什么(线段树)
传送门 题意:给定一个序列A[i],每次询问l,r,求[l,r]内最长子串,使得该子串为不上升子串或不下降子串. 思路: 注意要求的是子串而不是子序列!!! 然后直接用线段树维护最大子段和的方式合并一 ...