如何从机器人框架中的嵌套字典变量中提取值?
How to extract values from nested dictionary variable in robot framework?
我有嵌套的 dict 变量,想从中提取值以比较它是否等于实际值。使用键它工作正常但是然后使用嵌套字典我没有找到如何提取值的方法(例如operatorid)。你对如何去做有什么建议吗?
变量
${HIRING_DATA_TYPES}= {'Job Profile': {"AND":"", "operatorId": 'in the selection list', "targetInstances": 'Finance'},
... 'Recruiter': {"AND":"", "operatorId": 'not in the selection list', "targetInstances": '3314 Tax'},'Job Requisition': {"AND":"", "operatorId": 'is not empty'},
... 'Description': {"AND":"", "operatorId": 'equal to', "dataType":"Text", "targetType": 'targetText', "targetValue": "SDET_text"},
... 'Description 2': {"AND":"", "operatorId": 'greater than', "dataType":"Text", "targetType": "targetText", "targetValue": "SDET_text"},
... 'Description 3': {"AND":"", "operatorId": 'greater than or equal to', "dataType":"Text", "targetType": "targetText", "targetValue": "SDET_text"}}
提取密钥
Check Added Source Fields
[Arguments] ${RESPONSE} ${FILTERS_TO_ADD}
${ACTUAL_SOURCE_FIELDS}= Get Json Path ${RESPONSE} $.pipelines..filter..children..field..descriptor
Sort list ${ACTUAL_SOURCE_FIELDS}
${FILTERS_TO_ADD}= Evaluate ${HIRING_DATA_TYPES}
${EXPECTED_SOURCE_FIELDS}= Get Dictionary Keys ${FILTERS_TO_ADD}
Lists Should Be Equal ${ACTUAL_SOURCE_FIELDS} ${EXPECTED_SOURCE_FIELDS}
它以下列方式对我有用:
Check Added Comp Operators and Values
[Arguments] ${RESPONSE} ${FILTERS_TO_ADD}
@{EXPECTED_COMP_OPERATOR}= Create List
FOR ${key} IN @{HIRING_DATA_TYPES.keys()}
${COMP_OPER_VALUES}= Get From Dictionary ${HIRING_DATA_TYPES}[${key}] operatorId
Append To List ${EXPECTED_COMP_OPERATOR} ${COMP_OPER_VALUES}
END
Lists Should Be Equal ${ACTUAL_COMP_OPER} ${EXPECTED_COMP_OPERATOR}
我有嵌套的 dict 变量,想从中提取值以比较它是否等于实际值。使用键它工作正常但是然后使用嵌套字典我没有找到如何提取值的方法(例如operatorid)。你对如何去做有什么建议吗? 变量
${HIRING_DATA_TYPES}= {'Job Profile': {"AND":"", "operatorId": 'in the selection list', "targetInstances": 'Finance'},
... 'Recruiter': {"AND":"", "operatorId": 'not in the selection list', "targetInstances": '3314 Tax'},'Job Requisition': {"AND":"", "operatorId": 'is not empty'},
... 'Description': {"AND":"", "operatorId": 'equal to', "dataType":"Text", "targetType": 'targetText', "targetValue": "SDET_text"},
... 'Description 2': {"AND":"", "operatorId": 'greater than', "dataType":"Text", "targetType": "targetText", "targetValue": "SDET_text"},
... 'Description 3': {"AND":"", "operatorId": 'greater than or equal to', "dataType":"Text", "targetType": "targetText", "targetValue": "SDET_text"}}
提取密钥
Check Added Source Fields
[Arguments] ${RESPONSE} ${FILTERS_TO_ADD}
${ACTUAL_SOURCE_FIELDS}= Get Json Path ${RESPONSE} $.pipelines..filter..children..field..descriptor
Sort list ${ACTUAL_SOURCE_FIELDS}
${FILTERS_TO_ADD}= Evaluate ${HIRING_DATA_TYPES}
${EXPECTED_SOURCE_FIELDS}= Get Dictionary Keys ${FILTERS_TO_ADD}
Lists Should Be Equal ${ACTUAL_SOURCE_FIELDS} ${EXPECTED_SOURCE_FIELDS}
它以下列方式对我有用:
Check Added Comp Operators and Values
[Arguments] ${RESPONSE} ${FILTERS_TO_ADD}
@{EXPECTED_COMP_OPERATOR}= Create List
FOR ${key} IN @{HIRING_DATA_TYPES.keys()}
${COMP_OPER_VALUES}= Get From Dictionary ${HIRING_DATA_TYPES}[${key}] operatorId
Append To List ${EXPECTED_COMP_OPERATOR} ${COMP_OPER_VALUES}
END
Lists Should Be Equal ${ACTUAL_COMP_OPER} ${EXPECTED_COMP_OPERATOR}