GenericKeywords.robot 2.38 KB
Newer Older
1
2
*** Settings ***
Library    JSONSchemaLibrary    schemas/
3
Library    BuiltIn
4
Library    OperatingSystem
5
6
7

*** Variables ***
${response}
8
9


10
*** Keywords ***
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Check HTTP Response Status Code Is
    [Arguments]    ${expected_status}
    ${status}=    Convert To Integer    ${expected_status}
    Should Be Equal    ${response['status']}    ${status}
    Log    Status code validated

Check HTTP Response Body Json Schema Is
    [Arguments]    ${input}
    Should Contain    ${response['headers']['Content-Type']}    application/json
    ${schema} =    Catenate    SEPARATOR=    ${input}    .schema.json
    Validate Json    ${schema}    ${response['body']}
    Log    Json Schema Validation OK

Should Be Present In Json List
    [Arguments]     ${expr}   ${json_field}   ${json_value}
Elian Kraja's avatar
Elian Kraja committed
26
    Log    Check if ${json_field} is present in ${expr} with the value ${json_value}
27
    :FOR  ${item}  IN  @{expr}
Michele Carignani's avatar
Michele Carignani committed
28
29
    \  ${are_equal}=    Should Be Equal As Strings    ${item["${json_field}"]}    ${json_value}
    \  Exit For Loop If    ${are_equal}
30
31
    Log    Item found ${item}
    [return]    ${item}
Elian Kraja's avatar
Elian Kraja committed
32
33
34
35
    
Should Be Present In Json
    [Arguments]     ${expr}   ${json_field}   ${json_value}
    Log    Check if ${json_field} is present in ${expr} with the value ${json_value}
36
    Should Be Equal As Strings    ${expr}[${json_field}]    ${json_value}
37

Elian Kraja's avatar
Elian Kraja committed
38
39
40
41
Check Response Contains
    [Arguments]    ${source}    ${parameter}    ${value}
    Should Be Present In Json    ${source}    ${parameter}    ${value}
    
Yann Garcia's avatar
Yann Garcia committed
42
Check Result Contains
43
    [Arguments]    ${source}    ${parameter}    ${value}
Yann Garcia's avatar
Yann Garcia committed
44
    Should Be Present In Json List    ${source}    ${parameter}    ${value}
45
46
47
48
49
50

Check ProblemDetails
    [Arguments]    ${expected_status}
    ${status}=    Convert To Integer    ${expected_status}
    Should Be Equal    ${response['body']['problemDetails']['status']}    ${status}
    Log    ProblemDetails Status code validated
Elian Kraja's avatar
Elian Kraja committed
51
52
53
54
55
56
57
58
    
Check HTTP Response Header Contains
    [Arguments]    ${HEADER_TOCHECK}
    Should Contain     ${response['headers']}    ${HEADER_TOCHECK}
    Log    Header is present

Check HTTP Response Body is Empty
    Should Be Empty    ${response['body']}   
59
60
61
62
63
64
    Log    Body is empty
    
Check HTTP Response Contain Header with value
    [Arguments]    ${HEADER_TOCHECK}    ${VALUE}
    Check HTTP Response Header Contains    ${HEADER_TOCHECK}
    Should Be Equal As Strings    ${value}    ${response['headers']['Content-Type']}    
65
66