DDDriverRestCommands

Last Updated:

REST Driver Commands for handling Response like store, delete etc.

This keyword library provides Driver Commands that can be used by all three DDE Drivers--CycleDriver, SuiteDriver, and StepDriver. That means they can be used in any keyword driven test tables regardless of the test tables level--Cycle, Suite, or Step.

Each different driver command has different parameters as described in its documentation. For reference, the first fields of ALL Driver Command test records are defined below:

Field #1
The "C" = DRIVER COMMAND record type specifier.
Field #2
The Driver Command keyword.

Example:

C, RestStoreResponse, responseId, varnamePrefix

Driver Command parameters must be placed in the test record in the field position specified in the documentation. Some parameters are optional. However, the field associated with that parameter must be honored. If you wish to skip an optional parameter you must still provide an empty field for that parameter.

Example:

C, LaunchApplication, NOTEPAD, NOTEPAD.EXE, , , "AppMap.map"

The above example shows two optional fields after NOTEPAD.EXE which are given no value(skipped).



[How To Read This Reference]
RestCleanResponseMap
TID
Delete REST response (and request if it is stored) from the internal Map.
RestDeleteResponse
TID
Delete a REST response (and request if stored) from the persistent storages.
RestDeleteResponseStore
TID
Delete ALL REST responses (and requests if stored) from the persistent storages.
RestHeadersLoad
TID
Load headers from a file.
RestStoreResponse
TID
Save a REST response into a persistent storage.
RestVerifyResponse
TID
Verify a REST response is what is expected.
RestVerifyResponseContains
TID
Verify a REST response contains what is expected.

DDDriverRestCommands::RestCleanResponseMap
TID

Delete REST response (and request if it is stored) from the internal Map.

Delete a REST response (and request if it is stored) from the internal Map. The REST response/request is stored internally in a Map of pair (responsID, Response). BE CAREFUL WHNE CALLING THIS KEYWORD! It will clean Response from internal Map, and can cause other keyword failing to work.

Fields: [ ]=Optional with Default Value
  1. [ responseID = ]
    The ID used to delete Response Object from internal Map.

    Every single Request generates a new Response, which will be stored in a map internally. This responseID is the key to get that Response Object from that map. This responseID should be generated by SAFS after executing a REST request, such as GET, POST, DELETE, PUT etc.

Examples:
[How To Read This Reference]

DDDriverRestCommands::RestDeleteResponse
TID

Delete a REST response (and request if stored) from the persistent storages.

Delete a REST response (and request if stored) from the persistent storages. The REST response/request is supposed to be in the persistent storages. The response/request can be in more than one type of persistence storage, and it can be a series of variables, a file or something else, please refer to explanation of parameters of keyword RestStoreResponse. For example, if the Response/Request is stored be in a XML file, a JSON file and "a series of variables" at the same time, then this keyword will delete all of them (XML file, JSON file and variables).

Fields: [ ]=Optional with Default Value
  1. responseID
    The ID of the Response/Request (stored in persistence storages) to be deleted.

    The Response/Request can stored be in more than one type of persistence storage; For example, it can be in a XML file, a JSON file and "a series of variables" at the same time. This keyword will delete all of them.
    Please refer to keyword RestStoreResponse if you want to know exactly what type of persistence storage can be used to save a REST response/request.



Examples:
[How To Read This Reference]

DDDriverRestCommands::RestDeleteResponseStore
TID

Delete ALL REST responses (and requests if stored) from the persistent storages.

Delete ALL REST responses (and requests if stored) from the persistent storages. The REST response/request is supposed to be in the persistent storages. The response/request can be in more than one type of persistence storage, and it can be a series of variables, a file or something else, please refer to explanation of parameters of keyword RestStoreResponse. For example, if there are 2 Responses/Requests have been persisted, one is stored be in a XML file, a JSON file and "a series of variables" at the same time, the other is stored in JSON file and "a series of variables", then this keyword will delete all of them (XML file, JSON file and variables of the first Response/Request, JSON file and "a series of variables" of the second Response/Request).

Fields: [ ]=Optional with Default Value
    Examples:
    [How To Read This Reference]

    DDDriverRestCommands::RestHeadersLoad
    TID

    Load headers from a file.

    This might be called before invoking a REST action, like RESTGetXML etc. And the loaded headers will be used when executing that REST action if no headers are provided as parameter of that REST action.

    Fields: [ ]=Optional with Default Value
    1. headersFile
      The path to file holding headers information.

      The content is to be decided. JSON=single/multi-line header
      XML=single/multi-line header


    2. [ method = ]
      The method is used to load the "headers" from a file.
      If this parameter is not provided, then "headers" of all methods will be loaded.

      The possible methods are listed below:
      • DELETE
      • GET
      • HEAD
      • PATCH
      • POST
      • PUT


    3. [ type = ]
      The type is used to load the "headers" from a file.
      If this parameter is not provided, then "headers" of all types will be loaded.

      The possible types are listed below:
      • BINARY
      • CSS
      • CUSTOM
      • HTML
      • JSON
      • IMAGE
      • SCRIPT
      • TEXT
      • XML


    Examples:
    [How To Read This Reference]

    DDDriverRestCommands::RestStoreResponse
    TID

    Save a REST response into a persistent storage.

    Retrieve a REST response according to the responseID, and store the response into a persistent storage. The persistent storage can be a series of variables, a file or something else, please refer to explanation of parameters.

    Fields: [ ]=Optional with Default Value
    1. responseID
      The ID used to retrieve Response Object from internal Map.

      Every single Request generates a new Response, which will be stored in a map internally. This responseID is the key to get that Response Object from that map. This responseID should be generated by SAFS after executing a REST request, such as GET, POST, DELETE, PUT etc.

    2. variablePrefix
      The prefix of the variables to store the information of a REST response/request if parameter persistenceType is VARIABLE.
      Or the file name holding the information of a REST response/request if parameter persistenceType is FILE.

      If this parameter means a 'variable prefix'.
      The variablePrefix is used to deduce variables to store a REST response. Deduced variables are listed as below:

      • variablePrefix.Response.Id
      • variablePrefix.Response.StatusCode
      • variablePrefix.Response.HttpVersion
      • variablePrefix.Response.ContentType
      • variablePrefix.Response.EntityBody
      • variablePrefix.Response.EntityLength
      • variablePrefix.Response.Headers
      • to be added ...
      If the parameter storeRequest is true, then the originating REST Request will also be stored in the deduced variables listed as below:
      • variablePrefix.Request.Method
      • variablePrefix.Request.URI
      • variablePrefix.Request.HttpVersion
      • variablePrefix.Request.Headers
      • variablePrefix.Request.MessageBody
      • to be added ...

      If this parameter means a file name, then the information of a REST Response (and Request if the parameter storeRequest is true) will be stored in a file.
      The file could be a property file, a json file, or an XML file, examples as below:
      Please pay attention to the special characters (new-line, double-quote, <?XML etc.) escaped by the escape character shown in read as below.

          a JSON file example
          {
          "Response":{
            "StatusCode": "200",
            "Headers" : "{Date=Tue, 13 Dec 2016 03:32:13 GMT, Content-Length=4574, Content-Type=application/xml}",
            "EntityBody" : "<?xml version=\"1.0\"?><CUSTOMERList xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n    <CUSTOMER xlink:href=\"http://www.thomas-bayer.com/sqlrest/CUSTOMER/0/\">0</CUSTOMER>    \n</CUSTOMERList>",
            "Request": {
               "Method": "GET",
               "Headers": "{Date=Tue, 06 Dec 2016 03:08:12 GMT, Content-Length=4574}"
            }
           }
          }
          
          an XML file example:
          <Response>
            <StatusCode>200</StatusCode>
            <Headers>{Date=Tue, 13 Dec 2016 03:29:27 GMT, Content-Length=4574, Connection=keep-alive, Content-Type=application/xml}</Headers>
            <EntityBody><![CDATA[<?xml version="1.0"?><CUSTOMERList xmlns:xlink="http://www.w3.org/1999/xlink">
              <CUSTOMER xlink:href="http://www.thomas-bayer.com/sqlrest/CUSTOMER/0/">0</CUSTOMER>
              <CUSTOMER xlink:href="http://www.thomas-bayer.com/sqlrest/CUSTOMER/49/">49</CUSTOMER>
              </CUSTOMERList>]]></EntityBody>
            <Request>
              <Method>GET</Method>
              <Headers>
                Content-Type:application/octet-stream, Accept:application/octet-stream
              </Headers>
            </Request>
          </Response>
          
          a Properties file example:
          Response.ContentType : application/xml
          Response.EntityBody : <?xml version="1.0"?><CUSTOMERList xmlns:xlink="http://www.w3.org/1999/xlink">\
      \n <CUSTOMER xlink:href="http://www.thomas-bayer.com/sqlrest/CUSTOMER/0/">0</CUSTOMER>\
      \n <CUSTOMER xlink:href="http://www.thomas-bayer.com/sqlrest/CUSTOMER/1/">1</CUSTOMER>\
      \n </CUSTOMERList> Response.EntityLength : 0 Response.Headers : {Date=Mon, 12 Dec 2016 05:17:19 GMT, Content-Length=4762, Via=1.1 inetgw38 (squid), Connection=keep-alive, Content-Type=application/xml, X-Cache=MISS from inetgw38, Server=Apache-Coyote/1.1} Response.Request.Headers : Content-Type:application/octet-stream Accept:application/octet-stream



    3. [ storeRequest = False ]
      Store the originating Request information if this parameter is true. The default value is false.


    4. [ persistenceType = VARIABLE ]
      The type of the persistence storage to save the Response/Request information.

      The valid parameter values are listed below:
      • FILE
      • VARIABLE


    5. [ fileType = JSON ]
      The Type of file to save Response/Request, ONLY useful when persistenceType is "FILE"

      The valid parameter values are listed below:
      • JSON
      • PROPERTIES
      • XML


    Examples:
    [How To Read This Reference]

    DDDriverRestCommands::RestVerifyResponse
    TID

    Verify a REST response is what is expected.

    Retrieve a REST response according to the responseID, and compare the response with the content stored in a bench file.
    The comparison should be defined by parameter verifyRequest, valueContains and valueCaseSensitive.


    Fields: [ ]=Optional with Default Value
    1. responseID
      The ID used to retrieve Response Object from internal Map.

      Every single Request generates a new Response, which will be stored in a map internally. This responseID is the key to get that Response Object from that map. This responseID should be generated by SAFS after executing a REST request, such as GET, POST, DELETE, PUT etc.

    2. benchFile
      The bench file for verifying a REST response.

      The bench file can be a property file, a json file, or an XML file. Examples listed as below:
      Please pay attention to the special characters (new-line, double-quote, <?XML etc.) escaped by the escape character shown in read as below.
          a JSON file example
          {
          "Response":{
            "StatusCode": "200",
            "Headers" : "{Date=Tue, 13 Dec 2016 03:32:13 GMT, Content-Length=4574, Content-Type=application/xml}",
            "EntityBody" : "<?xml version=\"1.0\"?><CUSTOMERList xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n    <CUSTOMER xlink:href=\"http://www.thomas-bayer.com/sqlrest/CUSTOMER/0/\">0</CUSTOMER>    \n</CUSTOMERList>",
            "Request": {
               "Method": "GET",
               "Headers": "{Date=Tue, 06 Dec 2016 03:08:12 GMT, Content-Length=4574}"
            }
           }
          }
          
          an XML file example:
          <Response>
            <StatusCode>200</StatusCode>
            <Headers>{Date=Tue, 13 Dec 2016 03:29:27 GMT, Content-Length=4574, Connection=keep-alive, Content-Type=application/xml}</Headers>
            <EntityBody><![CDATA[<?xml version="1.0"?><CUSTOMERList xmlns:xlink="http://www.w3.org/1999/xlink">
              <CUSTOMER xlink:href="http://www.thomas-bayer.com/sqlrest/CUSTOMER/0/">0</CUSTOMER>
              <CUSTOMER xlink:href="http://www.thomas-bayer.com/sqlrest/CUSTOMER/49/">49</CUSTOMER>
              </CUSTOMERList>]]></EntityBody>
            <Request>
              <Method>GET</Method>
              <Headers>
                Content-Type:application/octet-stream, Accept:application/octet-stream
              </Headers>
            </Request>
          </Response>
          
          a Properties file example:
          Response.ContentType : application/xml
          Response.EntityBody : <?xml version="1.0"?><CUSTOMERList xmlns:xlink="http://www.w3.org/1999/xlink">\
      \n <CUSTOMER xlink:href="http://www.thomas-bayer.com/sqlrest/CUSTOMER/0/">0</CUSTOMER>\
      \n <CUSTOMER xlink:href="http://www.thomas-bayer.com/sqlrest/CUSTOMER/1/">1</CUSTOMER>\
      \n </CUSTOMERList> Response.EntityLength : 0 Response.Headers : {Date=Mon, 12 Dec 2016 05:17:19 GMT, Content-Length=4762, Via=1.1 inetgw38 (squid), Connection=keep-alive, Content-Type=application/xml, X-Cache=MISS from inetgw38, Server=Apache-Coyote/1.1} Response.Request.Headers : Content-Type:application/octet-stream Accept:application/octet-stream


    3. [ fileType = JSON ]
      The Type of file to save Response/Request, ONLY useful when persistenceType is "FILE"

      The valid parameter values are listed below:
      • JSON
      • PROPERTIES
      • XML


    4. [ result = <responseID>.verification.result ]
      The variable holding the verification result.

      If this parameter is not provided, then the 'verification result' will be automatically saved to a deduced variable "<responseID>.verification.result".

    5. [ verifyRequest = FALSE ]
      If it is true, then verify also the Request; otherwise only the Response will be verified. The default value is 'false', which means only the Response will be verified.


    6. [ valueContains = FALSE ]
      If true, then verify that Response/Request field's value contains that in benchFile;
      Otherwise, then verify that Response/Request field's value matches wholly with that in benchFile;
      The default value is false;


    7. [ valueCaseSensitive = TRUE ]
      If true, then verify that Response/Request field's value matches case sensitively with that in benchFile;
      Otherwise, then verify that Response/Request field's value matches case insensitively with that in benchFile;
      The default value is true;


    Examples:
    [How To Read This Reference]

    DDDriverRestCommands::RestVerifyResponseContains
    TID

    Verify a REST response contains what is expected.

    Retrieve a REST response according to the responseID, and verify that the response contains the content stored in a bench file.
    The Contains in keyword RestVerifyResponseContains means the Response/Request contains the fields defined in the bench file, that is to say not all fields of Response/Request should be matched
    For the field's value, it should be defined by parameter valueContains and valueCaseSensitive.


    Fields: [ ]=Optional with Default Value
    1. responseID
      The ID used to retrieve Response Object from internal Map.

      Every single Request generates a new Response, which will be stored in a map internally. This responseID is the key to get that Response Object from that map. This responseID should be generated by SAFS after executing a REST request, such as GET, POST, DELETE, PUT etc.

    2. benchFile
      The bench file for verifying a REST response.

      The bench file can be a property file, a json file, or an XML file. Examples listed as below:
      Please pay attention to the special characters (new-line, double-quote, <?XML etc.) escaped by the escape character shown in read as below.
          a JSON file example
          {
          "Response":{
            "StatusCode": "200",
            "Headers" : "{Date=Tue, 13 Dec 2016 03:32:13 GMT, Content-Length=4574, Content-Type=application/xml}",
            "EntityBody" : "<?xml version=\"1.0\"?><CUSTOMERList xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n    <CUSTOMER xlink:href=\"http://www.thomas-bayer.com/sqlrest/CUSTOMER/0/\">0</CUSTOMER>    \n</CUSTOMERList>",
            "Request": {
               "Method": "GET",
               "Headers": "{Date=Tue, 06 Dec 2016 03:08:12 GMT, Content-Length=4574}"
            }
           }
          }
          
          an XML file example:
          <Response>
            <StatusCode>200</StatusCode>
            <Headers>{Date=Tue, 13 Dec 2016 03:29:27 GMT, Content-Length=4574, Connection=keep-alive, Content-Type=application/xml}</Headers>
            <EntityBody><![CDATA[<?xml version="1.0"?><CUSTOMERList xmlns:xlink="http://www.w3.org/1999/xlink">
              <CUSTOMER xlink:href="http://www.thomas-bayer.com/sqlrest/CUSTOMER/0/">0</CUSTOMER>
              <CUSTOMER xlink:href="http://www.thomas-bayer.com/sqlrest/CUSTOMER/49/">49</CUSTOMER>
              </CUSTOMERList>]]></EntityBody>
            <Request>
              <Method>GET</Method>
              <Headers>
                Content-Type:application/octet-stream, Accept:application/octet-stream
              </Headers>
            </Request>
          </Response>
          
          a Properties file example:
          Response.ContentType : application/xml
          Response.EntityBody : <?xml version="1.0"?><CUSTOMERList xmlns:xlink="http://www.w3.org/1999/xlink">\
      \n <CUSTOMER xlink:href="http://www.thomas-bayer.com/sqlrest/CUSTOMER/0/">0</CUSTOMER>\
      \n <CUSTOMER xlink:href="http://www.thomas-bayer.com/sqlrest/CUSTOMER/1/">1</CUSTOMER>\
      \n </CUSTOMERList> Response.EntityLength : 0 Response.Headers : {Date=Mon, 12 Dec 2016 05:17:19 GMT, Content-Length=4762, Via=1.1 inetgw38 (squid), Connection=keep-alive, Content-Type=application/xml, X-Cache=MISS from inetgw38, Server=Apache-Coyote/1.1} Response.Request.Headers : Content-Type:application/octet-stream Accept:application/octet-stream


    3. [ fileType = JSON ]
      The Type of file to save Response/Request, ONLY useful when persistenceType is "FILE"

      The valid parameter values are listed below:
      • JSON
      • PROPERTIES
      • XML


    4. [ result = <responseID>.verification.result ]
      The variable holding the verification result.

      If this parameter is not provided, then the 'verification result' will be automatically saved to a deduced variable "<responseID>.verification.result".

    5. [ verifyRequest = FALSE ]
      If it is true, then verify also the Request; otherwise only the Response will be verified. The default value is 'false', which means only the Response will be verified.


    6. [ valueContains = FALSE ]
      If true, then verify that Response/Request field's value contains that in benchFile;
      Otherwise, then verify that Response/Request field's value matches wholly with that in benchFile;
      The default value is false;


    7. [ valueCaseSensitive = TRUE ]
      If true, then verify that Response/Request field's value matches case sensitively with that in benchFile;
      Otherwise, then verify that Response/Request field's value matches case insensitively with that in benchFile;
      The default value is true;


    Examples:
    [How To Read This Reference]