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)
__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'
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自动化测试(五)--- 开发系统关键字 - 虫师 - 博客园
分类:
Robot Framework
标签:
robotframework
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)