Integrating Postman Collections in Functionize Tests

Overview

Functionize allows you to execute Postman API collections directly within a test case. This enables workflows where you can perform an API action, such as creating a deal, and then capture a value from the API response, like a deal number. This captured value can then be stored in a variable and used in subsequent UI-based steps, for example, to search for and verify the newly created deal in the application's user interface.

How It Works

The process involves three main stages: executing the collection, capturing the desired data from the response, and using that data in your test.

  1. Execute the Postman Collection

    Use the Extension: Postman Collection action to run your API requests.

    • In your test, add the Extension > Postman Collection action at the desired step.
    • In the action settings, upload or paste your Postman Collection JSON.
    • If your collection uses environment variables, upload the corresponding Postman Environment JSON file.
    • Set the Processing Type to Synchronous. This is critical as it forces the test to wait for the API execution to complete before proceeding to the next step, ensuring the response data is available.
  2. Capture Data from the API Response

    The API response from the Postman extension is returned as a binary stream and must be converted to a usable JSON format. A Custom Code action is the recommended way to handle this conversion.

    Using a Custom Code Action

    For reliable processing, a Custom Code action provides the necessary control. Add this action immediately after the Postman step and use the following JavaScript to parse the response:

    /* Replace 'ActionId' with the ID of your Postman extension step */
    var postmanResponse = fze.action('ActionId').extensionResponse;
    
    // Get the stream data from the first execution in the response
    var streamData = postmanResponse.run.executions[0].response.stream.data;
    
    // Convert the array of integers into a JSON string
    var jsonString = String.fromCharCode.apply(null, streamData);
    
    // Parse the JSON string into a JavaScript object
    var jsonObject = JSON.parse(jsonString);
    
    // Save the desired value to a local variable
    // Example: fze.local.dealNumber = jsonObject.deal.id;

    You must replace 'ActionId' with the actual ID of your Postman extension step and adjust the final line to access the correct property from your specific API response.

  3. Use the Variable in UI Steps

    Once the data is saved to a variable (e.g., dealNumber), you can reference it in subsequent UI steps.

    • In an input field, such as a search bar, enter the variable using Functionize's syntax: {{fze.local.dealNumber}}.
    • Proceed with standard UI actions like Click or Verify to interact with and validate the results on the screen.

Limitations

  • Synchronous Execution is Required: The Postman extension step must be configured with Synchronous processing if you intend to use its response in an immediately following step. If set to Asynchronous (Background), the test will not wait for the API call to finish, and the response data will not be available, which can cause errors like Cannot read properties of undefined.
  • Response Format: The response from the Postman extension is a binary stream. It must be explicitly converted into a JSON string and then parsed into a JSON object before you can access its properties, as shown in the Custom Code example.