fujinhua | a12f3bb | 2017-09-14 16:28:50 +0800 | [diff] [blame] | 1 | #Robot functions that will be shared also with other tests |
Mariusz Wagner | 831baff | 2018-09-14 14:24:02 +0200 | [diff] [blame] | 2 | *** Settings *** |
| 3 | Library OperatingSystem |
Mariusz Wagner | 3958139 | 2018-09-24 11:52:15 +0200 | [diff] [blame] | 4 | Library HttpLibrary.HTTP |
fujinhua | a12f3bb | 2017-09-14 16:28:50 +0800 | [diff] [blame] | 5 | |
| 6 | *** Keywords *** |
| 7 | json_from_file |
| 8 | #Robot function to extract the json object from a file |
| 9 | [Arguments] ${file_path} |
Mariusz Wagner | 831baff | 2018-09-14 14:24:02 +0200 | [diff] [blame] | 10 | ${json_file}= Get File ${file_path} |
fujinhua | a12f3bb | 2017-09-14 16:28:50 +0800 | [diff] [blame] | 11 | ${json_object}= Evaluate json.loads('''${json_file}''') json |
Mariusz Wagner | 831baff | 2018-09-14 14:24:02 +0200 | [diff] [blame] | 12 | [Return] ${json_object} |
fujinhua | a12f3bb | 2017-09-14 16:28:50 +0800 | [diff] [blame] | 13 | |
| 14 | string_from_json |
| 15 | #Robot function to transform the json object to a string |
| 16 | [Arguments] ${json_value} |
| 17 | ${json_string}= Stringify Json ${json_value} |
Mariusz Wagner | 831baff | 2018-09-14 14:24:02 +0200 | [diff] [blame] | 18 | [Return] ${json_string} |
fujinhua | a12f3bb | 2017-09-14 16:28:50 +0800 | [diff] [blame] | 19 | |
| 20 | random_ip |
| 21 | #Robot function to generate a random IP |
| 22 | [Arguments] |
| 23 | ${numbers}= Evaluate random.sample([x for x in range(1, 256)], 4) random |
| 24 | ${generated_ip}= Catenate ${numbers[0]}.${numbers[1]}.${numbers[2]}.${numbers[3]} |
Mariusz Wagner | 831baff | 2018-09-14 14:24:02 +0200 | [diff] [blame] | 25 | [Return] ${generated_ip} |
| 26 | |
| 27 | Get Data From File |
| 28 | [Arguments] ${file} |
| 29 | ${data}= Get File ${file} |
| 30 | [Return] ${data} |