|
1 | 1 | *** Settings *** |
2 | | -Library JSONLibrary |
| 2 | +Library JSONLibrary |
| 3 | +Library Collections |
| 4 | +Library String |
| 5 | +Test Setup SetUp Test |
3 | 6 | Default Tags JSONLibrary |
4 | 7 |
|
| 8 | +*** Keywords *** |
| 9 | +SetUp Test |
| 10 | + ${json_obj}= Load JSON From File ${CURDIR}${/}..${/}tests${/}json${/}example.json |
| 11 | + Set Test Variable ${json_obj} ${json_obj} |
| 12 | + |
5 | 13 | *** Test Cases *** |
6 | | -Addition |
7 | | - [Documentation] Test Addition Success |
8 | | - ${result}= Add Numbers ${-10} ${20} ${50} |
9 | | - Should Be Equal As Integers ${result} ${60} |
| 14 | +TestAddJSONObjectByJSONPath |
| 15 | + [Documentation] Adding some json object using JSONPath |
| 16 | + ${object_to_add}= Create Dictionary latitude=13.1234 longitude=130.1234 |
| 17 | + ${json_obj}= Add Object To Json ${json_obj} $..address ${object_to_add} |
| 18 | + Dictionary Should Contain Sub Dictionary ${json_obj['address']} ${object_to_add} |
| 19 | + |
| 20 | +TestGetValueByJSONPath |
| 21 | + [Documentation] Get some json object using JSONPath |
| 22 | + ${values}= Get Value From Json ${json_obj} $..address.postalCode |
| 23 | + Should Be Equal As Strings ${values[0]} 630-0192 |
10 | 24 |
|
11 | | -Subtraction |
12 | | - [Documentation] Test Subtraction Success |
13 | | - ${result}= Subtract Numbers ${44} ${21} |
14 | | - Should Be Equal As Integers ${result} ${23} |
| 25 | +TestUpdateValueByJSONPath |
| 26 | + [Documentation] Update value to json object using JSONPath |
| 27 | + ${json_obj}= Update Value To Json ${json_obj} $..address.city Bangkok |
| 28 | + ${updated_city}= Get Value From Json ${json_obj} $..address.city |
| 29 | + Should Be Equal As Strings ${updated_city[0]} Bangkok |
15 | 30 |
|
16 | | -Multiplication |
17 | | - [Documentation] Test Multiplication Success |
18 | | - ${result}= Multiply Numbers ${11} ${11} |
19 | | - Should Be Equal As Integers ${result} ${121} |
| 31 | +TestDeleteObjectByJSONPath |
| 32 | + [Documentation] Delete object from json object using JSONPath |
| 33 | + ${json_obj}= Delete Object From Json ${json_obj} $..isMarried |
| 34 | + Dictionary Should Not Contain Key ${json_obj} isMarried |
20 | 35 |
|
21 | | -Division |
22 | | - [Documentation] Test Division Success |
23 | | - ${result}= Divide Numbers ${121} ${11} |
24 | | - Should Be Equal As Integers ${result} ${11} |
| 36 | +TestConvertJSONToString |
| 37 | + [Documentation] Convert JSON To String |
| 38 | + ${json_str}= Convert JSON To String ${json_obj} |
| 39 | + Should Be String ${json_str} |
25 | 40 |
|
26 | | -Modulo |
27 | | - [Documentation] Test Modulo Success |
28 | | - ${remainder}= Mod Numbers ${121} ${21} |
29 | | - Should Be Equal As Integers ${remainder} ${16} |
|
0 commit comments