Robot Framework 学习

#Robot Framework 第一章 基础库
Robot framework就是通用的自动化测试框架,用于验收测试和验收测试驱动开发
User Guide

自带的库

  • Builtin: 提供通用关键字
  • stint
  • Screeshot
  • date

-第三方的库

  • web自动化: selenuimLibrary
  • Windows GUI 测试: AutoltLibrary
  • 数据库测设: database Library
  • 文件对比测试: diff
  • Http

Robot framwork 基础关键字
可以通过F5找到库,同时点击库查看相应的关键字。我的理解,关键字就是封装好的方法

  • 创建关键字:
*** Settings ***
Documentation     ssh connection
Suite Setup       Open Connection And Log In
Suite Teardown    Close All Connections
Library           SSHLibrary
 *** Keywords ***
Open Connection And Log In
    Open Connection    ${HOST}
    Login    ${USERNAME}    ${PASSWORD}
 Suite Setup       Open Connection And Log In
  • 基础关键字:
*** Test Cases ***
Variable
    ${a}    set variable    Hello world
    log    ${a}

list
    ${abc}    Create List    a    b    c
    Log    ${abc}

catenate
    ${Hi}    Catenate    Robot    Framework
    log    ${Hi}

time
    ${t}    get time
    log    ${t}
    sleep    5
    ${t}    get time
    log    ${t}

if
    ${a}    Set variable    59
    run keyword if    ${a}>=90    log    great
    ...    ELSE IF    ${a}>=70    log    pass
    ...    ELSE IF    ${a}>=60    log    ok
    ...    ELSE    log    fail

for
    : FOR    ${i}    IN RANGE    10
    \    log    ${i}

evaluate
    ${d}    Evaluate    random.randint(1000,9999)    random
    log    ${d}

time_py
    ${t}    Evaluate    time.ctime()    time
    log    ${t}

###用户关键字
相当于Python中的封装的方法

*** Test Cases ***
test_range
    myrange    10

*** Keywords ***
myrange
    [Arguments]    ${times}
    :FOR    ${i}    IN RANGE    ${times}
    \    log    ${i}
  

引用资源文件中的关键字

  • 在测试套件里边导入资源文件
*** Settings ***
Resource          module.robot

*** Test Cases ***
test_range
    myrange    10
    ${c}    add    2    3
    log    ${c}

setup/Teardown 开始和结束的操作

test_case2
    [Setup]    start
    log    this is a test case
    [Teardown]    end

*** Keywords ***
start
    log    start test

end
    log    end test

Selenium2Library

用于web测试

  • crtl + N 快速创建一个project
  • 选中创建好的项目new suite创建一个测试套件
  • 选中创建好的测试套件new Test Case 创建一个测试用例
  • 在测试套件的edit界面点击library,然后点击ok。如果显示为红色,表示导入的库不存在,如果是黑色,则导入成功。
  • 在ride软件中可以使用F5查看关键字
  • 编写测试用例
    • 打开浏览器 如果第三栏不填,默认是使用firefox浏览器
    • 根据id找到输入框,输入’软件测试’搜索内容
    • 点击按钮搜索
    • . 等待3秒
    • 关闭浏览器
*** Settings ***
Library            Selenium2Library

*** Test Cases ***
Baidu_case
    open browser    https://www.baidu.com    firefox
    input text    id=kw    selenium2library
    click button    id=su
    sleep    2
    ${title}    get title
    log    ${title}
    Should Contain    ${title}    selenium2library_百度搜索
    Close browser

##RequestsLibrary
用于http接口自动化测试

##SSHLibrary
进入python27/Scripts下面执行: pip install robotframework-sshlibrary

  • ssh 连接执行指令和拽文件

    code:

      *** Settings ***
      Library           SSHLibrary
      
      *** Test Cases ***
      simple connection
          [Documentation]    only used to connect
          Open Connection    10.20.0.20    port=22
          Login    root    r00tme
          write    virsh list --title --all > /tmp/test
          Get File    /tmp/test    log.txt
    
  • 返回指令验证

发布了5 篇原创文章 · 获赞 0 · 访问量 40

猜你喜欢

转载自blog.csdn.net/Liu1584266/article/details/82356511