POST API 中的请求使用 ROBOT Framework 进行测试
POST Request in API Testing using ROBOT Framework
大家好我想POST将以下格式作为ROBOT Framework的输入。
{
"Description": "School",
"Details": [
{
"name": "Test1",
"Surname": "XYZ"
},
{
"name1": "Test2",
"Surname2": "ABC"
}
]
}
但我收到以下错误
body={"Error":"module 'jsonschema._utils' has no attribute 'types_msg'"}
下面是我的代码
${tag_1} = create dictionary name="Test1" value"XYZ"
${tag_2} = create dictionary name="Test2" value"ABC"
${body} = create list Description="School" Details=[$tag_1,$tag_2]
${header}= create dictionary Authorization=%{TEMP_TOKEN} content-Type=application/json
${create_student}= post On Session ABCDE /input json=${body} headers=${header} expected_status=200
在我看来有一些问题 - 主要是,您试图将 json 存储在数组中,而不是对象中,并且您没有转换为 JSON。
键值周围还有双引号,值“XYX”和值“ABC”无效 key/value,这也不符合您的示例,因为它应该是“姓氏”[=12] =]
下面的一些示例更改:
# Name and Surname Objects - Updated to remove double quotes and match the provided json with "Surname" instead of "value"
${tag_1} Create Dictionary name=Test1 Surname=XYZ
${tag_2} Create Dictionary name=Test2 Surname=ABC
# Details List / Json Array
@{details} Create List ${tag_1} ${tag_2}
# Body - Fixed so it's an object not an array
&{body} Create Dictionary
... Description=School
... Details=${details}
# Convert the body to JSON
${body} Evaluate json.dumps(${body}) json
输出:
{"Description": "School", "Details": [{"name": "Test1", "Surname": "XYZ"}, {"name": "Test2", "Surname": "ABC"}]}
大家好我想POST将以下格式作为ROBOT Framework的输入。
{
"Description": "School",
"Details": [
{
"name": "Test1",
"Surname": "XYZ"
},
{
"name1": "Test2",
"Surname2": "ABC"
}
]
}
但我收到以下错误
body={"Error":"module 'jsonschema._utils' has no attribute 'types_msg'"}
下面是我的代码
${tag_1} = create dictionary name="Test1" value"XYZ"
${tag_2} = create dictionary name="Test2" value"ABC"
${body} = create list Description="School" Details=[$tag_1,$tag_2]
${header}= create dictionary Authorization=%{TEMP_TOKEN} content-Type=application/json
${create_student}= post On Session ABCDE /input json=${body} headers=${header} expected_status=200
在我看来有一些问题 - 主要是,您试图将 json 存储在数组中,而不是对象中,并且您没有转换为 JSON。
键值周围还有双引号,值“XYX”和值“ABC”无效 key/value,这也不符合您的示例,因为它应该是“姓氏”[=12] =]
下面的一些示例更改:
# Name and Surname Objects - Updated to remove double quotes and match the provided json with "Surname" instead of "value"
${tag_1} Create Dictionary name=Test1 Surname=XYZ
${tag_2} Create Dictionary name=Test2 Surname=ABC
# Details List / Json Array
@{details} Create List ${tag_1} ${tag_2}
# Body - Fixed so it's an object not an array
&{body} Create Dictionary
... Description=School
... Details=${details}
# Convert the body to JSON
${body} Evaluate json.dumps(${body}) json
输出:
{"Description": "School", "Details": [{"name": "Test1", "Surname": "XYZ"}, {"name": "Test2", "Surname": "ABC"}]}