I have a compare json data in Robot framework issue. If I have three json as below:
json_A:
{
"name":"XXX",
"Type": {
"SubType": {
"Properties": [
"Status",
"Model",
"State",
"Tag",
"Number"],
}
}
}
json_B:
{
"Status": OK,
"Model": YYY,
"Number": 0000,
"Task": XYZ
}
json_C:
{
"Status": OK,
"Model": YYY,
"Number": 0000
"State": ON
"Tag": 1234
}
Here are I want to do:
result_A = compare Properties of json_A and Object of json_B and collect SAME object
if "ALL" object of the result_A exist in json_C
is true and print all object key and value
else
break
So the result will be true and it will display
{
"Status": OK,
"Model": YYY,
"Number": 0000
}
I know it might be complicated, but could robot framework has related keyword to do that? Thanks!!
Also attach my work for now:
*** Settings ***
Library JsonValidator
*** Keywords ***
Get_Response_1
[Arguments] ${ip}=${ip}
... ${username}=${USERNAME}
... ${password}=${PASSWORD}
${auth} = Create List ${username} ${password}
Create Session alias=test_session url=http://${ip}:8080/redfish/v1
... auth=${auth} verify=${False}
${response} = GET On Session test_session
... url=https://${ip}:8080/redfish/v1/XXXXXX/YYYYY/ZZZZZ
Status Should Be 200 ${response}
Should Be Equal As Strings OK ${response.reason}
[Return] ${response}
Get_Response_2
[Arguments] ${ip}=${ip}
... ${username}=${USERNAME}
... ${password}=${PASSWORD}
${auth} = Create List ${username} ${password}
Create Session alias=test_session url=http://${ip}:8080/redfish/v1
... auth=${auth} verify=${False}
${response} = GET On Session test_session
... url=https://${ip}:8080/redfish/v1/AAAA/BBBB/CCCC
Status Should Be 200 ${response}
Should Be Equal As Strings OK ${response.reason}
[Return] ${response}
Get_JSON_File_Data
[Documentation] Get_JSON_File_Data
${json}= Get File D:\\xxx\yyy\zzz\\json_A.json
${Properties}= get json value ${json} /Type/SubType/Properties
[Return] ${Properties}
Get_Properties_List
[Documentation] Get_Properties_List
[Arguments] ${GET_RESPONSE_DATA}
${reponse_content}= Parse Json ${GET_RESPONSE_DATA.content}
log ${reponse_content}
FOR ${properties} IN @{reponse_content}
${elements}= get elements ${reponse_content} ${properties}
${properties_list}= create dictionary ${properties} ${elements}
Log ${elements}
Log ${properties}
Log ${properties_list}
END
[Return] ${properties_list}
*** Test Cases ***
${Properties}= Get_JSON_File_Data
log ${Properties}
${GET_JSON_RESPONSE_1}= GET_Response_1
log ${GET_JSON_RESPONSE_1.content}
${properties_list}= Get_Properties_List ${GET_JSON_RESPONSE_1}
Log ${properties_list}
${GET_JSON_RESPONSE_2}= GET_Response_2
Log ${GET_JSON_RESPONSE_2.content}
${properties_list}= Get_Properties_List ${GET_JSON_RESPONSE_2}