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. 执行结果

  • 相关阅读:
    Codeforces Round #443 Div. 1
    linux中ps命令
    占cpu 100%的脚本
    检查Linux系统cpu--内存---磁盘的脚本
    jQuery对象的属性操作
    关于js的一些收集
    Linux命令集合
    使用python操作excel表格
    Linux7.3系统 升级python到3.6使用ping主机脚本
    一个别人的线程池的编写
  • 原文地址:https://www.cnblogs.com/moonpool/p/6143589.html
Copyright © 2011-2022 走看看