'Iterate on JSON Array using Robotframework
Created a functionality(Thanks to NILS) wherein it dynamically fetch and count objects MOTOR and BIKELIST and get its bike type
${json}= Evaluate json.loads('''${response.text}''') json
FOR ${ob_list} IN @{json['bikesToAdd']['bikeList']}
Log remarkType: ${ob_list["bikeType"]} console=True
Should Contain remarkType: ${ob_list["bikeType"]} Mountain Bike
END
My end goal is get the BIKE LIST, BIKE TYPE and its Corresponding WHEELCOMMENT. If i have 2 diffrent bike type the out put should be
- BikeList, Mountain Bike, The nut cracker
- Bikelist, Road, Test 1
however I'm encountering Keywords error and failed Key error on fetching wheel comment.
{
"bikesToAdd": {
"bikeList": [
{
"bikeId": null,
"bikeType": Mountain Bike,
"bikeCommentList": [
{
"wheelComment": “The Nut Cracker”,
"handlingComment": null,
}
]
},{
"bikeId": null,
"bikeType": Road,
"bikeCommentList": [
{
"wheelComment": null,
"handlingComment": null,
}
]
},
],"motorList": [
{
"motorListId": null,
"motorListType": null,
"motorList": [
{
"wheelComment": “The White Cho”,
"handlingComment": null,
}
]
},{
"motorListId": null,
"motorListType": null,
"motorList": [
{
"wheelComment": “The quick brown fox”,
"handlingComment": null,
}
]
},
]
}
failed: SyntaxError: invalid syntax (, line 1) (FOR LOOP ISSUE)
was injecting counter variable next to the ['bikelist'][${counte_var}] json query and it keeps prompting an error
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
