如何在Robot框架中创建POST(ReST)API

Dee*_*i K 5 python http robotframework

我需要在Robot Framework中复制以下API调用:

curl -X POST "http://xyz/api/createApp" -H "Content-Type:application/json" -d @/tmp/testfile.json

testfile.json有一个json有效负载.我无法将Json文件的内容作为正文发送.

我导入了HTTP库.但是没有看到用文件进行API调用的任何关键词.

Mar*_*kHu 10

Bulkan的机器人框架要求很好.但是如果你能用更少的东西,你可以在几行中做你自己的本地lib/posthttp.py:

import requests
import json

def do_requests_post( url=None, data=None, headers={"Content-Type":"application/json"}):
    return requests.post( url, data=data, headers=json.loads(headers) )

def do_requests_request( method="GET" url=None, data=None, headers={}):
    return requests.request( url, method=method, data=data, headers=json.loads(headers))
Run Code Online (Sandbox Code Playgroud)

请注意,返回对象是功能丰富的"响应",它具有成员函数.json()(如果.text被感知为JSON 则返回dict )和.status_code(int).


Har*_*rri 5

http://bulkan.github.io/robotframework-requests/#Post有files参数.你可以做的是使用Get FileOperatingSystem库中的关键字并将其传递给你的Post关键字.