Page tree
Skip to end of metadata
Go to start of metadata

Now, with the help of utility methods, you an extract the variables of your test case response. This functionality is helpful in extracting variables 

  1. from any type (JSON/XML or other than JSON/XML) of test case response.
  2. or from response headers
    1. An example use case is performing token based authentication in vREST.

How to use:

  1. First define a utility method in Project Configuration >> Utility Methods section. vREST automatically provides the following first two parameters to this utility method automatically. Use supplied parameters will be automatically appended after these two parameters.
    1. response: Test Case Response in string format. If the API is returning JSON response then the response parameter will be stringified JSON. You may overwrite the response parameter for JSON response using the below line:

      response = JSON.parse(response);
    2. opts: Options object 
      1. opts object is a simple JSON object which contains the following keys
        1.  "headers" and value contains the JSON object of response headers.
        2. "statusCode" and value contains the HTTP response status code.
      2. to extract variables from response headers, use the opts.headers object.
      3. to use status code information, use the opts.statusCode.

    Write your utility method like below:



  2. Use this utility method in variable extractor tab like this.

    Any parameters passed to this utility method will get appended after two parameters (response and opts) in the utility method. In the above figure, value of var1 will be extracted via utility method varExtractUtility. Here value "hello" will be passed to "userDefinedParam1" parameter and "world" will be passed to "userDefinedParam2" parameter of the utility method defined in step 1.


 

  • No labels