我有一个服务定义(Rest),并且我想在Robot Frameowrk中执行POST Request lavereging RequestsLibrary。服务本身的问题在于设计带有字典的词典。您发现甚至创建这样的Post方法是否可行?
服务定义接受以下结构。我正在创建以下关键字来协调:
PostRequestAPI
Create Session ${AliasName} ${PostReqURL} auth=${Authen}
${head}= Create Dictionary Content-Type=application/json Authorization=Basic c3U6Z3c=
${resp}= Post Request ${AliasName} ${PostReqURI} data={"payload":{"BatchFeeAmount":10, "NonCollectableFeeAmount':11,"FileID":"234324324322"},"header":{"saveDate":"2019-07-17T16:37:22.123Z" }} headers=${head} # (edited)
${resp} = Response [400] [Expected service definition ]
图片1
答案 0 :(得分:0)
有可能。有两种方法:
Method 1:
您有两个字典,payload
和header
,您想在第三本字典中用作键值对。如果您逐步进行操作,则下面是您将得到的代码:
Dictionary of dictionary
${payload} Create Dictionary BatchFeeAmount=10 NonCollectableFeeAmount=11 FileID=234324324322
${header} Create Dictionary saveDate=2019-07-17T16:37:22.123Z
${data} Create Dictionary payload=${payload} header=${header}
Log To Console ${data}
// ${data} contains the API POST request payload in your desired format
Method 2:
您还可以将嵌套字典定义为纯python变量,然后在机器人脚本中使用该文件。如下所示:
variables.py
data ={"payload":{"BatchFeeAmount":10, "NonCollectableFeeAmount":11, "FileID":234324324322}, "header":{"saveDate":"2019-07-17T16:37:22.123Z"}}
test_case.robot
*** Settings ***
Variables /path/to/variables.py
*** Test Cases ***
Dictionary of Dictionaries
Log to Console ${data}