# API Dependent TestCase

### Overview

In scriptless automation, dependent test cases allow for sequential execution of API calls where the output of one test is a prerequisite for another. This document describes how to configure and utilize dependent test cases in a scriptless automation environment.

### Configuring Dependent Test Cases

Dependent test cases are defined in CSV templates, where one test case is marked as a prerequisite for another. This configuration ensures that tests are executed in a specific order, allowing for the passing of data from one test to the next.

#### Example

Consider two test cases, `POST_Sanity.csv` and `GET_Sanity.csv`, where `GET_Sanity.csv` depends on `POST_Sanity.csv`.

**POST\_Sanity.csv**

This file defines a POST request and stores values for subsequent use:

```ruby
DEPENDANT_TEST_CASE,NONE,
END_POINT,https://api-generator.retool.com/7kbSLy/data,
METHOD,POST,
...
BODY:KEY,Column 1,
BODY:VALUE,PrecisionTestAutomation,
RESPONSE:CODE,201,
RESPONSE:JSON_PATH,NONE,'Column 1',id
RESPONSE:EXPECTED_VALUE,NONE,PrecisionTestAutomation,
RESPONSE:STORE_VALUE,NONE,Name,ID
```

The POST request generates an `ID` and a `Name`, which are stored for later use.

**GET\_Sanity.csv**

This file defines a GET request that relies on data from `POST_Sanity.csv`:

```ruby
DEPENDANT_TEST_CASE,POST,
END_POINT,http://api-generator.retool.com/7kbSLy/data/ApiGlobalVariables:ID,
METHOD,RELAX_GET,
...
RESPONSE:CODE,200,
RESPONSE:JSON_PATH,NONE,id,'Column 1'
RESPONSE:EXPECTED_VALUE,NONE,1,ApiGlobalVariables:Name
RESPONSE:STORE_VALUE,NONE,NONE,NONE
```

The `DEPENDANT_TEST_CASE` field is set to `POST`, indicating that `POST_Sanity.csv` must be executed before this GET request.

### Functionality of Dependent Test Cases

#### Sequential Execution with Independent Reporting

* **Sequential Execution**: Dependent test cases are executed in a specific order. For instance, a POST request may be set as a prerequisite (dependent test case) for a GET request.
* **Independent Reporting**: Despite their sequential execution, each test case is reported separately. This means the results for both the GET and the POST requests will appear independently in the test report, maintaining clarity and distinction between the different test cases.

### Execution Flow

During execution, the automation framework first runs `POST_Sanity.csv`, storing the necessary values (`ID` and `Name`). Then, it executes `GET_Sanity.csv`, utilizing the stored `ID` and `Name`.

#### Execution Results

The output of the execution might look like this:

1. POST request is executed, creating a new entry and storing `ID` and `Name`.
2. GET request is executed, retrieving data based on the `ID` from the POST request.

Below is the execution from IDE

```
----------------------------------INSIDE BEFORE TEST----------------------------------
----------------------------------GET Started----------------------------------
----------------------------------POST Started----------------------------------
Request method:	POST
Request URI:	https://api-generator.retool.com/7kbSLy/data
Proxy:			<none>
Request params:	<none>
Query params:	<none>
Form params:	<none>
Path params:	<none>
Headers:		Accept=*/*
				Content-Type=application/json
Cookies:		<none>
Multiparts:		<none>
Body:
{
    "Column 1": "PrecisionTestAutomation"
}
{
    "Column 1": "PrecisionTestAutomation",
    "id": 60
}
----------------------------------POSTEnded----------------------------------
Request method:	GET
Request URI:	http://api-generator.retool.com/7kbSLy/data/60
Proxy:			<none>
Request params:	<none>
Query params:	<none>
Form params:	<none>
Path params:	<none>
Headers:		Accept=*/*
Cookies:		<none>
Multiparts:		<none>
Body:			<none>
{
    "id": 60,
    "Column 1": "PrecisionTestAutomation"
}
----------------------------------GETEnded----------------------------------
Error while converting image to base64 URL: /Users/amupraba/Desktop/PrecisionTestAutomation/Backend/maven/config/logo.jpg (No such file or directory)
Error while converting image to base64 URL: /Users/amupraba/Desktop/PrecisionTestAutomation/Backend/maven/config/logo.jpg (No such file or directory)
[main] WARN com.slack.api.methods.RequestFormBuilder - The top-level `text` argument is missing in the request payload for a chat.postMessage call - It's a best practice to always provide a `text` argument when posting a message. The `text` is used in places where the content cannot be rendered such as: system push notifications, assistive technology such as screen readers, etc.
[main] WARN com.slack.api.methods.RequestFormBuilder - Additionally, the attachment-level `fallback` argument is missing in the request payload for a chat.postMessage call - To avoid this warning, it is recommended to always provide a top-level `text` argument when posting a message. Alternatively, you can provide an attachment-level `fallback` argument, though this is now considered a legacy field (see https://api.slack.com/reference/messaging/attachments#legacy_fields for more details).

===============================================
Scriptless
Total tests run: 1, Passes: 1, Failures: 0, Skips: 0
===============================================
```

### Skipping Validation in Dependent Test Cases

* **Validation Skip**: When a test case is marked as a dependent (e.g., a POST request being a dependent for a GET request), the validation steps in the dependent test case are skipped. This is because the primary purpose of the dependent test is to set up the pre-requisites for the subsequent test.
* **Exclusion from Report**: As a result of skipping the validation, the validation results of the dependent test case are not included in the final report. The focus is on the successful execution of the dependent test as a setup step rather than its individual validation outcomes.

### Conclusion

The use of dependent test cases in scriptless automation serves as a method to ensure the correct sequence of test execution while maintaining the independence of each test case in terms of reporting. This approach provides a clear and organized structure for executing interdependent API tests, where one test's output is required for the execution of another. Additionally, the mechanism of skipping validation in dependent test cases optimizes the testing process, focusing on the necessary setup actions without cluttering the reports with unnecessary validation details. This feature enhances the efficiency and clarity of comprehensive API testing, especially in complex scenarios involving multiple interdependent endpoints.

### Sample Report

{% file src="/files/OoJZMI7Ltygy3rKb7VRm" %}


---

# 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.precisiontestautomation.in/scriptlessautomation/automation-platforms/scriptlessapi-automation/api-dependent-testcase.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.
