需要通过机器人框架

时间:2017-12-19 10:16:36

标签: post robotframework

我是机器人框架的新手,我需要通过机器人框架发出POST请求。我能够通过postman工具成功运行post请求。下面是我通过postman工具生成的curl命令:

curl -X POST \
  http://ip:port/ai/data/upload \
  -H 'content-type: multipart/form-data \
  -F 'fileData=@C:\Users\xyz\Desktop\report.html' \
  -F clientId=client \
  -F subClientId=test \
  -F fileType=compliance

有人可以帮我解决机器人中相当于上面的卷曲请求吗?

2 个答案:

答案 0 :(得分:0)

正如亚历克斯建议你想看看 https://github.com/bulkan/robotframework-requests

或者

将命令(curl ...)存储在command.sh文件中,然后通过Process Library http://robotframework.org/robotframework/2.8.6/libraries/Process.html

执行此command.sh文件

代码:

*** Settings ***
Library    Process
*** Variables ***
*** Test cases ***
Test Requests
    test process
*** Keywords ***
test process
    ${handle}=    Start Process    command.sh     #make sure your robotfile and command.sh is in same directory or give path till sh file

答案 1 :(得分:0)

使用Robot RequestsLibrary

以下是与多部分文件上传案例相关的相关链接。

https://github.com/bulkan/robotframework-requests/issues/131

试试这个:

*Settings*

Library  RequestsLibrary
Library  OperatingSystem

*Test Case*
Test One
  &{data}=  Create Dictionary  foo=bar
  Create File  foobar  content=foobarcontent
  &{files}=  Evaluate  {'foofile': open('foobar')}
  ${resp}=  Evaluate
  ...  requests.post('http://localhost:8000/foo', data=$data, files=$files)
  ...  modules=requests
  Log  ${resp}  console=${TRUE}
相关问题