Robotframework 我得到了一个“答案”;键和值的预期偶数,得到1。”;在Robot框架中运行post请求时
我的代码如下所示,它还使用了JSONLibraryRobotframework 我得到了一个“答案”;键和值的预期偶数,得到1。”;在Robot框架中运行post请求时,robotframework,Robotframework,我的代码如下所示,它还使用了JSONLibrary *** Settings *** Library RequestsLibrary Library JSONLibrary Library Collections *** Variables *** ${Base_URL} http://example.com *** Keywords *** ${json_string}= catenate \ ... {
*** Settings ***
Library RequestsLibrary
Library JSONLibrary
Library Collections
*** Variables ***
${Base_URL} http://example.com
*** Keywords ***
${json_string}= catenate
\ ... {
\ ... "name":"abc",
\ ... "sourceConn":{"storType":"abc","connConfig":[
\ ... {"key":"endpoint","value":"abc.com"},
\ ... {"key":"bucketname","value":"c2c-migration"},
\ ... {"key":"region","value":"us-east-1"},
\ ... {"key":"access","value":"abcdgggggfgffg"},
\ ... {"key":"security","value":"sdfggffggfgghghghggf"}
\ ... ]},
\ ... "destConn":{"storType":"abg","connConfig":[
\ ... {"key":"endpoint","value":"s3.us-east.cloud-object-storage.appdomain.cloud"},
\ ... {"key":"bucketname","value":"addddf"},
\ ... {"key":"region","value":"us-east"},
\ ... {"key":"access","value":"gffdfgfggbvgvvv"},
\ ... {"key":"security","value":"ghtyrtrdrfdfdf"}
\ ... ]},
\ ... "type":"migration",
\ ... "remainSource": true,
\ ... "Filter": {
\ ... "ObjectList": ["New Text Document (2).txt" ,"demo.txt","Blog.mp4","Captur_e.JPG"]
\ ... }
\ ... }
*** Test Cases ***
post_001
Create Session post_01 ${Base_URL}
${body}= Create Dictionary ${ Json_String}
${header}= Create Dictionary Content-Type=application/json
${Response}= Post Request post_01 /v1/adminTenantId/plans data=${body} headers=${header}
Log To Console ${Response.status_code}
Log To Console ${Response.content}
虽然你没有说过,但我猜错误来自这一行:
${body}= Create Dictionary ${Json}
在注释中,您说${Json}
是Json格式的数据。但这并不重要——关键字创建了一个字典,并且需要键值对,这些键值对将成为它的成员。
它被称为:
key_name=a_value
- e、 g.使用赋值,或作为关键字的单独参数-始终为偶数: 键\名称\值
${Json}
变量的值是一个字典-我怀疑这一点,那么您可以在调用期间将其解包:
${body}= Create Dictionary &{Json}
注意名字前面的符号,与通常的美元符号相对
如果它是一个字符串,那么您可以通过python的json
库将其转换为字典。但是,您将遇到名称冲突(因为您的变量也被命名为“json”,并且隐藏了标准库);如果变量名为“json1”:
现在
${body}
是一本字典 要解决您的问题,您需要做的就是纠正创建字典的方式。请参阅下面的工作代码,我只更正了您的代码,没有完全修改您的代码
问题就在这里-您需要同时提供键和值,即键=值。在创建字典时,您只提供了值而没有提供键,因此,错误为“应为偶数…”
工作代码
*** Settings ***
Library RequestsLibrary
Library JSONLibrary
Library Collections
*** Variables ***
${Base_URL} http://example.com
*** Test Cases ***
post_001
Create Session post_01 ${Base_URL}
${json_string}= catenate
\ ... {
\ ... "name":"abc",
\ ... "sourceConn":{"storType":"abc","connConfig":[
\ ... {"key":"endpoint","value":"abc.com"},
\ ... {"key":"bucketname","value":"c2c-migration"},
\ ... {"key":"region","value":"us-east-1"},
\ ... {"key":"access","value":"abcdgggggfgffg"},
\ ... {"key":"security","value":"sdfggffggfgghghghggf"}
\ ... ]},
\ ... "destConn":{"storType":"abg","connConfig":[
\ ... {"key":"endpoint","value":"s3.us-east.cloud-object-storage.appdomain.cloud"},
\ ... {"key":"bucketname","value":"addddf"},
\ ... {"key":"region","value":"us-east"},
\ ... {"key":"access","value":"gffdfgfggbvgvvv"},
\ ... {"key":"security","value":"ghtyrtrdrfdfdf"}
\ ... ]},
\ ... "type":"migration",
\ ... "remainSource": true,
\ ... "Filter": {
\ ... "ObjectList": ["New Text Document (2).txt" ,"demo.txt","Blog.mp4","Captur_e.JPG"]
\ ... }
\ ... }
${body}= Create Dictionary js=${json_String}
${header}= Create Dictionary Content-Type=application/json
${Response}= Post Request post_01 /v1/adminTenantId/plans data=${body} headers=${header}
Log To Console ${Response.status_code}
Log To Console ${Response.content}
输出
(rf1) C:\Users\kgurupra>robot 2.robot
[ WARN ] Error in file 'C:\Users\kgurupra\2.robot': Escaping empty cells with '\' before line continuation marker '...' is deprecated. Remove escaping before Robot Framework 3.2.
[ WARN ] Error in file 'C:\Users\kgurupra\2.robot': Escaping empty cells with '\' before line continuation marker '...' is deprecated. Remove escaping before Robot Framework 3.2.
[ WARN ] Error in file 'C:\Users\kgurupra\2.robot': Escaping empty cells with '\' before line continuation marker '...' is deprecated. Remove escaping before Robot Framework 3.2.
[ WARN ] Error in file 'C:\Users\kgurupra\2.robot': Escaping empty cells with '\' before line continuation marker '...' is deprecated. Remove escaping before Robot Framework 3.2.
[ WARN ] Error in file 'C:\Users\kgurupra\2.robot': Escaping empty cells with '\' before line continuation marker '...' is deprecated. Remove escaping before Robot Framework 3.2.
[ WARN ] Error in file 'C:\Users\kgurupra\2.robot': Escaping empty cells with '\' before line continuation marker '...' is deprecated. Remove escaping before Robot Framework 3.2.
[ WARN ] Error in file 'C:\Users\kgurupra\2.robot': Escaping empty cells with '\' before line continuation marker '...' is deprecated. Remove escaping before Robot Framework 3.2.
[ WARN ] Error in file 'C:\Users\kgurupra\2.robot': Escaping empty cells with '\' before line continuation marker '...' is deprecated. Remove escaping before Robot Framework 3.2.
[ WARN ] Error in file 'C:\Users\kgurupra\2.robot': Escaping empty cells with '\' before line continuation marker '...' is deprecated. Remove escaping before Robot Framework 3.2.
[ WARN ] Error in file 'C:\Users\kgurupra\2.robot': Escaping empty cells with '\' before line continuation marker '...' is deprecated. Remove escaping before Robot Framework 3.2.
[ WARN ] Error in file 'C:\Users\kgurupra\2.robot': Escaping empty cells with '\' before line continuation marker '...' is deprecated. Remove escaping before Robot Framework 3.2.
[ WARN ] Error in file 'C:\Users\kgurupra\2.robot': Escaping empty cells with '\' before line continuation marker '...' is deprecated. Remove escaping before Robot Framework 3.2.
[ WARN ] Error in file 'C:\Users\kgurupra\2.robot': Escaping empty cells with '\' before line continuation marker '...' is deprecated. Remove escaping before Robot Framework 3.2.
[ WARN ] Error in file 'C:\Users\kgurupra\2.robot': Escaping empty cells with '\' before line continuation marker '...' is deprecated. Remove escaping before Robot Framework 3.2.
[ WARN ] Error in file 'C:\Users\kgurupra\2.robot': Escaping empty cells with '\' before line continuation marker '...' is deprecated. Remove escaping before Robot Framework 3.2.
[ WARN ] Error in file 'C:\Users\kgurupra\2.robot': Escaping empty cells with '\' before line continuation marker '...' is deprecated. Remove escaping before Robot Framework 3.2.
[ WARN ] Error in file 'C:\Users\kgurupra\2.robot': Escaping empty cells with '\' before line continuation marker '...' is deprecated. Remove escaping before Robot Framework 3.2.
[ WARN ] Error in file 'C:\Users\kgurupra\2.robot': Escaping empty cells with '\' before line continuation marker '...' is deprecated. Remove escaping before Robot Framework 3.2.
[ WARN ] Error in file 'C:\Users\kgurupra\2.robot': Escaping empty cells with '\' before line continuation marker '...' is deprecated. Remove escaping before Robot Framework 3.2.
[ WARN ] Error in file 'C:\Users\kgurupra\2.robot': Escaping empty cells with '\' before line continuation marker '...' is deprecated. Remove escaping before Robot Framework 3.2.
[ WARN ] Error in file 'C:\Users\kgurupra\2.robot': Escaping empty cells with '\' before line continuation marker '...' is deprecated. Remove escaping before Robot Framework 3.2.
[ WARN ] Error in file 'C:\Users\kgurupra\2.robot': Escaping empty cells with '\' before line continuation marker '...' is deprecated. Remove escaping before Robot Framework 3.2.
==============================================================================
2
==============================================================================
post_001 .....404
.<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>404 - Not Found</title>
</head>
<body>
<h1>404 - Not Found</h1>
<script type="text/javascript" src="//wpc.75674.betacdn.net/0075674/www/ec_tpm_bcon.js"></script>
</body>
</html>
post_001 | PASS |
------------------------------------------------------------------------------
2 | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
Output: C:\Users\kgurupra\output.xml
Log: C:\Users\kgurupra\log.html
Report: C:\Users\kgurupra\report.html
(rf1)C:\Users\kgurupra>robot 2.robot
[警告]文件“C:\Users\kgurupra\2.robot”中出错:不推荐在行继续标记“…”之前使用“\”转义空单元格。拆除机器人框架3.2之前的逃生装置。
[警告]文件“C:\Users\kgurupra\2.robot”中出错:不推荐在行继续标记“…”之前使用“\”转义空单元格。拆除机器人框架3.2之前的逃生装置。
[警告]文件“C:\Users\kgurupra\2.robot”中出错:不推荐在行继续标记“…”之前使用“\”转义空单元格。拆除机器人框架3.2之前的逃生装置。
[警告]文件“C:\Users\kgurupra\2.robot”中出错:不推荐在行继续标记“…”之前使用“\”转义空单元格。拆除机器人框架3.2之前的逃生装置。
[警告]文件“C:\Users\kgurupra\2.robot”中出错:不推荐在行继续标记“…”之前使用“\”转义空单元格。拆除机器人框架3.2之前的逃生装置。
[警告]文件“C:\Users\kgurupra\2.robot”中出错:不推荐在行继续标记“…”之前使用“\”转义空单元格。拆除机器人框架3.2之前的逃生装置。
[警告]文件“C:\Users\kgurupra\2.robot”中出错:不推荐在行继续标记“…”之前使用“\”转义空单元格。拆除机器人框架3.2之前的逃生装置。
[警告]文件“C:\Users\kgurupra\2.robot”中出错:不推荐在行继续标记“…”之前使用“\”转义空单元格。拆除机器人框架3.2之前的逃生装置。
[警告]文件“C:\Users\kgurupra\2.robot”中出错:不推荐在行继续标记“…”之前使用“\”转义空单元格。拆除机器人框架3.2之前的逃生装置。
[警告]文件“C:\Users\kgurupra\2.robot”中出错:不推荐在行继续标记“…”之前使用“\”转义空单元格。拆除机器人框架3.2之前的逃生装置。
[警告]文件“C:\Users\kgurupra\2.robot”中出错:不推荐在行继续标记“…”之前使用“\”转义空单元格。拆除机器人框架3.2之前的逃生装置。
[警告]文件“C:\Users\kgurupra\2.robot”中出错:不推荐在行继续标记“…”之前使用“\”转义空单元格。拆除机器人框架3.2之前的逃生装置。
[警告]文件“C:\Users\kgurupra\2.robot”中出错:不推荐在行继续标记“…”之前使用“\”转义空单元格。拆除机器人框架3.2之前的逃生装置。
[警告]文件“C:\Users\kgurupra\2.robot”中出错:不推荐在行继续标记“…”之前使用“\”转义空单元格。拆除机器人框架3.2之前的逃生装置。
[警告]文件“C:\Users\kgurupra\2.robot”中出错:不推荐在行继续标记“…”之前使用“\”转义空单元格。拆除机器人框架3.2之前的逃生装置。
[警告]文件“C:\Users\kgurupra\2.robot”中出错:不推荐在行继续标记“…”之前使用“\”转义空单元格。拆除机器人框架3.2之前的逃生装置。
[警告]文件“C:\Users\kgurupra\2.robot”中出错:不推荐在行继续标记“…”之前使用“\”转义空单元格。拆除机器人框架3.2之前的逃生装置。
[警告]文件“C:\Users\kgurupra\2.robot”中出错:不推荐在行继续标记“…”之前使用“\”转义空单元格。拆除机器人框架3.2之前的逃生装置。
[警告]文件“C:\Users\kgurupra\2.robot”中出错:不推荐在行继续标记“…”之前使用“\”转义空单元格。拆除机器人框架3.2之前的逃生装置。
[警告]文件“C:\Users\kgurupra\2.robot”中出错:不推荐在行继续标记“…”之前使用“\”转义空单元格。拆除机器人框架3.2之前的逃生装置。
[警告]文件“C:\Users\kgurupra\2.robot”中出错:不推荐在行继续标记“…”之前使用“\”转义空单元格。拆除机器人框架3.2之前的逃生装置。
[警告]文件“C:\Users\kgurupra\2.robot”中出错:不推荐在行继续标记“…”之前使用“\”转义空单元格。拆除机器人框架3.2之前的逃生装置。
==============================================================================
2.
==============================================================================
邮政编码001…404
.
404-找不到
404-找不到
*** Settings ***
Library RequestsLibrary
Library JSONLibrary
Library Collections
*** Variables ***
${Base_URL} http://example.com
*** Test Cases ***
post_001
Create Session post_01 ${Base_URL}
${json_string}= catenate
\ ... {
\ ... "name":"abc",
\ ... "sourceConn":{"storType":"abc","connConfig":[
\ ... {"key":"endpoint","value":"abc.com"},
\ ... {"key":"bucketname","value":"c2c-migration"},
\ ... {"key":"region","value":"us-east-1"},
\ ... {"key":"access","value":"abcdgggggfgffg"},
\ ... {"key":"security","value":"sdfggffggfgghghghggf"}
\ ... ]},
\ ... "destConn":{"storType":"abg","connConfig":[
\ ... {"key":"endpoint","value":"s3.us-east.cloud-object-storage.appdomain.cloud"},
\ ... {"key":"bucketname","value":"addddf"},
\ ... {"key":"region","value":"us-east"},
\ ... {"key":"access","value":"gffdfgfggbvgvvv"},
\ ... {"key":"security","value":"ghtyrtrdrfdfdf"}
\ ... ]},
\ ... "type":"migration",
\ ... "remainSource": true,
\ ... "Filter": {
\ ... "ObjectList": ["New Text Document (2).txt" ,"demo.txt","Blog.mp4","Captur_e.JPG"]
\ ... }
\ ... }
${body}= Create Dictionary js=${json_String}
${header}= Create Dictionary Content-Type=application/json
${Response}= Post Request post_01 /v1/adminTenantId/plans data=${body} headers=${header}
Log To Console ${Response.status_code}
Log To Console ${Response.content}
(rf1) C:\Users\kgurupra>robot 2.robot
[ WARN ] Error in file 'C:\Users\kgurupra\2.robot': Escaping empty cells with '\' before line continuation marker '...' is deprecated. Remove escaping before Robot Framework 3.2.
[ WARN ] Error in file 'C:\Users\kgurupra\2.robot': Escaping empty cells with '\' before line continuation marker '...' is deprecated. Remove escaping before Robot Framework 3.2.
[ WARN ] Error in file 'C:\Users\kgurupra\2.robot': Escaping empty cells with '\' before line continuation marker '...' is deprecated. Remove escaping before Robot Framework 3.2.
[ WARN ] Error in file 'C:\Users\kgurupra\2.robot': Escaping empty cells with '\' before line continuation marker '...' is deprecated. Remove escaping before Robot Framework 3.2.
[ WARN ] Error in file 'C:\Users\kgurupra\2.robot': Escaping empty cells with '\' before line continuation marker '...' is deprecated. Remove escaping before Robot Framework 3.2.
[ WARN ] Error in file 'C:\Users\kgurupra\2.robot': Escaping empty cells with '\' before line continuation marker '...' is deprecated. Remove escaping before Robot Framework 3.2.
[ WARN ] Error in file 'C:\Users\kgurupra\2.robot': Escaping empty cells with '\' before line continuation marker '...' is deprecated. Remove escaping before Robot Framework 3.2.
[ WARN ] Error in file 'C:\Users\kgurupra\2.robot': Escaping empty cells with '\' before line continuation marker '...' is deprecated. Remove escaping before Robot Framework 3.2.
[ WARN ] Error in file 'C:\Users\kgurupra\2.robot': Escaping empty cells with '\' before line continuation marker '...' is deprecated. Remove escaping before Robot Framework 3.2.
[ WARN ] Error in file 'C:\Users\kgurupra\2.robot': Escaping empty cells with '\' before line continuation marker '...' is deprecated. Remove escaping before Robot Framework 3.2.
[ WARN ] Error in file 'C:\Users\kgurupra\2.robot': Escaping empty cells with '\' before line continuation marker '...' is deprecated. Remove escaping before Robot Framework 3.2.
[ WARN ] Error in file 'C:\Users\kgurupra\2.robot': Escaping empty cells with '\' before line continuation marker '...' is deprecated. Remove escaping before Robot Framework 3.2.
[ WARN ] Error in file 'C:\Users\kgurupra\2.robot': Escaping empty cells with '\' before line continuation marker '...' is deprecated. Remove escaping before Robot Framework 3.2.
[ WARN ] Error in file 'C:\Users\kgurupra\2.robot': Escaping empty cells with '\' before line continuation marker '...' is deprecated. Remove escaping before Robot Framework 3.2.
[ WARN ] Error in file 'C:\Users\kgurupra\2.robot': Escaping empty cells with '\' before line continuation marker '...' is deprecated. Remove escaping before Robot Framework 3.2.
[ WARN ] Error in file 'C:\Users\kgurupra\2.robot': Escaping empty cells with '\' before line continuation marker '...' is deprecated. Remove escaping before Robot Framework 3.2.
[ WARN ] Error in file 'C:\Users\kgurupra\2.robot': Escaping empty cells with '\' before line continuation marker '...' is deprecated. Remove escaping before Robot Framework 3.2.
[ WARN ] Error in file 'C:\Users\kgurupra\2.robot': Escaping empty cells with '\' before line continuation marker '...' is deprecated. Remove escaping before Robot Framework 3.2.
[ WARN ] Error in file 'C:\Users\kgurupra\2.robot': Escaping empty cells with '\' before line continuation marker '...' is deprecated. Remove escaping before Robot Framework 3.2.
[ WARN ] Error in file 'C:\Users\kgurupra\2.robot': Escaping empty cells with '\' before line continuation marker '...' is deprecated. Remove escaping before Robot Framework 3.2.
[ WARN ] Error in file 'C:\Users\kgurupra\2.robot': Escaping empty cells with '\' before line continuation marker '...' is deprecated. Remove escaping before Robot Framework 3.2.
[ WARN ] Error in file 'C:\Users\kgurupra\2.robot': Escaping empty cells with '\' before line continuation marker '...' is deprecated. Remove escaping before Robot Framework 3.2.
==============================================================================
2
==============================================================================
post_001 .....404
.<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>404 - Not Found</title>
</head>
<body>
<h1>404 - Not Found</h1>
<script type="text/javascript" src="//wpc.75674.betacdn.net/0075674/www/ec_tpm_bcon.js"></script>
</body>
</html>
post_001 | PASS |
------------------------------------------------------------------------------
2 | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
Output: C:\Users\kgurupra\output.xml
Log: C:\Users\kgurupra\log.html
Report: C:\Users\kgurupra\report.html