# API + Single App Test

Testing APIs alongside a single application allows you to validate app behavior in real-time with dynamic API interactions. This approach is ideal for scenarios where an app's functionality relies on data fetched from or sent to APIs. Below, we explore how to integrate API calls within a single app test flow.

### API + App Interaction

The EXECUTE\_API command is used to execute API calls during a test session. You can validate the response from an API and ensure the app behaves as expected based on that data.

#### **Example Use Case: Validating a Weather App**

In this example, a weather app retrieves data from a weather API. We will:

1. Fetch weather data using an API.
2. Verify the app displays the data correctly.

#### **Step-by-Step Workflow:**

**Step 1:** Launch the weather app and navigate to the relevant screen.

| OPEN\_APP:(com.weatherapp) |
| -------------------------- |

**Step 2:** Execute the weather API to fetch live weather data.

| EXECUTE\_API: get\_weather\_api(latitude=12.9716, longitude=77.5946) |
| -------------------------------------------------------------------- |

**Step 3:** Validate the API response to ensure it returns expected data.

| validate that the value of temperature in get\_weather\_api response is not null |
| -------------------------------------------------------------------------------- |

**Step 4:** Compare the API response with the app's UI to ensure consistency.

| validate that the value of temperature in get\_weather\_api response is equal to the value of temperature shown on the screen |
| ----------------------------------------------------------------------------------------------------------------------------- |

### Dynamic API Responses

API responses can be used dynamically to influence subsequent steps in the test flow. By referencing API response fields, you can simulate real-world scenarios more effectively.

**Example Use Case: Validating Location-Based Content**

Suppose you’re testing an e-commerce app that displays location-specific offers.

#### **Step-by-Step Workflow:**

**Step 1:** Execute a GPS API to retrieve the user's current location.

| EXECUTE\_API: get\_gps\_api() |
| ----------------------------- |

**Step 2:** Use the retrieved location to fetch offers using the e-commerce API.

| EXECUTE\_API: get\_offers\_api(latitude={{GET\_GPS\_API.location.latitude}}, longitude={{GET\_GPS\_API.location.longitude}}) |
| ---------------------------------------------------------------------------------------------------------------------------- |

**Step 3:** Validate the app's UI to ensure it displays the offers fetched by the API.

| validate that the value of offers in get\_offers\_api response is equal to the value of offers shown on the screen |
| ------------------------------------------------------------------------------------------------------------------ |

### API-App Sync

Ensuring that the app responds accurately to API data is a critical part of this approach. By validating both the API response and the app’s displayed data, you ensure consistency and reliability.

#### **Command Examples:**

Validate the API response directly:

| Validate that the value of status in create\_user\_api response is equal to "success" |
| ------------------------------------------------------------------------------------- |

Validate app data against the API response:

| Validate that the value of name in create\_user\_api response is equal to the value of name shown on the screen |
| --------------------------------------------------------------------------------------------------------------- |

#### **Benefits of API + Single App Testing:**&#x20;

* Ensures end-to-end functionality by validating data flow between the app and APIs.
* Enables dynamic test scenarios where app behavior depends on real-time API data.
* Provides comprehensive coverage for both app UI and backend data validation.

By integrating API testing with single app workflows, you can create robust and reliable test cases that cover both frontend and backend functionality.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.drizz.dev/different-use-cases-supported-by-drizz/api-+-single-app-test.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
