# Functional Assertions

* [Functional API Assertions](#functional-api-assertions)
  * [Assertions on REST & GRAPHQL API](#assertions-on-rest-and-graphql-api)
  * [Assertions on SOAP API](#assertions-on-soap-api)
  * [Multiple Assertion Options](#multiple-assertion-options)
    * [Xpath and Json Assertions](#xpath-and-json-assertions)
    * [Assertion on Body](#assertion-on-body)
  * [Execution of API Assertion](#execution-of-api-assertion)

***

### Functional API Assertions

* Functional assertions in API testing involve validating various aspects of an API's behavior, functionality, and responses to ensure that they meet the expected criteria.
* **Assertions on REST and GRAPHQL API:**

  * [Assertion on Headers (REST)](#a-assertion-on-headers-rest)
  * [JSON Path Assertion (REST)](#b-json-path-assertion-rest)
  * [Assertion on Body (REST)](#c-assertion-on-body-rest)
  * [Schema Validation (REST)](#d-schema-validation-rest)

  ![image](/files/o7q6dr5L3Fy4Iqx76a2o)

#### a. Assertion on Headers (REST):

* Assertions on headers help ensure that your API responses adhere to the specified standards.

  Step-1: Click on **Assertion on Headers**

  Step-2: Click on "Add" to include a header..

  Step-3: Choose desired operation in the dropdown menu and Provide the expected value in the "value" field.

  ![image](/files/rQySFMllnwy3wdy00aGC)

  You can remove headers by clicking on the delete icon.

  ![image](/files/bTX5FLjPH38nKsfupedG)

***

#### b. JSON Path Assertion (REST):

* JSON Path assertion is a technique employed in Qyrus API testing to validate precise values within a JSON response.

  Step-1: Input JSON body in the JSON path extractor and click on extract.

  ![image](/files/PUxHYvzowwJsDXsyPWDI)

  Step-2: Copy the JSON path you want to use and paste it into the designated "path" field. Provide the expected value in the "value" field, and then choose the desired operation from the dropdown menu to **Extract**.

  ![image](/files/JKm6CljyPxInWe5wbz0x)

  You can remove JSON Path Assertion by clicking on the delete icon.

  ![image](/files/SxUEM4ecjHnjcufY9eiy)

***

#### c. Assertion on Body (REST)

* Assertions on the body allow users to ensure that the data returned by the API meets the intended specifications

  Step-1: Select the appropriate assertion **Type** from the dropdown menu.

  Step-2: Enter the **Expected Value** corresponding to the selected assertion type.

  ![image](/files/EcU5AEjjf9l9baM4rfje)

  Assertions on body can be removed by clicking on the delete icon.

  ![image](/files/rSGiNi7eazEoLWMw9OAf)

***

#### d. Schema Validation (REST)

* Schema validation in API testing refers to the process of verifying whether the structure and data of an API response conform to a predefined schema or structure.

  Step-1: To use that, add JSON body in Schema Generator Section.

  ![image](/files/RXpB2p4a5cYWKOjQaWLS)

  * Click on **Generate** button and copy the Schema Response and use it in Schema Validation.

  ![image](/files/7OzHXFnDd9gIa0b1JY6i)

***

### Assertions on SOAP API:

* [Assertion on Headers (SOAP)](#a-assertion-on-headers-soap)
* [XPath Assertion (SOAP)](#b-xpath-assertions-soap)
* [Assertion on Body (SOAP)](#c-assertion-on-body-soap)
* [Schema Validation (SOAP)](#d-schema-validation-soap)

#### a. Assertion on Headers (SOAP):

Step-1: Click on **Assertion on Headers**

Step-2: Add a header.

Step-3: Choose desired operation in the dropdown menu and Provide the expected value in the "value" field.

![image](/files/PKHEjyFKCX80CLy6Ttwy)

***

#### b. XPath Assertions (SOAP):

Step-1: Add XML Body inside XPath extractor and click on extract.

![image](/files/Ojc0HffJW4G4XtlpFXWg)

Step-3: Copy the path you want to use and paste it into the designated "path" field. Provide the expected value in the "value" field, and then choose the desired operation from the dropdown menu to **Extract**.

![image](/files/3SOYg0uXkcXFL15GsLGh)

XPath Assertions can be removed by clicking on the delete icon.

![image](/files/yXLxAKg0Q9XbX5LXo3uR)

***

#### c. Assertion on Body (SOAP)

* Assertions on the body allow users to ensure that the data returned by the API meets the intended specifications

  Step-1: Select the appropriate assertion **Type** from the dropdown menu.

  Step-2: Enter the **Expected Value** corresponding to the selected assertion type.

  ![image](/files/BngvW2o0FWgZEXQQKD8s)

***

#### d. Schema Validation (SOAP)

* Schema validation in API testing involves verifying that the actual responses received from an API match a predefined schema or structure.

Step-1: Copy the response and paste it in Schema Generator Section.

![image](/files/Ia5tUASnqCX84WFcLo3G)

Step 2: Clicks on **Generate** button and copy the Schema Response and use it in Schema Validation.

![image](/files/N1MFxm19c8asCmARRLUH)

Step-3: Save and Run the test script.

***

### Multiple Assertion Options

#### Xpath and Json Assertions

Json and Xpath Path Assertions also performs

* **Contains**: Verifies that a specific value or pattern is present within the JSON response.
* **Does Not Contain**: Ensures that a particular value or pattern is absent in the JSON response.
* **Equals To**: Compares a JSON value with an expected value for exact match.
* **Not Equals To**: Checks if a JSON value is not equal to a specified value.
* **Less Than**: Validates if a numeric JSON value is less than a given value.
* **Greater Than**: Validates if a numeric JSON value is greater than a given value.
* **Not Null**: Verifies that a JSON value exists and is not null.
* **Regular Expression**: Enables validation using regular expressions for complex matching requirements.
* **JavaScript**: Allows you to perform custom validation using JavaScript expressions.

***

#### Assertion on Body

Assertion on Body also performs:

* **Contains**: Verifies that a specific value or pattern is present within the JSON response.
* **Regular Expression**: Enables validation using regular expressions for complex matching requirements.
* **JavaScript**: Allows you to perform custom validation using JavaScript expressions.

***

### Execution of API Assertion

![Execute API assertion](/files/R8LXhmojzs4LczxyA4ju)


---

# 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.qyrus.com/api-testing/functional-testing/functional-assertions.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.
