我正在尝试将响应数据字符串转换为Robot Framework中的字典:
Create Session Get_Inventory_Details ${Base_URL}
${Headers}= Create Dictionary Content-Type=application/json Authorization=bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyTmFtZSI6InByaXRpc3dhaW4iLCJpYXQiOjE1Njc1MTQ2NDd9.o3qTPbj2KH6AgHpIf1BLV5nOlGL-fR83wSGAYyuWsBQ
${Response}= Get Request Get_Inventory_Details inventorybyOutlet/7 headers=${Headers}
Log To Console ${Response.status_code}
Log Many ${Response.content}
${actual_response}= Convert To String ${Response.status_code}
Should Be Equal ${actual_response} 200
${Get_response}= Evaluate json.loads('''${Response.content}''') '${Response.content}'.replace(' ','_')
运行此代码时出错:
ImportError: No module named '[{"isInventoryOperationEnable":1
Screenshot of RobotFramework TestCase Log with Failed Step
如何解决此错误?
当您调用Evaluate时,它期望它的第二个参数是一个或多个python模块的列表。似乎很清楚'${Response.content}'.replace(' ','_')
不会给您有效的模块列表。
json.loads('''${Response.content}''') '${Response.content}'.replace(' ','_')