1. 安装selenium2library
命令行安装: pip install SeleniumLibrary
离线安装: https://github.com/robotframework/Selenium2Library
2. Web UI 自动化测试用例
账号登录CSDN网站并点击首页最新文章链接。获取页面的title赋值给${title}并做断言,判断${title}是否等于‘最新文章-CSDN。
3. 添加用户关键字
选中TestSuite并新建User Keyword->输入Keyword name->拷贝之前写的登录的代码并创建两个arguments,按${name}格式命名并用|分隔。代码中输入参数的地方用新建的arguments代替。
新建case,调用新建的关键字并输入参数。执行用例测试用户关键字是否可用。
4. 添加系统关键字
在python\lib\Lib\site-packages下新建目录 MyLibrary。MyLibrary目录下新建python文件 mylib.py和__init__.py。
mylib.py的源码:
#-*- coding:utf-8 -*-
__version__ = '0.1'
class PersonalMethods(object):
def add_two_number(self,n,m):
'''
number: n,m return n+m
'''
return n + m
def mutiple_two_number(self,n,m):
'''
number: n,m return n*m
'''
return n * m
__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 mylib import PersonalMethods
__version__ = '0.1'
class MyLibrary(PersonalMethods):
ROBOT_LIBRARY_SCOPE = 'GLOBAL'
注意:
新建的目录名必须和__init__.py里的class name相同,否则在robotframework里面引入不成功。本例中就是 'MyLibrary'
在 robot里面导入library,显示黑色即表示创建系统关键字成功。
测试系统关键字: