码迷,mamicode.com
首页 > 其他好文 > 详细

robotframework 自定义library

时间:2016-12-08 09:42:24      阅读:445      评论:0      收藏:0      [点我收藏+]

标签:img   pack   src   reg   getc   cli   sel   代码   ict   

作用说明:本例中自定义的library作用就是从Redis中获取短信验证码。

 

1.在D:\I_python\Python27\Lib\site-packages(这个路径一定要在系统path路径中)下面创建一个CustomRedisClient文件夹

2.在该文件夹下创建两个文件,分别是__init__.py以及getcodefromredis.py(其中需要先安装redis和regex)

代码如下

getcodefromredis.py:

 1 #-*- coding:utf-8 -*-
 2 ‘‘‘
 3     created by hch 2016-12-7
 4 ‘‘‘
 5 import redis
 6 import regex
 7 
 8 __version__ = 0.1
 9 
10 class Getcodefromredis(object):
11 
12     def getsmscode(self,host,port,dbindex,keyvalue):
13         ‘‘‘获取redis中的code。例
14             | getsmscode          | host               | port   | dbindex   | phonenum   |
15         ‘‘‘
16         
17         print host
18         print port
19         print dbindex
20         print keyvalue
21         r=redis.StrictRedis(host,port,dbindex)
22         
23         value=r.get(keyvalue)
24         valuecontent = regex.findall(r"\d{6}",value)[0]
25         print valuecontent

__init__.py:

 1 #-*- coding:utf-8 -*-
 2 ‘‘‘
 3     created by hch 2016-12-8
 4 ‘‘‘
 5 
 6 
 7 
 8 from getcodefromredis import Getcodefromredis
 9 
10 
11 __version__ = 0.1
12 
13 class CustomRedisClient(Getcodefromredis):   
14     ROBOT_LIBRARY_SCOPE = GLOBAL

 3. 重新启动ride,并添加library

技术分享

4.通过F5查看library以及key说明

技术分享

技术分享

5.编写用例

技术分享

6. 执行结果

技术分享

 

robotframework 自定义library

标签:img   pack   src   reg   getc   cli   sel   代码   ict   

原文地址:http://www.cnblogs.com/moonpool/p/6143589.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!