robotframework 自定義library


作用說明:本例中自定義的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. 執行結果

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM