Robot Framework自动化测试(三)--- 封装系统关键字

之前对robotframework-ride了解的不多,后来知道了引入Selenium2Lirary库后可以做web UI自动化测试,但发现和python没啥关系,今天学习了封装系统关键字算是和python联系上了,跟封装包提供调用函数类似。 本文仅适用于Python2,Python3自定义库方式: https://www.cnblogs.com/v5captain/p/16994013.html
1.封装一个库并调试通过、放在C:\Python27\Lib\site-packages目录下(查看Python安装路径where Python)
2.ride中导入Library
3.查看导入的库
4.测试库是否正常工作
1.创建一个目录HelloWorld(这是库的名字,自己随便定义)
2.在目录中创建两个文件__init__.py,和helloworld.py,把helloworld.py调通,保证能够运行无语法错误。
helloworld.py文件内容,复制代码要小心,并一定调试通过再往下走。
# -*- coding:utf-8 -*-
'''
    created by captain9 2017-1-2
'''

__version__ = '0.1'


class Hello(object):
    def hi(self,name):
        u'''接收一个名字,并问候.例如
        | hi  | xiaoming        | 
        '''
        print 'Hello, ' + name + '!'

    def decode(self,name):
        return customerstr.decode('utf-8')

if __name__ == "__main__":
    name = u'xiaodong'
    run = Hello()
    run.hi(name)
View Code

__init__.py文件内容

# -*- coding:utf-8 -*-
#  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 helloworld import Hello

__version__ = '0.1'


class HelloWorld(Hello):
    """
    这是一个HelloWorld库,输入名字,输出问候。
 
    """
    ROBOT_LIBRARY_SCOPE = 'GLOBAL'
View Code

2.把HelloWorld目录放到C:\Python27\Lib\site-packages目录下

2.ride中导入Library,注意大小写敏感,这里是文件夹的名称:
若为黑色则为导入成功,红色为失败,helloword.py文件能否正常运行。
3.查看导入的库 F5或者Tools-Search Keywords
4.测试库是否正常工作
虽然关键字大小写不敏感,但我认为还是按照大小写敏感来写比较规范。
测试结果
好了,以后可以开发更多有用的关键字了。
Robot Framework is a Python-based, extensible keyword-driven test automation framework for end-to-end acceptance testing and acceptance-test-driven development (ATDD). It can be used for testing distributed, heterogeneous applications, where verification requires touching several technologies and interfaces.
参考:
Robot Framework自动化测试(五)--- 开发系统关键字 - 虫师 - 博客园
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Robot Framework是一个基于Python的可扩展关键字驱动的自动化框架,用于验收测试,验收测试驱动开发(ATDD),行为驱动开发(BDD)和机器人流程自动化(RPA)。它可以在分布式异构环境中使用,其中自动化需要使用不同的技术和接口。由Robot Framework基金会支持,许多行业领先的公司在其软件开发中使用该工具。Robot Framework是开放和可扩展的,可以与几乎任何其他工具集成,以创建强大而灵活的自动化解决方案,并且可以免费使用,无需许可费用。Robot Framework具有高度模块化的体系结构,测试数据采用简单、易于编辑的表格格式。当Robot Framework启动时,它会处理数据,执行测试用例并生成日志和报告。核心框架对被测目标一无所知,与它的交互由库处理。库可以直接使用应用程序接口,也可以使用较低级别的测试工具作为驱动程序。所以,Robot Framework是一种强大的自动化测试工具,适用于各种测试场景,并且具有灵活的扩展性和集成能力。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [Robot Framework自动化测试框架超强教程(一)](https://blog.csdn.net/weixin_57794111/article/details/126320063)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值