Add API
Creating and Configuring API Test Steps in FinalRun
Think of a test that first gets a token or ID from an API, then uses that value in a mobile step—or a mobile step that grabs some data and sends it back to the server to check. FinalRun’s Add API step makes this easy: you call an endpoint, check the response, and save a value as a variable for your next mobile action. Or you can take data from your mobile test (like an order ID) and send it to an API to confirm it on the backend. This guide shows you exactly how to add and use the API step in FinalRun.
Overview and Prerequisites
Why Use API Steps?
Setup Test Data: Populate your application state before executing UI interactions.
Verify Backend Logic: Ensure endpoints return expected results before proceeding with front-end validation.
Fetch Dynamic Values: Extract tokens, IDs, or other data to drive subsequent test steps.
Prerequisites:
FinalRun Account & Project: Ensure you have a project with at least one test case created.
Endpoint Details: Know the API URL, supported HTTP methods, required headers, authentication scheme, and sample payloads.
Network Access: Confirm that your machine can reach the target endpoint (e.g., no VPN or firewall blocking).
2. Adding an API Step
Navigate to Test Steps:
Open your test case and scroll to the Test Steps section.
Click on the
Select a step
dropdown.
Choose “Add API”:
From the list of available steps, select
Add API
.The API request builder appears.
Tip: If you frequently add API steps, consider creating a reusable template with common headers (e.g., Authorization) in your settings.
3. Configuring Your API Request
3.1 Select HTTP Method
Available options:
GET
,POST
,PUT
,PATCH
,DELETE
.Example: For a read-only fetch, choose
GET
.
3.2 Enter the Endpoint URL
In the URL field, paste or type the full endpoint (e.g.,
https://jsonplaceholder.typicode.com/todos/1
).
3.3 Add Params, Headers, and Body (Optional)
Params Tab: Add query parameters as key–value pairs.
Authorization Tab: Select an auth type (e.g., Bearer Token, Basic Auth). Enter credentials or tokens.
Headers Tab: Define custom headers (e.g.,
Content-Type: application/json
).Body Tab (for POST/PUT/PATCH): Enter raw JSON, form-data, or other supported payload formats.
Example: To create a new TODO item:
{ "userId": 1, "title": "Buy groceries", "completed": false }
3.4 Sending the Request
Click the
Send
(orHit API
) button located at the bottom-right.Wait for the response; the Response Data pane populates with status, headers, and body.
4. Validating the API Response (Assertions)
Use assertions to verify that the API behaves as expected.
4.1 Status Code Validation
Switch to the
Status
Tab: Shows the HTTP status (e.g., 200 OK).Hover & Click “Validate”: A dialog opens pre-filled with the current status code.
Adjust Comparison Logic (Optional): Change operators (e.g.,
==
,>=
).Click
Create
: The assertion appears under the step summary (e.g., Status == 200).
Best Practice: Always assert that status codes are in the 2xx range for successful requests.
4.2 Header Validation
Switch to the
Headers
Tab: Lists all response headers.Identify Target Header (e.g.,
x-ratelimit-limit
):Hover & Click “Validate”: A dialog pre-fills the header and its value.
Click
Create
: Assertion appears (e.g., x-ratelimit-limit >= 1000).
Note: Header names are case-insensitive. Use exact keys from the response.
4.3 Body Validation with AI JSONPath Helper
Go to the
Body
Tab: Displays the raw JSON response.Click “Validate” Next to JSON View: Opens the validation dialog.
Select “Use AI” Button: An input box appears.
Type a Natural-Language Query (e.g.,
extract completed
): AI generates a JSONPath expression (e.g.,$.completed
).Verify & Adjust “Expected Value” Field: AI populates this based on current response (e.g.,
false
).Click
Create
: Assertion is saved under the step (e.g., $.completed == false).
Pro Tip: Use AI for complex nested fields (e.g.,
extract user’s company name
) to avoid manual JSONPath errors.
5. Extracting Data into Variables
Saving parts of the response to variables makes your tests dynamic.
5.1 Extract Status Code
Switch to the
Status
Tab:Hover & Click “Extract Value”: Opens extraction dialog.
Name Your Variable (e.g.,
statusCode
):Click
Extract
: The status code is stored in{{statusCode}}
for later use.
Usage: In a subsequent HTTP request, you could reference
{{statusCode}}
to assert dependencies.
5.2 Extract from Body with AI
Go to the
Body
Tab:Click “Extract Value” Next to JSON View: Opens extraction dialog.
Click “Use AI”: Type a plain-English extraction request (e.g.,
extract title
).AI Suggests JSONPath (
$.title
): Review and confirm the path.Enter Variable Name (e.g.,
todoTitle
):Click
Extract
: Value from$.title
is saved in{{todoTitle}}
.
Example: If the response is:
{ "userId": 1, "id": 1, "title": "Buy groceries", "completed": false }
extracting
title
stores "Buy groceries" in{{todoTitle}}
.
6. Example Walkthrough: Creating & Validating a TODO
Add API Step → Select
GET https://jsonplaceholder.typicode.com/todos/1
.Send Request → Observe
200 OK
, response body displays TODO fields.Validate Status → Assert
Status == 200
.Validate Body Field → Use AI helper: “
extract completed
” → Assert$.completed == false
.Extract Values → Extract
id
intotodoId
, extracttitle
intotodoTitle
.Save Step → Step summary shows two assertions (
Status == 200
,$.completed == false
) and two extractions ({{todoId}}
,{{todoTitle}}
).
Screenshot Placeholder:
API Request Builder showing URL, method.
Response Pane with status, headers, body.
Validations & Extractions UI highlighting AI JSONPath helper.
7. Best Practices & Troubleshooting
Consistent Variable Naming: Use descriptive, camelCase names (e.g.,
userId
,authToken
).Chain API Steps Carefully: If one API depends on data from another, ensure extraction is done before referencing the variable.
Validate Critical Fields First: Always assert status code before deeper validations to catch errors early.
Use AI Helper Sparingly: For very simple fields, manual JSONPath (
$.fieldName
) may be faster.Error Handling: If an API returns an unexpected schema, adjust your JSONPath or API configuration to match the actual response.
Timeouts & Retries: Configure request timeouts and retry logic in project settings if endpoints are unstable.
8. Finalizing and Saving Your Test Case
Review All Assertions & Extractions: Scroll to the bottom of the API step builder; ensure every item is correct.
Click
Create
: Adds the fully configured API step to your test case.Save Test Case: In the top-right, click
Save Changes
to persist your test.Run the Full Test Suite: Verify that API steps integrate seamlessly with UI steps.
9. Summary
This improved documentation offers a structured approach, practical tips, and clear examples for configuring API test steps in FinalRun. By following these guidelines, you can:
Rapidly add and configure API steps.
Assert response correctness with minimal effort.
Extract dynamic values for robust, data-driven testing.
Continue experimenting with different endpoints and complex scenarios to fully leverage FinalRun’s API testing capabilities.
For questions or feedback, reach out to the FinalRun support team or consult the official knowledge base.
Last updated