2.12-使用robotframework进行接口自动化测试

使用robotframework进行接口自动化测试

回到第一章:目录



前言

这节将使用RF框架对 2.8- 使用idea开发javaWeb应用程序-4(实现用户的增删改查) 开发的第一个网站进行接口自动化测试。
测试内容:
登录;新增用户;查询用户;修改用户;删除用户


1、运行2.8节的项目

可正常通过浏览器访问:
在这里插入图片描述

2、检查robot framework环境是否正常

打开cmd命令行,输入python --version
pip --version
在这里插入图片描述

如果提示版本信息则说明安装好了。
没有安装好,则 2.11节的方法进行安装: 2.11-robot framework 自动化测试框架环境搭建

3、启动ride.py

命令行输入 ride.py
如果操作系统提示不知道用什么程序怎么打开,则手动选则用python.exe打开。

启动后,建立一个目录用来存放rf脚本:E:\new\rf_test
在ride的左边,选中这个目录,鼠标右键 new Suit 输入 接口自动化测试。
在这里插入图片描述

4、引入接口测试库:RequestsLibrary

点击右边的 Library,输入 RequestsLibrary点ok,
在这里插入图片描述
RequestsLibrary为黑色表示引入成功,若不成功则为红色。
在这里插入图片描述

5、编写接口测试脚本

在 接口自动化测试上 右键,new testcase ,输入登录,编写脚本 。

在这里插入图片描述
同样的方法,编写:添加用户,查询用户,修改用户,删除用户的接口测试脚本:

*** Settings ***
Library           RequestsLibrary

*** Test Cases ***
登录
    &{header}=    Create Dictionary    Content-type=application/x-www-form-urlencoded
    Create Session    mysite    http://localhost:8282    headers=${header}
    &{data}=    Create Dictionary    uname=admin    pwd=123456
    ${resp}    Post Request    mysite    FirstJavaWeb/login    data=${data}
    log    ${resp.status_code}
    log    ${resp.text}
    Should Be Equal As Numbers    200    ${resp.status_code}

添加用户
    &{header}=    Create Dictionary    Content-type=application/x-www-form-urlencoded
    Create Session    mysite    http://localhost:8282    headers=${header}
    &{data}=    Create Dictionary    uname=rf_add    pwd=123456    realName=自动化用户    sex=男    pwdRepeat=123456
    ${resp}    Post Request    mysite    FirstJavaWeb/user/addUser    data=${data}
    log    ${resp.status_code}
    log    ${resp.text}
    Should Be Equal As Numbers    200    ${resp.status_code}

查询用户
    &{header}=    Create Dictionary    Content-type=application/x-www-form-urlencoded
    Create Session    mysite    http://localhost:8282    headers=${header}
    ${resp}    Post Request    mysite    FirstJavaWeb/user/list
    log    ${resp.status_code}
    log    ${resp.text}
    Should Be Equal As Numbers    200    ${resp.status_code}
    Should Contain    ${resp.text}    admin

修改用户
    &{header}=    Create Dictionary    Content-type=application/x-www-form-urlencoded
    Create Session    mysite    http://localhost:8282    headers=${header}
    &{data}=    Create Dictionary    uname=rf_add    pwd=123456    realName=自动化用户修改    sex=男    pwdRepeat=123456    id=42599
    ${resp}    Post Request    mysite    FirstJavaWeb/user/addUser    data=${data}
    log    ${resp.status_code}
    log    ${resp.text}
    Should Be Equal As Numbers    200    ${resp.status_code}

删除用户
    &{header}=    Create Dictionary    Content-type=application/x-www-form-urlencoded
    Create Session    mysite    http://localhost:8282    headers=${header}
    &{data}=    Create Dictionary    id=42600
    ${resp}    Post Request    mysite    FirstJavaWeb/user/del     data=${data}
    log    ${resp.status_code}
    log    ${resp.text}
    Should Be Equal As Numbers    200    ${resp.status_code}

6、运行接口自动化脚本

点击工具栏上的运行按钮:
在这里插入图片描述
确认数据变化的正确性:
在这里插入图片描述

  • 2
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值