美文网首页
01_Robot Framework的安装

01_Robot Framework的安装

作者: 今天我叫陈开心 | 来源:发表于2018-08-07 12:40 被阅读0次

    1、Python版本

    • python版本:3.6

    robotframework从3.0版本开始支持python3.

    2、robotframework安装

    pip install robotframework

    • robotframwork版本:3.0.4

    • 官方文档地址:http://robotframework.org/,阅读文档了解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 Denied
    
    E:\QuickStartGuide-master>python sut/login.py create fred P4ssw0rd
    SUCCESS
    
    E:\QuickStartGuide-master>python sut/login.py login fred P4ssw0rd
    Logged In
    
    E:\QuickStartGuide-master>python sut/login.py login fred short
    Access Denied
    
    E:\QuickStartGuide-master>python sut/login.py create fred short
    Creating user failed: Password must be 7-12 characters long
    
    E:\QuickStartGuide-master>python sut/login.py create fred invalid
    Creating user failed: Password must be a combination of lowercase and uppercase
    letters and numbers
    
    E:\QuickStartGuide-master>python sut/login.py change-password fred wrong NeeP4ss
    Changing password failed: Access Denied
    
    E:\QuickStartGuide-master>python sut/login.py change-password fred P4ssw0rd shor
    t
    Changing password failed: Password must be 7-12 characters long
    
    E:\QuickStartGuide-master>python sut/login.py change-password fred P4ssw0rd NewP
    4ss
    SUCCESS
    

    5、执行QuickStart.rst中的用例

    • 由于login.py功能的测试用例写在QuickStart.rst中,QuickStart.rst使用了源文档标记语言,所以需要先安装pip install docutils
    • 执行测试用例的命令:robot QuickStart.rst
    • 查看结果:从图中看出共执行了5个用例,可以看到用例执行状态和报告、日志的默认输入位置及格式


      image.png

    6、用例的组成部分说明

    • 认真阅读QuickStart.rst文档,可以看到测试用例由以下几部分组成:
    *** Test Cases ***
    *** Settings ***
    *** Keywords ***
    *** Variables ***
    
    • *** Variables ***:定义变量名和值,${TEMPDIR}${/}为内置变量
    *** 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
    
    • *** Keywords ***:定义关键字,把可操作性语言转化为描述性语言

    关键字
    [Arguments] 参数1 参数2
    命令 参数1 参数2
    预期结果 状态

    *** Keywords ***
    Clear login database
        Remove file    ${DATABASE FILE}
    
    Create valid user
        [Arguments]    ${username}    ${password}
        Create user    ${username}    ${password}
        Status should be    SUCCESS
    
    Creating 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 account
        Create valid user    ${USERNAME}    ${PASSWORD}
    
    She changes her password
        Change password    ${USERNAME}    ${PASSWORD}    ${NEW PASSWORD}
        Status should be    SUCCESS
    
    She can log in with the new password
        Login    ${USERNAME}    ${NEW PASSWORD}
    
    She cannot use the old password anymore
        Attempt to login with credentials    ${USERNAME}    ${PASSWORD}
        Status should be    Access Denied
    
    • *** Settings ***:QuickStart.rst中用到了几组Settings,作用分别类似于环境变量、[Template]、[Tags]、
    *** Settings ***
    Library           OperatingSystem
    Library           lib/LoginLibrary.py
    
    Suite Setup       Clear Login Database
    Test Teardown     Clear Login Database
    
    Force Tags        quickstart
    Default Tags      example    smoke
    
    • *** Test Cases ***:包含用例名称、执行步骤、期望结果。用例步骤中包含:关键字及要传入的参数,若没有采用关键字,则直接用可操作语言实现步骤及预期结果。
    *** Test Cases ***
    User can create an account and log in
        Create Valid User    fred    P4ssw0rd
        Attempt to Login with Credentials    fred    P4ssw0rd
        Status Should Be    Logged In
    
    User cannot log in with bad password
        Create Valid User    betty    P4ssw0rd
        Attempt to Login with Credentials    betty    wrong
        Status Should Be    Access Denied
    
    User can change password
        Given a user has a valid account
        When she changes her password
        Then she can log in with the new password
        And she cannot use the old password anymore
    
    Invalid password
        [Template]    Creating user with invalid password should fail
        abCD5            ${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及命令行。

    相关文章

      网友评论

          本文标题:01_Robot Framework的安装

          本文链接:https://www.haomeiwen.com/subject/yntgvftx.html