栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

实验四:Robotframework框架实验

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

实验四:Robotframework框架实验

安装Robotframework框架,对实验二中开发的接口进行自动化测试,要求出现个人信息,提交源代码,以及过程与结果截图

1、安装robotframework环境

(由于老师要求截图要带个人信息,所以红色的小方块是我打的马赛克,虽然看上去也没什么用)
我是直接在pycharm的Terminal里面安装的,不是打开了电脑的cmd,都一样,能装成功能用就行,报错的话就要自己去找问题哦~

(1)安装robotframework

pip install robotframework


(2)安装 wxPython-4.0.3 (ride可视化界面必备的python图形化支持)

pip install wxPython


(3)安装ride用于编写rf脚本 robotframework-ride

pip install robotframework-ride



(4)安装测试UI 自动化支持 robotframework-SeleniumLibrary

pip install robotframework-SeleniumLibrary

(5)安装测试接口支持 robotframework-httplibrary 和robotframework-requests

pip install robotframework-httplibrary
pip install robotframework-requests

(6)安装 robot framework数据库访问插件

pip install PyMySQL

2、点击桌面的ride,如果打不开,可能是你的Python版本3.8,因为我也打不开,但是有别的办法可以打开,需要自己上网找。我是个笨人,我直接重装了Python3.7版本,然后把原来的代码复制过去了,o(╥﹏╥)o

3、在ride界面里面找到你Pycharm项目的位置,我的项目在D盘

4、一直找到你项目名字出现

5、导入库

6、测试用例



7、测试

8、报告(报错的时候看很有帮助)

9、记得去数据库刷新看看数据变化,当然,查看数据没啥

10、Pycharm的代码,可以看到多出了一个文件夹和.robot文件

仅作参考。
我也是找到别人的博客学习的,只是忘记了那篇博客是哪一篇。

*** Settings ***
Library           RequestsLibrary

*** Test Cases ***
test_add_params_null
    &{header}=    Create Dictionary    Content-type=application/x-www-form-urlencoded
    Create Session    cbb    http://127.0.0.1:5000    headers=${header}
    &{data}=    Create Dictionary
    ${resp}    Post on Session    cbb    /add    data=${data}
    log    ${resp.json().get("code")}
    log    ${resp.json().get("message")}
    Should Be Equal As Numbers    10001    ${resp.json().get("code")}

test_add_success
    &{header}=    Create Dictionary    Content-type=application/x-www-form-urlencoded
    Create Session    cbb    http://127.0.0.1:5000    headers=${header}
    &{data}=    Create Dictionary    name=测试添加数据    age=430
    ${resp}    Post on Session    cbb    /add    data=${data}
    log    ${resp.json().get("code")}
    log    ${resp.json().get("message")}
    Should Be Equal As Numbers    200    ${resp.json().get("code")}

test_delete_id_null
    &{header}=    Create Dictionary    Content-type=application/x-www-form-urlencoded
    Create Session    cbb    http://127.0.0.1:5000    headers=${header}
    &{data}=    Create Dictionary
    ${resp}    Post on Session    cbb    /delete    data=${data}
    log    ${resp.json().get("code")}
    log    ${resp.json().get("message")}
    Should Be Equal As Numbers    10001    ${resp.json().get("code")}

test_delete_success
    &{header}=    Create Dictionary    Content-type=application/x-www-form-urlencoded
    Create Session    cbb    http://127.0.0.1:5000    headers=${header}
    &{data}=    Create Dictionary    id=30
    ${resp}    Post on Session    cbb    /delete    data=${data}
    log    ${resp.json().get("code")}
    log    ${resp.json().get("message")}
    Should Be Equal As Numbers    200    ${resp.json().get("code")}

test_update_params_null
    &{header}=    Create Dictionary    Content-type=application/x-www-form-urlencoded
    Create Session    cbb    http://127.0.0.1:5000    headers=${header}
    &{data}=    Create Dictionary
    ${resp}    Post on Session    cbb    /update    data=${data}
    log    ${resp.json().get("code")}
    log    ${resp.json().get("message")}
    Should Be Equal As Numbers    10001    ${resp.json().get("code")}

test_update_success
    &{header}=    Create Dictionary    Content-type=application/x-www-form-urlencoded
    Create Session    cbb    http://127.0.0.1:5000    headers=${header}
    &{data}=    Create Dictionary    id=30    name=测试修改数据    age=430
    ${resp}    Post on Session    cbb    /update    data=${data}
    log    ${resp.json().get("code")}
    log    ${resp.json().get("message")}
    Should Be Equal As Numbers    200    ${resp.json().get("code")}

test_query_id_null
    &{header}=    Create Dictionary    Content-type=application/x-www-form-urlencoded
    Create Session    cbb    http://127.0.0.1:5000    headers=${header}
    &{data}=    Create Dictionary
    ${resp}    Post on Session    cbb    /query    data=${data}
    log    ${resp.json().get("code")}
    log    ${resp.json().get("message")}
    Should Be Equal As Numbers    10001    ${resp.json().get("code")}

test_query_success
    &{header}=    Create Dictionary    Content-type=application/x-www-form-urlencoded
    Create Session    cbb    http://127.0.0.1:5000    headers=${header}
    &{data}=    Create Dictionary    id=1
    ${resp}    Post on Session    cbb    /query    data=${data}
    log    ${resp.json().get("code")}
    log    ${resp.json().get("message")}
    Should Be Equal As Numbers    200    ${resp.json().get("code")}

结语:

你知道,有些鸟是注定不会关在牢笼里的,它的每一片羽毛都闪耀着自由的光辉。——《肖申克的救赎》

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/870673.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号