1、Python版本
robotframework从3.0版本开始支持python3.
2、robotframework安装
pip install robotframework
3、安装检验
4、quick start的操作说明
1.下载并解压文件:https://github.com/robotframework/QuickStartGuide.git
2.根据操作指南进行操作:
suit/login.py支持4个动作: { create | login | change-password | help }
create:新建用户 python sut/login.py create username password
password规则:7-12位大小写+字母组合
login:登录python sut/login.py login username password
change-password:修改密码python sut/login.py change-password username P4ssw0rd newpassword
密码规则和新建时的密码规则一样
关于login的功能,可以查看login.py源码
E:\QuickStartGuide-master>python sut/login.py login create fred P4ssw0rd
Usage: login.py { create | login | change-password | help }E:\QuickStartGuide-master>python sut/login.py login nobody P4ssw0rd
Access DeniedE:\QuickStartGuide-master>python sut/login.py create fred P4ssw0rd
SUCCESSE:\QuickStartGuide-master>python sut/login.py login fred P4ssw0rd
Logged InE:\QuickStartGuide-master>python sut/login.py login fred shortAccess DeniedE:\QuickStartGuide-master>python sut/login.py create fred shortCreating user failed: Password must be 7-12 characters longE:\QuickStartGuide-master>python sut/login.py create fred invalid
Creating user failed: Password must be a combination of lowercase and uppercase
letters and numbersE:\QuickStartGuide-master>python sut/login.py change-password fred wrong NeeP4ss
Changing password failed: Access DeniedE:\QuickStartGuide-master>python sut/login.py change-password fred P4ssw0rd shor
t
Changing password failed: Password must be 7-12 characters longE:\QuickStartGuide-master>python sut/login.py change-password fred P4ssw0rd NewP4ss
SUCCESS
5、执行QuickStart.rst中的用例
由于login.py功能的测试用例写在QuickStart.rst中,QuickStart.rst使用了源文档标记语言,所以需要先安装pip install docutils
执行测试用例的命令:robot QuickStart.rst
查看结果:从图中看出共执行了5个用例,可以看到用例执行状态和报告、日志的默认输入位置及格式
6、用例的组成部分说明
*** Test Cases ***
*** Settings ***
*** Keywords ***
*** Variables ***
*** Variables ***
${USERNAME} janedoe
${PASSWORD} J4n3D0e
${NEW PASSWORD} e0D3n4J
${DATABASE FILE} ${TEMPDIR}${/}robotframework-quickstart-db.txt
${PWD INVALID LENGTH} Password must be 7-12 characters long
${PWD INVALID CONTENT} Password must be a combination of lowercase and uppercase letters and numbers
关键字
[Arguments] 参数1 参数2
命令 参数1 参数2
预期结果 状态
*** Keywords ***
Clear login databaseRemove file ${DATABASE FILE}Create valid user[Arguments] ${username} ${password}Create user ${username} ${password}Status should be SUCCESSCreating user with invalid password should fail[Arguments] ${password} ${error}Create user example ${password}Status should be Creating user failed: ${error}Login[Arguments] ${username} ${password}Attempt to login with credentials ${username} ${password}Status should be Logged In# Keywords below used by higher level tests. Notice how given/when/then/and# prefixes can be dropped. And this is a comment.A user has a valid accountCreate valid user ${USERNAME} ${PASSWORD}She changes her passwordChange password ${USERNAME} ${PASSWORD} ${NEW PASSWORD}Status should be SUCCESSShe can log in with the new passwordLogin ${USERNAME} ${NEW PASSWORD}She cannot use the old password anymoreAttempt to login with credentials ${USERNAME} ${PASSWORD}Status should be Access Denied
*** Settings ***
Library OperatingSystem
Library lib/LoginLibrary.pySuite Setup Clear Login Database
Test Teardown Clear Login DatabaseForce Tags quickstartDefault Tags example smoke
*** Test Cases ***
User can create an account and log inCreate Valid User fred P4ssw0rdAttempt to Login with Credentials fred P4ssw0rdStatus Should Be Logged InUser cannot log in with bad passwordCreate Valid User betty P4ssw0rdAttempt to Login with Credentials betty wrongStatus Should Be Access DeniedUser can change passwordGiven a user has a valid accountWhen she changes her passwordThen she can log in with the new passwordAnd she cannot use the old password anymoreInvalid password[Template] Creating user with invalid password should failabCD5 ${PWD INVALID LENGTH}abCD567890123 ${PWD INVALID LENGTH}123DEFG ${PWD INVALID CONTENT}abcd56789 ${PWD INVALID CONTENT}AbCdEfGh ${PWD INVALID CONTENT}abCD56+ ${PWD INVALID CONTENT}
7、总结
1、RobotFramework是典型的关键字驱动框架,从第6部分的用例描述中可以看出;
2、初期学习的时候,先学会阅读RobotFramework框架编写的测试用例,去了解框架的模块构成、每个模块的作用、每个模块中特定的关键字;
3、阅读官方文档中的示例及描述,快速掌握用例的组织及应用;
4、RobotFramework有对应的api文档,需要去阅读api文档,了解api的应用。
写在最后
在写这篇文章之前,是没有了解过RobotFramework的;
本次从安装-查看文档-查看QuickStart并进行实践阅读-输出这篇文章,共耗时4小时;
掌握程度:知道了框架的构成部分
需要进一步了解的内容:每个部分中可用的内置关键字及作用,如Test Cases中的 [Template] 、*** Settings ***中的Default Tags及命令行。
AutoLink开源自动化测试集成解决方案