*** Settings *** Library Telnet Library HttpLibrary.HTTP Library Process Library OperatingSystem *** Variables *** ${project} = ../../proj_templates/LeabraStd.proj *** Keywords *** Status OK No Result [Arguments] ${output} Status OK ${output} Json Value Should Not Exist ${output} /result Status OK Has Result [Arguments] ${output} Status OK ${output} Get Json Value ${output} /result Status OK Match Result [Arguments] ${output} ${expected} Status OK ${output} Json String Should Match ${output} /result ${expected} Status OK Equal Result [Arguments] ${output} ${expected} Status OK ${output} Json Value Should Equal ${output} /result ${expected} Status OK [Arguments] ${output} Should Be Valid Json ${output} ${output2} ${err_msg} = Run Keyword And Ignore Error Get Json Value ${output} /message Json String Should Match ${output} /status OK "Result not OK: ${err_msg}" Json Value Should Not Exist ${output} /message Json Value Should Not Exist ${output} /error Status Error Match [Arguments] ${output} ${error} ${message} Status Error ${output} Json Value Should Equal ${output} /error ${error} Json String Should Match ${output} /message ${message} Status Error [Arguments] ${output} Should Be Valid Json ${output} Json String Should Match ${output} /status ERROR Json Value Should Not Exist ${output} /result Message Should Match [Arguments] ${output} ${expected} ${match} ${message} = ... Should Match Regexp ${output} OK (.*) Should Be Equal ${expected} ${message} # Use 'Json Value Should Equal' for numbers #Json Value Should Match # [Arguments] ${json} ${pointer} ${expected} # ${value} = Get Json Value ${json} ${pointer} # Should Match ${value} ${expected} Json Value Should Not Exist [Arguments] ${json} ${pointer} Run Keyword And Expect Error JsonPointerException* Get Json Value ${json} ${pointer} Json String Should Match [Arguments] ${json} ${pointer} ${expected} ${err_msg}="Json String did not match" ${pass_fail} ${value} = Run Keyword And Ignore Error Get Json String ${json} ${pointer} Run Keyword If "${pass_fail}" == "FAIL" LOG ${err_msg} WARN Run Keyword If "${value}" <> "${expected}" LOG ${err_msg} WARN Should Match ${pass_fail} PASS Should Match ${value} ${expected} Json String Should Be Empty [Arguments] ${json} ${pointer} ${value} = Get Json String ${json} ${pointer} Should Be Empty ${value} Get Json String [Arguments] ${json} ${pointer} ${value} = Get Json Value ${json} ${pointer} ${match} ${output} = ... Should Match Regexp ${value} "(.*)" [return] ${output} Get Column Value by Name [Arguments] ${json} ${row} ${columnname} ${object} Evaluate json.loads('''${json}''') json ${row_num} Convert To Integer ${row} ${num_columns} Evaluate len(${object["result"]["columns"]}) :FOR ${i} IN RANGE ${num_columns} \ ${column} Set Variable ${object["result"]["columns"][${i}]} \ Run Keyword If '${column["name"]}' == '${columnname}' Exit For Loop [return] ${column["values"][${row_num}]} Column Value Should Match [Arguments] ${json} ${row} ${columnname} ${expected} ${value} Get Column Value by Name ${json} ${row} ${columnname} ${value_str} Convert To String ${value} Should Match '${value_str}' '${expected}' Column Float Value Should Match [Arguments] ${json} ${row} ${columnname} ${expected} ${value} Get Column Value by Name ${json} ${row} ${columnname} ${value_str} Convert To String ${value} Should Be Equal As Numbers ${value} ${expected} Print [Arguments] ${text} Run Keyword If ${verbose} Log ${text} WARN Initialize Emergent [Arguments] ${project_arg} ${other_args}="" Set Suite Variable ${project} ${project_arg} Log ${project} WARN ${pid} = Start Process emergent -nogui -server -p ${project} ${other_args} shell=True Set Suite Variable ${pid} Log ${pid} WARN Sleep 8 sec # Could do a loop and use Is Process Running but not a big deal Open Connection 127.0.0.1 port=5360 Shutdown Emergent Close All Connections Sleep 2 sec ${output} = Terminate Process ${pid} kill=true Sleep 5 sec Run Command Wait [Arguments] ${command} ${output} = Run Command ${command} 500ms [Return] ${output} Run Command [Arguments] ${command} ${wait} Print [Sending] ${command} # temporary Write Bare ${command}\n ${output} = Read till non empty "Couldn't get any useful data back from running command ${command}" Print [Received] ${output} # this is temporary just so I can see what's happening [Return] ${output} Run Command Completion [Arguments] ${command} ${wait} Print [Sending] ${command} # temporary Write Bare ${command}\n Sleep 500ms Set Timeout ${wait} ${output} = Read Until } Print [Received] ${output} # this is temporary just so I can see what's happening [Return] ${output} Read till non empty [Arguments] ${err_message} Sleep 100ms ${output} = Read :FOR ${j} IN RANGE 12000 \ ${strlen} = Get Length ${output.strip()} \ Exit For Loop If ${strlen} > 0 \ Run Keyword If ${j} % 300 == 299 Log "Output from telnet was null, when it shouldn't have been" WARN \ Sleep 100ms \ ${output} = Read Should Not Be Empty ${output} ${err_message} [Return] ${output} Run Emergent Program [Arguments] ${program} ${output} = Run Command {"command": "CollectConsoleOutput", "enable": true} 500ms Status OK No Result ${output} ${output} = Run Command {"command": "ClearConsoleOutput"} 500ms Status OK No Result ${output} ${command} = Set Variable {"command": "RunProgramAsync", "program": "${program}"} ${output} = Run Command ${command} 2500ms Status OK No Result ${output} :FOR ${i} IN RANGE 6000 \ ${command} = Set Variable {"command": "GetRunState"} \ Write Bare ${command}\n \ ${output} = Read till non empty Could not read run state while executing program ${program} \ ${runstate} = Get Json Value ${output} /result \ Exit For Loop If ${runstate} <> "2" Print Completed running program in ${i} seconds ${output} = Run Command {"command": "GetConsoleOutput"} 500ms Status OK ${output} ${console} Set Variable "" ${output2} ${console} = Run Keyword And Ignore Error Get Json Value ${output} /result Run Keyword If ${runstate} <> "0" Log ${console} WARN Should Be Equal ${runstate} "0" Print ${console} ${output} = Run Command {"command": "CollectConsoleOutput", "enable": false} 500ms Status OK No Result ${output} ${output} = Run Command {"command": "ClearConsoleOutput"} 500ms Status OK No Result ${output} [Return] ${console} Set Emergent Var [Arguments] ${program} ${var_name} ${value} ${output} = Run Command Wait {"command": "SetVar", "program": "${program}", "var_name": "${var_name}", "var_value": ${value}} Status OK ${output} Set Emergent Member [Arguments] ${path} ${member_name} ${value} ${output} = Run Command Wait {"command": "SetMember", "path": "${path}", "member": "${member_name}", "var_value": ${value}} Status OK ${output} Get Emergent Var [Arguments] ${program} ${var_name} ${output} = Run Command Wait {"command": "GetVar", "program": "${program}", "var_name": "${var_name}"} Status OK ${output} ${value} = Get Json Value ${output} /result [Return] ${value} Prog Var Should Match [Arguments] ${var_name} ${should_match} ${output} = Run Command Wait {"command": "GetVar", "program": ${program_test}, "var_name": "${var_name}"} Status OK ${output} Json String Should Match ${output} /result ${should_match} Prog Var Should Equal [Arguments] ${var_name} ${should_equal} ${output} = Run Command Wait {"command": "GetVar", "program": ${program_test}, "var_name": "${var_name}"} Status OK ${output} Json Value Should Equal ${output} /result ${should_equal} Prog Var Should Be Empty [Arguments] ${var_name} ${output} = Run Command Wait {"command": "GetVar", "program": ${program_test}, "var_name": "${var_name}"} Status OK ${output} Json String Should Be Empty ${output} /result DataTable Set String Cell Value [Arguments] ${table_path} ${row_from} ${col} ${value} ${output} = Run Command Wait {"command": "SetData", "table": ${table_path}, "row_from": ${row_from}, "data": {"columns" : [ { "name": ${col}, "type": "string", "matrix": false, "values": [${value}] } ] } } Status OK ${output} DataTable Cell Value Should Match [Arguments] ${table_path} ${row_from} ${col} ${value} ${output} = Run Command Wait {"command": "GetData", "table": "${table_path}", "row_from": ${row_from}, "column" : "${col}", "rows": 1} Status OK ${output} Json String Should Match ${output} /result/columns/0/values/0 ${value} DataTable Cell Value Should Equal [Arguments] ${table_path} ${row_from} ${col} ${value} ${output} = Run Command Wait {"command": "GetData", "table": "${table_path}", "row_from": ${row_from}, "column" : "${col}", "rows": 1} Status OK ${output} Json Value Should Equal ${output} /result/columns/0/values/0 ${value} DataTable Cell Value Should Be Null [Arguments] ${table_path} ${row_from} ${col} ${output} = Run Command Wait {"command": "GetData", "table": "${table_path}", "row_from": ${row_from}, "column" : "${col}", "rows": 1} Status OK ${output} ${value_str} = Get Json Value ${output} /result/columns/0/values/0 Should Match '${value_str}' 'null' DataTable Cell Value Should Roughly Equal [Arguments] ${table_path} ${row_from} ${col} ${target_value} ${margin} ${err_msg} ${output} = Run Command Wait {"command": "GetData", "table": "${table_path}", "row_from": ${row_from}, "column" : "${col}", "rows": 1} Status OK ${output} ${value} = Get Json Value ${output} /result/columns/0/values/0 Should Be True ${value} > (${target_value} - ${margin}) "${err_msg}: ${value} is not roughly equal to ${target_value}+-${margin}" Should Be True ${value} < (${target_value} + ${margin}) "${err_msg}: ${value} is not roughly equal to ${target_value}+-${margin}" DataTable Cell Value Should Be Less Than [Arguments] ${table_path} ${row_from} ${col} ${value} ${err_msg}="" ${output} = Run Command Wait {"command": "GetData", "table": "${table_path}", "row_from": ${row_from}, "column" : "${col}", "rows": 1} Status OK ${output} ${result} = Get Json Value ${output} /result/columns/0/values/0 Should Be True ${result} < ${value} "${err_msg}: ${col} in row ${row_from} of ${table_path} (${result}) is not less than ${value}" DataTable Cell Matrix Value Should Be Less Than [Arguments] ${table_path} ${row_from} ${col} ${x} ${y} ${value} ${err_msg}="" ${output} = Run Command Wait {"command": "GetData", "table": "${table_path}", "row_from": ${row_from}, "column" : "${col}", "rows": 1} Status OK ${output} ${result} = Get Json Value ${output} /result/columns/0/values/0/${y}/${x} Should Be True ${result} < ${value} "${err_msg}: ${x}/${y} ${col} in row ${row_from} of ${table_path} (${result}) is not less than ${value}" DataTable Cell Value Should Be Greater Than [Arguments] ${table_path} ${row_from} ${col} ${value} ${err_msg}="" ${output} = Run Command Wait {"command": "GetData", "table": "${table_path}", "row_from": ${row_from}, "column" : "${col}", "rows": 1} Status OK ${output} ${result} = Get Json Value ${output} /result/columns/0/values/0 Should Be True ${result} > ${value} "${err_msg}: ${col} in row ${row_from} of ${table_path} (${result}) is not greater than ${value}" DataTable Cell Matrix Value Should Be Greater Than [Arguments] ${table_path} ${row_from} ${col} ${x} ${y} ${value} ${err_msg}="" ${output} = Run Command Wait {"command": "GetData", "table": "${table_path}", "row_from": ${row_from}, "column" : "${col}", "rows": 1} Status OK ${output} ${result} = Get Json Value ${output} /result/columns/0/values/0/${y}/${x} Should Be True ${result} > ${value} "${err_msg}: ${x}/${y} ${col} in row ${row_from} of ${table_path} (${result}) is not greater than ${value}" DataTable Rows Should Be Less Than [Arguments] ${table_path} ${rows} ${err_msg}="" ${output} = Run Command Wait {"command": "GetData", "table": "${table_path}", "row_from": 0} Status OK ${output} ${result} = Get Json Value ${output} /result/columns/0/values ${valarray} = Parse Json ${result} ${num_rows} Get Length ${valarray} Should Be True ${num_rows} < ${rows} "${err_msg}: ${table_path} has ${num_rows} rows which is not less than ${rows}" Restart Emergent [Arguments] ${other_args}="" Log "Resetting emergent" WARN Shutdown Emergent Sleep 5 Initialize Emergent ${project} ${other_args} Sleep 5 ${output} = Read ${output} = Run Command Wait {"command": "GetRunState"} Status OK Match Result ${output} 4 Print "Emergent was reset" Ensure Emergent Free Print "Checking Emergent is free" ${stat1} ${output} = Run Keyword And Ignore Error Run Command Wait {"command": "GetRunState"} ${stat} ${status} = Run Keyword If '${stat1}' == 'PASS' Run Keyword And Ignore Error Get Json String ${output} /status ${stat} ${result} = Run Keyword If '${stat1}' == 'PASS' Run Keyword And Ignore Error Get Json String ${output} /result Return from Keyword If '${status}' == 'OK' and ('${result}' == '4' or '${result}' == '0') Log "Emergent is still busy, restarting server" WARN Restart Emergent # For reference - JSON keywords from HttpLibrary.HTTP # Get Json Value string, pointer, ... # Json Value Should Equal string, pointer, expected # Json Value Should Not Equal string, pointer, expected # Log Json string, (args) # Parse Json string # Set Json Value string, pointer, value # Should Be Valid Json string