RobotFramework 接口自动化实战案例
1.进行接口测试
参数说明:
1.Create Dictionary 创建字典
2.Set Variable 设置参数
3.Create Session app http://127.0.0.1:8090 创建session
4.Post Request app /api/admin/login data=${data} 发送post请求
5.To Json ${reponse.content} 将数据转换为json格式的数据
6.Should Contain ${reponse}.status 200 状态码断言
详细脚本内容:
*** Settings ***
Library RequestsLibrary
Library collections
Library jsonpath*** Test Cases ***登录${headers} Create Dictionary Content-Type=application/json User-Agent=Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36Create Session app http://127.0.0.1:8090 ${headers}${data} Set Variable {
"password":"12345678","username":"liuhao"}${reponse} Post Request app /api/admin/login data=${data}${rp} To Json ${reponse.content}log ${rp}[data][access_token] #获取tokenlog ${reponse}.statusShould Contain ${reponse}.status 200log 登录成功