zoukankan      html  css  js  c++  java
  • robotframework 自定义library

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

    1.在D:I_pythonPython27Libsite-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. 执行结果

  • 相关阅读:
    About Me
    洛谷 P2633 Count on a tree
    【题解】牛客编程巅峰赛S1赛季第1场
    洛谷 P4132 [BJOI2012]算不出的等式
    洛谷 P5970 [POI2016]Nim z utrudnieniem
    DP没入门就入土
    洛谷 P4042 [AHOI2014/JSOI2014]骑士游戏
    洛谷 P3592 [POI2015]MYJ
    51Nod 1683 最短路
    51Nod 1327 棋盘游戏
  • 原文地址:https://www.cnblogs.com/moonpool/p/6143589.html
Copyright © 2011-2022 走看看