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

  • 相关阅读:
    DS博客作业01--日期抽象数据类型设计与实现
    C语言-第6次作业
    C语言-第5次作业
    C语言--第4次作业
    DS博客作业08--课程总结
    DS博客作业07--查找
    DS博客作业06--图
    DS博客作业05--树
    DS博客作业03--栈和队列
    DS作业01--日期抽象数据类型设计与实现
  • 原文地址:https://www.cnblogs.com/moonpool/p/6143589.html
Copyright © 2011-2022 走看看