robot framework用python扩展编写自定义library
2015-06-04 16:09 xiaoluosun 阅读(1419) 评论(0) 收藏 举报我的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。\n
例:
| 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'
在Python27\Lib\site-packages目录下新建UtilsLibrary文件夹,两个文件丢到里面。
然后进入cmd先编译这两个文件,生成.pyc
python -m __init__.py utils.py
启动robot framework ride,添加library,如图:

黑色说明添加成功。
按F5,如图:

浙公网安备 33010602011771号