0% found this document useful (0 votes)
13 views

API Testing

The document provides an overview of API testing, explaining different types of servers (Database, Application, Web), deployment methods, and the concepts of static and dynamic applications. It details various HTTP methods such as GET, POST, PUT, and their respective use cases in API testing, along with caching techniques and session management. Additionally, it covers the importance of handling query parameters, response validation, and error management in API requests.

Uploaded by

devendergoude6
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

API Testing

The document provides an overview of API testing, explaining different types of servers (Database, Application, Web), deployment methods, and the concepts of static and dynamic applications. It details various HTTP methods such as GET, POST, PUT, and their respective use cases in API testing, along with caching techniques and session management. Additionally, it covers the importance of handling query parameters, response validation, and error management in API requests.

Uploaded by

devendergoude6
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 26

API Testing

What is Server?

Server is a software which manages all the resources along with which the
process the client request and serve the client request.

Different types of servers are

1. Database Server
2. Application Server
3. Web Server

Database Server: Database Server is used to deals with data.

Example: Oracle, Mysql, SQL, Derby, MangoDB etc.,

Application Server: Application Server is used to execute dynamic application or


real time application. It is used to execute both Web and Enterprise Application.

Example: Apache POI, Jboss, IBM WebSphere, Oracle web logic etc.,

What is dynamic application or real time application?

Ans: An application which performs all three different types of logics such as:

1. Presentation logic
2. Persistence logic
3. Business logic

Example: Facebook, Instagram, Google, Telegram

Web Server: Web server is used to execute only web-applications.

Example: Apache Tomcat, Oracle glassfish etc.,

Deployment: Making all the resources available to the server is known as


“Deployment”.

There are two types of deployment


 Manual Deployment: In this case, all the resources are made available to
the server manually.
 Automated Deployment: In this case, all the resources are made available
to the server automatically with the help of automatic tools Such as: ANT,
MAVEN etc.,

Static Resources: Resources are which are capable of dealing with only static
data [which can’t be changed] are known as “static resources”.

Static Application: An application which contains only static resources in it is


known as “static application”.

Example: Standalone Application [any desktop applications]

Dynamic Resources: Resources which are capable of dealing with only dynamic
data [which can be change] are known as “Dynamic Resources”.

Dynamic Application: An application which contains only dynamic resources in it


is known as “Dynamic Application”.

Example: Any real time application [FB, Insta]

What is Presentation logic?

 Presentation logic is used to present the contents onto an application.


 Technologies involved – HTML, CSS, JavaScript, PHP, JSP etc.,

What is Persistence logic?

 Persist means to store.


 Persistence logic is used to persist[store] the data into the persistence
system [Database].
 Technologies involved – JDBC, SQL, Hibernate etc.,

What is Business logic?

 Business logic performs core functionality i.e., some set of calculation and
validation operation on an application.
 Technologies involved - Servlet, Spring etc.,
Note: A Dynamic application or Real time application is an Integration
[Combination] all the three different types of logic such as Presentation logic,
Persistence logic and Business logic.

What is Session?

Any activity which takes place between the start time and stop time is known as
“Session”.

What is Caching?

 Caching is a technique used to store frequently accessed data in a


temporary storage location called a cache
 so that it can be quickly retrieved without needing to recompute or refetch
it from the original source (e.g., a database, server, or API).
 This improves performance and reduces the load on the underlying
resources by avoiding repeated expensive operations.

Key Concepts of Caching:

Cache Storage: A cache can be stored in various locations, such as memory


(RAM), disk, or even distributed across servers (as in the case of distributed
caches like Redis or Memcached).

Types of Cache:

 Memory Cache: Data is stored in the RAM for fast access.


 Browser Cache: Browsers store resources like images, CSS, and JavaScript
files to avoid downloading them repeatedly from a server.
 Database Cache: Frequently used queries and data can be cached to avoid
repeatedly querying the database.
 Web Server Cache: Stores web page data or fragments of web pages for
faster loading.

Cache Hit vs. Cache Miss:


 Cache Hit: When the requested data is found in the cache, and the system
retrieves it from there, resulting in faster access.
 Cache Miss: When the requested data is not available in the cache,
requiring the system to fetch it from the original source (and possibly store
it in the cache for future use).

Use Cases of Caching:

 Web Browsing: Browsers cache resources to make websites load faster on


subsequent visits.
 API Responses: Frequently requested API responses can be cached to avoid
repetitive computation.
 Databases: Frequently queried data can be cached to reduce database
query times.

Benefits of Caching GET Requests:

 Speed: The client gets the response much faster because the server is
skipped for repeated requests.
 Reduced Load: The server doesn’t have to process the same requests over
and over.
 Efficiency: Network traffic is reduced because fewer requests are sent to
the server.

API Testing Methods


1. GET: Retrieve data from the server.
2. POST: Create new resources on the server.
3. PUT: Update existing resources (or create if not exists).
4. PATCH: Partially update resources.
5. DELETE: Remove resources.
6. HEAD: Retrieve headers from the server.
7. OPTIONS: Find out supported methods on a resource.
8. TRACE: Diagnostic echo of the request.
9. CONNECT: Establish a tunnel to the server (rare in REST API testing).

GET Request
What is GET Request?

 GET is used when you want to fetch or retrieve data from a server. This
could be any kind of data,
 such as:
o Information about a resource (e.g., users, products, posts).
o Data reports or analytics.
o Metadata about a system or service.
 GET requests do not alter data on the server. This is ideal for scenarios
where you only need to read or view information, not create, update, or
delete.
 Many APIs and web servers cache GET requests, making them faster. This is
because the same request will typically return the same data without
needing to interact with the server again.
 GET requests are stateless. The server does not store information about the
request after the response is returned.

Why to Use a GET Request?

The primary reasons to use a GET request are:

o Data Retrieval,
o Non-Modifying Operation,
o Caching Support,
o Stateless Communication.

How to Use a GET Request?

In Robot Framework, you use the RequestsLibrary to send a GET request.

*** Settings ***

Library RequestsLibrary

*** Variables ***

${BASE_URL} https://jsonplaceholder.typicode.com

*** Test Cases ***

Get Request Example

Create Session my_session ${BASE_URL}

${response}= GET my_session /posts/1

Should Be Equal As Numbers ${response.status_code} 200

Log ${response.json()}

Explanation:

 Create Session: Establishes a connection with the server


(https://jsonplaceholder.typicode.com).
 GET: Retrieves the resource at /posts/1.
 Validation: Checks if the status code is 200, which means success.
 Log: Displays the retrieved data in JSON format.

Sending GET Requests in Python:

import requests

response = requests.get('https://jsonplaceholder.typicode.com/posts/1')
if response.status_code == 200:

print(response.json()) # Print the JSON data from the response

Where to Use a GET Request?

You should use GET requests whenever you need to retrieve data without altering
the server's state.

Common scenarios include

Fetching Data from an API:

 Use GET to retrieve information such as:


 A list of items (e.g., /products for a list of products).
 A specific item (e.g., /products/123 for details of product 123).

Querying Data:

 GET requests can include parameters to filter or query data, like: /users?
age=25&location=NYC to get users aged 25 in New York City.

Displaying Information on a Web Page:

 In web development, GET requests are used to load pages or data (e.g.,
loading a user’s profile).

Public APIs:

 Many public APIs (like weather, news, or stock market data) provide data
via GET requests.
 Examples: /weather/today to retrieve the current weather.
/stocks/GOOGL to retrieve stock prices for a company.

When to Use a GET Request?

Use a GET request in the following situations:

Reading Data from a Server:


 Whenever you need to view or retrieve data without modifying it. This
includes viewing a product catalog, user profiles, or search results.

Fetching Data Based on Query Parameters:

 When you need to filter or search for specific data (e.g., search for items by
category, date, or any specific attribute).

Accessing Public Data:

 When you need to access data that is publicly available (e.g., fetching
weather data or news feeds).

Testing Data Retrieval in APIs:

 When you're testing APIs, you can use GET requests to validate that data is
being retrieved correctly.

 What is a GET request in the context of HTTP and REST APIs?


A GET request is used to retrieve data from a specified resource on a server. It
is a safe and idempotent operation, meaning it doesn't modify any server data
and can be repeated without changing the outcome.

 Can you explain the difference between GET and POST requests?
1. GET requests retrieve data without modifying it, while POST requests
send data to the server to create resource.
2. GET requests can include parameters in the URL, whereas POST requests
typically send data in the request body.

 How do you handle query parameters in a GET request using Robot


Framework?
1) You can append query parameters directly to the URL when making a GET
request. For example:
${response}= GET my_session /products?category=electronics&sort=price
 What is the purpose of the RequestsLibrary in Robot Framework?
RequestsLibrary is used to make HTTP requests (GET, POST, PUT, DELETE, etc.)
in Robot Framework tests. It simplifies API testing by providing keywords for
handling requests and responses.

 How would you check the response status code of a GET request?
You can access the status_code attribute of the response object. For example:
Should Be Equal As Numbers ${response.status_code} 200

 How do you validate the response data from a GET request?


You can use keywords like Should Be Equal, Should Contain, or log the
response data to check if it matches expected values:
${response_data}= ${response.json()}
Should Be Equal ${response_data['title']} 'Expected Title'

 What are some common HTTP headers you would use with a GET request?
Common headers include:
Accept: Specifies the content types the client can process (e.g.,
application/json).
Authorization: Used for authentication, often containing tokens or credentials.
Cache-Control: Directives for caching mechanisms.

 How do you handle authentication when making a GET request?


You can include an Authorization header with the token or credentials
required for authentication. For example:
Create Session my_session ${BASE_URL} headers=Authorization: Bearer
your_token

 Can you give an example of using a GET request in Robot Framework to fetch
user details?
You can demonstrate a test case that retrieves user details using a GET
request, validating the response:
*** Test Cases ***
Get User Details
Create Session my_session https://jsonplaceholder.typicode.com
${response}= GET my_session /users/1
Should Be Equal As Numbers ${response.status_code} 200
Should Be Equal ${response.json()['username']} 'Bret'

 What would you do if the GET request returns a 404 status code?
I would investigate the endpoint to ensure it is correct, check if the resource
exists, and possibly log the error for further analysis. Depending on the
situation, I might implement error handling to manage such cases in my tests.

 If a GET request takes a long time to respond, how would you handle it?
You could implement timeout settings in your GET request and add error
handling to retry the request or log the issue. For example:
${response}= GET my_session /posts/1 timeout=10

POST Request
What is a POST Request?

 A POST request is an HTTP method used to send data to a server to create


resource.
 In API testing, POST requests are often used to submit data (e.g., form data,
JSON objects) and verify that the server processes and stores the data
correctly.

Why to Use POST Request in API Testing?


 Creating Resources: POST requests are primarily used to create new
resources on a server. For example, creating a new user in a database or
submitting a form.
 Handling Large Payloads: POST requests allow sending large amounts of
data in the request body, unlike GET requests where parameters are
limited to the URL.
 Server-Side Operations: POST is commonly used when the API requires
server-side operations, such as updating databases or triggering workflows.
 Non-Idempotency: POST requests are not idempotent, meaning multiple
requests may create multiple resources. This is useful when every
submission should result in a new resource.

Where to Use POST Requests?

 API Testing for Web Applications: Whenever you need to create or modify
data on the server, such as submitting a form, uploading a file, or posting
comments in a forum.
 Automation of CRUD Operations: In testing APIs that involve Create
operations (in Create, Read, Update, Delete - CRUD), POST is essential for
automating these tests.
 Integration Testing: POST requests are used in testing workflows where an
API creates resources that are then validated by further actions (e.g.,
retrieving data or updating data).

When to Use POST Requests?

 When Testing APIs That Create Data: POST is used when testing operations
that create new entities in the system, such as a new user or transaction.
 When You Have Data to Send in the Request Body: POST requests allow
you to send structured data (like JSON or XML) in the request body, which
is necessary when the API requires complex input data.
 For Testing Stateful Operations: Since POST requests often change the
state of the server (like creating an order in an e-commerce system), use
them when you need to test state-changing operations.
Key Points on POST Request:

Use: POST requests are used when testing APIs that involve creating or updating
resources on the server.

Why to Use: It allows sending structured data to create new resources and
perform non-idempotent operations.

Where to Use: POST requests are essential in testing the create (C) part of CRUD
operations in API testing.

When to Use: Use POST when you have to send large payloads in the request
body, modify the server state, or test API endpoints that involve data submission.

PUT Request
What is PUT?

 PUT is an HTTP method used to update an existing resource on a server or


create a new one if it doesn’t already exist.
 Unlike POST, which is used to create resources, PUT either updates the
entire resource if it already exists or creates a new resource if it doesn’t.

Why use PUT?

PUT is useful when you need to:

 Update the entire content of a specific resource.


 Ensure idempotency, meaning that no matter how many times you send
the same PUT request, the result will always be the same (unlike POST,
where multiple requests could result in multiple resources being created).
 Modify or replace an existing resource with a new one.

Where to use PUT?

 Use PUT when interacting with RESTful APIs in situations where you need
to:
 Update an existing resource (such as updating user details, modifying a
product, etc.).
 Ensure that multiple identical requests don’t cause unexpected results.
 Create resources with a client-specified ID (if the resource doesn’t exist).

When to use PUT?

PUT should be used when:

 You are making changes to an existing resource (for example, modifying


data fields for a particular user or object).
 You need to replace an entire resource.
 The resource ID is known, and you’re making changes to that specific
resource.

Summary

 PUT is used to update or create resources on a server.


 It is idempotent (multiple identical requests result in the same state).
 Use PUT when you want to update an entire resource or ensure that a
specific resource is replaced or created.
 In the Robot Framework, the RequestsLibrary is used to send PUT requests,
and you can easily integrate this with your Python scripts.

Example Use Case:

 You need to update an employee’s name from deva to Devender for the
employee with emp_id = 1. This can be done with a PUT request because
you're replacing the existing employee's information with new data.
 If the employee does not exist, the same PUT request can be used to create
a new employee record with emp_id = 1 and name = Devender.

Before PUT Request


If you have an employee resource with the following details:

emp_id: 204

name: “Kesav”

1. Before PUT Request

The original resource for emp_id = 204 might look like this:

“emp_id”: 204,

“name”: “Kesav”, //Needs to Updated name from kesav to Keshav

“position”: “Engineer”, //Needs to Updated position like the above one

“department”: “IT” //Needs to Updated department like the above one

2. PUT Request

If you want to update the employee’s details to, say, a new name “Keshav” and
perhaps change the position and department as well, you would send a PUT
request with the full updated employee object:

PUT /employees/204

Content-Type: application/json

“emp_id”: 204,

“name”: “Keshav”, //Updated name

“position”: “Senior Engineer”, //Updated position


“department”: “Development” //Updated department

3. Expected Behavior

After successfully sending the PUT request, the updated resource on the server
would now look like this:

“emp_id”: 204,

“name”: “Keshav”,

“position”: “Senior Engineer”,

“department”: “Development”

What is the difference between PUT and PATCH?

The PUT and PATCH methods are both used to update resources in RESTful APIs,
but they differ significantly in how they perform those updates.

4. Purpose
 PUT: The PUT method is used to update an existing resource or create a
new resource if it does not exist. It requires the complete representation of
the resource being updated.
 PATCH: The PATCH method is used to apply partial modifications to a
resource. It only requires the fields that need to be updated, rather than
the complete resource.
5. Request Body
 PUT: The request body must contain the entire updated resource. If any
fields are omitted, they may be cleared or set to default values on the
server.
Example: Updating a user profile:
PUT /users/123
{
“id”: 123,
“name”: “John Doe”,
“email”: “john@example.com”
}
 PATCH: The request body contains only the fields that need to be changed.
This makes it more efficient for updates.
Example: Updating just the user’s email:
PATCH /users/123
{
“email”: “john.doe@example.com”
}

3.Idempotence

 PUT: PUT is idempotent, meaning that making the same PUT request
multiple times will have the same effect as making it once. If you send the
same data again, it will not change the resource further.
 PATCH: PATCH is not necessarily idempotent, as applying the same patch
multiple times may result in different outcomes. For example, if you PATCH
a counter field, the value may change with each request.
6. Use Cases
 PUT: Use PUT when you need to replace an entire resource or ensure that
the resource has a complete and specific state. Common in situations
where the resource is small and can easily be sent in full.
 PATCH: Use PATCH when only a few fields of a resource need to be
updated. It is particularly useful for large resources where only minor
changes are necessary. Ideal for frequent updates, as it reduces data
transfer.
7. Server Behavior
 PUT: If the resource does not exist, the server may create it based on the
request body.
 PATCH: The server will only modify the fields specified in the request body.
Other fields remain unchanged.

PATCH Request
What is PATCH?

 The PATCH HTTP method is used to apply partial modifications to a


resource.
 Unlike PUT, which replaces the entire resource, PATCH only updates the
specified fields that you provide in the request body.
 This is particularly useful for optimizing data transfers and reducing payload
size when only a few fields need to be changed.

Why Use PATCH?

 Efficiency: Since only the changes are sent to the server, it minimizes the
amount of data sent over the network, making it more efficient.
 Flexibility: Allows partial updates without needing to resend the entire
resource, which can be beneficial for large resources.
 Better Performance: Reduces server load and bandwidth usage, especially
for applications where frequent updates are necessary.
Where to Use PATCH?

 RESTful APIs: Most commonly used in RESTful web services to update


resources where only certain attributes or fields need to be modified.
 Applications with Large Payloads: When dealing with large data objects
where only a few fields change frequently (e.g., user profiles, settings).
 Mobile Applications: Helps in reducing data usage on mobile networks
when sending updates to server data.

When to Use PATCH?

 When you need to update only a subset of a resource’s attributes.


 When the resource is large, and the update does not require the entire
resource to be sent.
 When you want to improve the efficiency of data updates, especially in
scenarios with frequent modifications.

Example: if you have a resource representing an employee with the following


details:

emp_id: 204

name: “Kesav”

Before PATCH Request

 The original resource (for emp_id = 204) might look something like this in
JSON format:
{“emp_id”: 204, “name”: “Kesav”, “position”: “Engineer”, “department”:
“IT” }

PATCH Request

You would send a PATCH request to update only the name field:

PATCH /employees/204

Content-Type: application/json
{

“name”: “Keshav”

Expected Behavior

After successfully sending the PATCH request, the updated resource on the server
might look like this:

“emp_id”: 204,

“name”: “Keshav”, // Updated name

“position”: “Engineer”,

“department”: “IT”

DELETE Request
What is DELETE?

 The DELETE HTTP method is used to request the removal of a specified


resource on a server.
 When a client sends a DELETE request, it typically indicates that the
resource identified by the URI should be deleted.

Why Use DELETE?


 Resource Management: It allows clients to manage resources on a server
by removing data that is no longer needed.
 Clean-up: It helps in cleaning up unused or outdated resources to free up
storage and maintain the server’s integrity.
 Transactional Behavior: In systems that support transactions, DELETE
operations can be a part of a larger transactional workflow.

Where to Use DELETE?

 RESTful APIs: Commonly used in RESTful services for operations involving


data manipulation.
 Resource-Specific Operations: Whenever there’s a need to delete a specific
record,

such as:

o Deleting a user from a database.


o Removing a product from an inventory.
o Clearing logs or temporary files.

When to Use DELETE?

 When Data is No Longer Needed: Use DELETE when you have confirmed
that the resource is no longer needed or is obsolete.
 When a User Requests Deletion: Often used in scenarios where a user
requests to remove their data or any specific resource.
 During Maintenance: Use DELETE during maintenance activities to remove
unnecessary or temporary data.

HEAD Request
What is HEAD?
The HEAD method is an HTTP request method used to retrieve the headers of a
resource without fetching the body of the resource. It’s similar to the GET
request, but it only returns the response headers, not the actual data.

Why Use HEAD?

 Efficiency: Since HEAD requests do not return the body of the resource,
they are generally faster and consume less bandwidth, making them ideal
for checking resource availability and metadata without downloading the
entire resource.
 Caching: It can be used to check if the cached version of a resource is still
valid, as the headers often contain cache-related information.
 Validation: Useful for checking if a resource exists before making a full GET
request, allowing for quick validation of URLs or endpoints.

Where to Use HEAD?

 Resource Availability: When you want to check if a resource exists or is


available without transferring the full content.
 Metadata Inspection: When you need to gather metadata such as
content type, content length, or last modified date of a resource.
 Performance Monitoring: To monitor response times and headers
without the overhead of transferring large payloads.

When to Use HEAD?

 When you need to verify the existence of a resource without downloading


it.
 When you want to retrieve information about a resource (like content
length or type) before performing other operations.
 When you want to reduce network traffic in situations where you are
checking many resources.

Summary
 HEAD is an efficient method to retrieve metadata about a resource without
downloading it.
 Use it for checking resource availability, inspecting headers, and optimizing
performance.
 Easily implemented in Robot Framework using the RequestsLibrary or
through custom Python keywords.

Interview Questions
What is REST, and how does it work?

REST (Representational State Transfer) is an architectural style for designing


networked applications.

It relies on stateless communication and uses standard HTTP methods like GET,
POST, PUT, DELETE to perform operations on resources, which are identified by
URLs (URIs).

What are the main HTTP methods used in REST APIs, and what do they do?

Answer: The main HTTP methods are:

 GET: Retrieve data from a server.


 POST: Send data to the server to create a new resource.
 PUT: Update an existing resource or create it if it doesn’t exist.
 DELETE: Remove a resource from the server.
 PATCH: Partially update an existing resource.

What is the difference between Get and Post Request?

 Get is used to retrieve data from the server and Post is used to submit data
to the server, to create a new resource in server.
 GET: Data is sent as part of the URL in the query string (e.g., ?name=value)
and Post: Data is sent in the body of the request, not in the URL.
 Because the data is included in the URL, there are length limits, and it’s not
suited for sending large data and There is no size limit on the body data, so
it can handle large payloads (e.g., files or form data).
 Data is visible in the URL, making it less secure for sensitive information
like passwords or personal data and Data is sent in the body, which is not
directly visible in the URL, making it more secure for sensitive data.
 GET is idempotent, meaning multiple identical GET requests will have the
same effect (i.e., fetching the same resource without any side effects) and
POST is not idempotent, meaning each POST request could have different
effects, such as creating a new resource or triggering an action on the
server.

What is the difference between a POST and PUT request in REST API, and how
can you implement both in Robot Framework?

POST: Used for creating a resource

${response}= Post Request my_session /api/resource json={“name”: “new


resource”}

PUT: Used for updating a resource

${response}= Put Request my_session /api/resource/1 json={“name”:


“updated resource”}

How would you handle authentication for REST API requests?

Answer: Authentication can be handled using different methods such as Basic


Auth, OAuth, Bearer Tokens, or API keys, depending on the API requirements.
You can include the credentials in the request headers.

How do you perform a GET request in Robot Framework?

Answer: Using the RequestsLibrary, you can perform a GET request like this

*** Settings ***

Library RequestsLibrary

*** Test Cases ***


Perform GET Request

Create Session my_session http://example.com

${response}= Get Request my_session /api/resource

Log ${response.status_code}

Log ${response.json()}

How can you verify the status code of an API response in Robot Framework?

Answer: You can verify it using the Should Be Equal As Numbers keyword

Should Be Equal As Numbers ${response.status_code} 200

How do you send headers and payload in a POST request in Robot Framework?

Answer: You can add headers and payload using the json or data arguments along
with Create Dictionary for headers.

${headers}= Create Dictionary Content-Type=application/json

${data}= Create Dictionary name=example age=30

${response}= Post Request my_session /api/resource headers=${headers}


json=${data}

How can you handle dynamic URLs in Robot Framework for API requests?

Answer: You can parameterize the URL by passing variables into the request.

${url}= Set Variable /api/resource/${resource_id}

${response}= Get Request my_session ${url}

How do you handle errors or failed API requests in Robot Framework?


Answer: You can use conditional statements and check the status code to handle
errors.

${response}= Get Request my_session /api/resource

Run Keyword If ‘${response.status_code}’ != ‘200’ Fail Request Failed: $


{response.status_code}

How would you validate JSON response data in Robot Framework?

Answer: You can use the Should Be Equal or Should Contain keyword to validate
the JSON response.

${response_json}= To Json ${response.content}

Should Be Equal ${response_json[“name”]} expected_name

How many status code are there of an API response in Robot Framework?

HTTP status codes are grouped into five categories, and there are many specific
codes under each category.

1. 1xx: Informational (100–103)


2. 2xx: Success (200–226)
3. 3xx: Redirection (300–308)
4. 4xx: Client Errors (400–451)
5. 5xx: Server Errors (500–511)

There are over 60 standard HTTP status codes across the different categories.

what is should be equal and Should Be Equal As Numbers

Should Be Equal

 Purpose: Compares two values for equality.


 Type Handling: Treats the values as strings, so the comparison is done
based on string content.
 Usage: Use this keyword when you want to check if two values are the
same as strings.
Should Be Equal As Numbers

 Purpose: Compares two values for equality while treating them as


numbers.
 Type Handling: Converts both values to numeric types (integer or float)
before comparison, so it evaluates the numerical equality.
 Usage: Use this keyword when you want to ensure that two values are
numerically equal, especially useful for comparisons involving numbers like
HTTP status codes.

what is ${response.content} and ${response.text} ?

${response.content}:

 This attribute contains the raw response content in bytes.


 It is useful when you need to handle binary data, such as images or files, as
it preserves the original byte structure without any encoding.
 You would typically use this when dealing with non-text responses.

${response.text}:

 This attribute contains the decoded response content as a string, using the
appropriate character encoding (e.g., UTF-8).
 It is typically used when you expect a textual response, such as JSON,
HTML, or plain text, and you want to work with it as a string.
 It automatically handles the decoding of bytes to a string based on the
content type specified in the response headers.

Key Differences:

Type: ${response.content} is in bytes, while ${response.text} is in string.

Use Case: Use ${response.content} for binary data and ${response.text} for
textual data.

You might also like