zoukankan      html  css  js  c++  java
  • robot framework用python扩展编写自定义library

    我的utils.py文件

    #!/usr/bin/env python
    #-*- coding:utf8 -*-
    
    __version__ = '0.1'
    
    import sys
    reload(sys)
    sys.setdefaultencoding('utf8')
    
    from robot.api import logger
    import urllib2, json, re, os, random
    import xml.dom.minidom
    
    class Utils(): 
        def read_xml(self, arg):
            u'''测试数据存储文件,接收节点name,返回text。
    
                例:
               | Read Xml        | email       |       
            '''        
            path = os.getcwd()+"\data\test_data.xml"
            dom = xml.dom.minidom.parse(path)
            root = dom.documentElement       
            texts = root.getElementsByTagName(arg)
            options = root.getElementsByTagName('switch')
            if int(options[0].firstChild.data) == 1:       
                text = texts[0]
                return text.firstChild.data
            elif (int(options[0].firstChild.data) == 2):
                text = texts[1]
                return text.firstChild.data
    
    if __name__ == '__main__':
    #    get = GetReset()
        pass
    

    我的__init__.py文件

    #  Copyright (c) 2010 Franz Allan Valencia See
    #
    #  Licensed under the Apache License, Version 2.0 (the "License");
    #  you may not use this file except in compliance with the License.
    #  You may obtain a copy of the License at
    #
    #      http://www.apache.org/licenses/LICENSE-2.0
    #
    #  Unless required by applicable law or agreed to in writing, software
    #  distributed under the License is distributed on an "AS IS" BASIS,
    #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    #  See the License for the specific language governing permissions and
    #  limitations under the License.
    
    from utils import Utils    
    from reply import Reply
    
    
    __version__ = '0.1'
    
    class UtilsLibrary(Utils, Reply):
        
        ROBOT_LIBRARY_SCOPE = 'GLOBAL'
    

    在Python27Libsite-packages目录下新建UtilsLibrary文件夹,两个文件丢到里面。

    然后进入cmd先编译这两个文件,生成.pyc

    python -m __init__.py utils.py
    

      

    启动robot framework ride,添加library,如图:

    黑色说明添加成功。

    按F5,如图:

  • 相关阅读:
    Consul常用命令
    ECharts 避免变窄
    TP3.2 日期默认格式
    新订单提示效果
    php 按照字典序排序 微信卡券签名算法用到
    td宽度自适应 窄的地方自动收缩
    git 删除本地分支,删除远程分支
    分页Model
    chrome表单自动填充如何取消
    tp3.2 如何比较两个字段
  • 原文地址:https://www.cnblogs.com/xiaoluosun/p/4552129.html
Copyright © 2011-2022 走看看