• 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,如图:

  • 相关阅读:
    du 命令计算隐藏文件夹或文件
    QEMU中VIRTIO实现
    virtio_blk
    网络虚拟化Virtio-net
    virtio desc
    vhost dpdk 共享内存
    gvisor 信号处理
    Java idea 执行单个测试方法
    Java idea 创建User.xml,需要新增一个mybatis-mapper.xml模板
    Java idea 创建log4j.properties
  • 原文地址:https://www.cnblogs.com/xiaoluosun/p/4552129.html
Copyright © 2020-2023  润新知