Automation QA Testing Course Content

Test Cases For API Functional Testing

 

60 Test Cases For API Testing For Each Category

Test Cases For API Functional Testing

  1. Status Code Validation for Valid Requests: Verify that the API consistently returns the expected response status code, such as "200 OK," for valid and properly formatted requests.
  2. Authentication Handling with Invalid Credentials: Test the API's response when provided with invalid authentication credentials, ensuring it consistently returns a "401 Unauthorized" status code as expected.
  3. Graceful Handling of Missing or Invalid Parameters: Verify that the API handles missing or invalid request parameters gracefully and returns clear and user-friendly error messages that aid in troubleshooting.
  4. Input Data Validation with Malformed Data: Test the API's input validation by submitting various forms of malformed data, such as invalid email formats, and confirm that it properly rejects and responds to these inputs.
  5. Timeout Handling under Load: Confirm that the API correctly handles timeouts by simulating requests that take longer to process, ensuring that it remains responsive and do not hang.
  6. Pagination Functionality Verification: Test the API's pagination functionality by requesting specific pages of results and verifying that the responses contain the expected data and pagination information.
  7. Concurrency Testing without Data Corruption: Verify that the API handles concurrent requests from multiple users without data corruption or conflicts, ensuring data integrity.
  8. Response Format Adherence (JSON/XML): Ensure that the API consistently returns responses in the specified format (e.g., JSON or XML) and adheres to the defined schema for data structure.
  9. Caching Mechanism Evaluation with Repeated Requests: Evaluate the API's caching mechanism by making repeated requests and verifying that the cache headers are correctly set and honoured.
  10. Rate Limiting Assessment: Test the API's rate limiting by sending requests at a rate that exceeds the defined limits and checking for the expected rate-limiting responses, ensuring that limits are enforced.
  11. HTTP Method Support for CRUD Operations: Verify that the API supports a variety of HTTP methods (GET, POST, PUT, DELETE) for Create, Read, Update, and Delete operations, and that it returns appropriate responses for each.
  12. Error Handling Capabilities for Meaningful Messages: Evaluate the API's error-handling capabilities by intentionally causing errors, such as invalid inputs or unexpected situations, and confirm that it consistently returns meaningful error messages for troubleshooting.
  13. Conditional Request Handling (If-Modified-Since, If-None-Match): Test the API's support for conditional requests using headers like If-Modified-Since and If-None-Match, ensuring that responses are handled appropriately.
  14. Sorting and Filtering Validation for Resource Listings: Verify that the API correctly sorts and filters resource listings based on specified parameters, maintaining data accuracy.
  15. Handling Long or Complex Data without Data Corruption: Ensure that the API properly handles long or complex strings, such as URLs or text fields, without truncating or corrupting the data.
  16. Content Negotiation Support for Multiple Formats: Test the API's support for content negotiation by specifying different Accept headers (e.g., JSON, XML) and verifying that the response format matches the requested format.
  17. Resource Not Found Handling (404 Not Found): Confirm that the API consistently returns the appropriate "404 Not Found" response when attempting to access a non-existent resource.
  18. Response Time Measurement for Various Requests: Measure the API's response time for different types of requests to assess its performance and responsiveness.
  19. Handling Large Payloads (File Uploads): Verify that the API can handle large payloads, such as file uploads, without encountering errors or significant performance degradation.
  20. Compatibility with Client Libraries and SDKs: Evaluate the API's compatibility with different client libraries or SDKs to ensure seamless integration with various platforms and programming languages.


Test Cases For API Performance Testing

  1. Baseline Response Time: Measure the response time of a simple API request under normal conditions to establish a performance baseline.
  2. Stress Testing: Send many simultaneous requests to the API to assess its performance under heavy load.
  3. Concurrency Testing: Evaluate how the API handles a specified number of concurrent requests without performance degradation.
  4. Ramp-up Testing: Gradually increase the number of requests over time to identify the API's breaking point and performance limits.
  5. Peak Load Testing: Test the API's performance at peak usage times to ensure it can handle maximum expected traffic.
  6. Endurance Testing: Continuously send requests to the API for an extended duration to assess its stability over time.
  7. Scalability Testing: Increase the load gradually and measure how the API scales by adding more resources (e.g., servers) to maintain performance.
  8. Resource Utilization Testing: Monitor CPU, memory, and network utilization while conducting performance tests to identify resource bottlenecks.
  9. Response Time Distribution: Analyze the distribution of response times to identify outliers and performance issues.
  10. Latency Testing: Measure network latency between the client and the API server to ensure low latency for users.
  11. Throughput Testing: Determine the maximum number of transactions the API can handle per unit of time while maintaining acceptable response times.
  12. Error Rate Testing: Monitor and record the rate of errors or failed requests during load testing to assess error handling and resilience.
  13. Caching Performance: Evaluate the impact of caching on response times and resource utilization.
  14. Data Volume Testing: Test the API with varying data volumes (e.g., small, medium, and large payloads) to assess its performance with different data sizes.
  15. Geographical Load Testing: Simulate requests from different geographic locations to assess the API's global performance and response times.
  16. Concurrency with Authentication: Evaluate how the API handles concurrent requests with authentication, including token validation.
  17. Database Load Testing: Assess the impact of API requests on the associated database by measuring query response times.
  18. Long-Running Transactions: Test transactions that take a significant amount of time to complete and assess their impact on overall system performance.
  19. Rate Limiting Stress Testing: Test how the API handles excessive requests when rate limiting is in place.
  20. Failover Testing: Simulate server failures and test the API's ability to failover to backup servers while maintaining performance.


Test Cases For API Security Testing

  1. Authentication Testing: Verify that the API enforces proper authentication for all endpoints.
  2. Authorisation Testing: Ensure that users can access only the resources they are authorised to access.
  3. Token Security: Test the security of authentication tokens, including token encryption and expiration.
  4. Session Management: Check for secure session management and handling of session cookies.
  5. SQL Injection: Test for SQL injection vulnerabilities by injecting malicious SQL queries in API parameters.
  6. Cross-Site Scripting (XSS): Verify that the API is protected against XSS attacks by injecting malicious scripts.
  7. Cross-Site Request Forgery (CSRF): Test if the API is vulnerable to CSRF attacks by submitting unauthorized requests.
  8. Input Validation: Ensure that the API validates and sanitizes user inputs to prevent injection attacks.
  9. Rate Limiting: Test the API's rate limiting to prevent abuse and DoS attacks.
  10. Sensitive Data Exposure: Verify that sensitive data, such as passwords or API keys, are not exposed in responses.
  11. HTTPS/TLS Testing: Ensure that the API uses secure communication via HTTPS/TLS and checks for certificate validity.
  12. CORS (Cross-Origin Resource Sharing) Security: Test for correct CORS headers to prevent unauthorized cross-origin requests.
  13. API Key Security: Assess the security of API keys and their storage.
  14. JWT (JSON Web Token) Security: Evaluate the security of JWTs used for authentication and authorization.
  15. Authentication Bypass: Attempt to bypass authentication mechanisms and gain unauthorized access.
  16. Session Fixation: Test if the API is vulnerable to session fixation attacks.
  17. Insecure Direct Object References (IDOR): Check for unauthorised access to resources by manipulating object references.
  18. Denial of Service (DoS) Testing: Attempt to overload the API and test its resilience against DoS attacks.
  19. API Versioning: Verify that the API supports versioning to prevent breaking changes from affecting existing clients.
  20. Security Headers: Check for the presence of security headers such as Content Security Policy (CSP), X-Content-Type-Options, etc., in API responses.


Which API Framework is better RESTASSURED or KARATE

 Both RestAssured and Karate are popular frameworks for API testing, but they serve slightly different purposes and have different strengths and weaknesses. Here’s a comparison to help you decide which one might be better for your specific needs:

RestAssured

Pros:

  1. Java Integration: RestAssured is a Java-based library, making it a good choice if you're already working within a Java ecosystem. It can easily integrate with other Java tools and frameworks.
  2. Flexibility: RestAssured provides fine-grained control over HTTP requests and responses, which is useful for complex testing scenarios.
  3. Mature and Robust: It is a well-established tool with extensive documentation and a large user community.
  4. Support for BDD: RestAssured supports Behavior-Driven Development (BDD) style tests using Cucumber.

Cons:

  1. Verbose: Writing tests can be more verbose compared to Karate, as you need to write more code to achieve the same functionality.
  2. Steeper Learning Curve: For beginners, getting started with RestAssured might be more challenging due to its extensive configuration and setup requirements.

Karate

Pros:

  1. Ease of Use: Karate is designed to be simple and easy to use, with a low learning curve. It uses a domain-specific language (DSL) that is very readable and concise.
  2. All-in-One Framework: Karate integrates API testing, mocking, performance testing, and UI testing (via Selenium) into a single framework.
  3. No Coding Required: You can write tests without having to write any Java code, making it accessible for non-developers.
  4. Built-in Assertions: Karate comes with built-in support for JSON and XML assertions, which makes it very convenient for validating responses.

Cons:

  1. Less Flexibility: While Karate is very powerful for most standard API testing needs, it might lack the flexibility required for more complex testing scenarios compared to RestAssured.
  2. Limited Customization: Being a higher-level framework, it might not provide as much control over the HTTP requests and responses as RestAssured.
  3. Performance: For extremely large and complex test suites, RestAssured might perform better due to its fine-grained control and optimizations.

When to Use RestAssured

  • Java Ecosystem: If your project is heavily based on Java and you prefer writing tests in Java.
  • Complex Scenarios: When you need extensive control over your HTTP requests and responses.
  • BDD Support: If you want to integrate with Cucumber for BDD-style tests.

When to Use Karate

  • Simplicity and Speed: When you need to get started quickly with minimal setup and want to write readable, maintainable tests.
  • Non-Developers: If your testing team includes members who are not proficient in coding.
  • All-in-One Solution: When you want a single framework to handle API, UI, and performance testing without needing multiple tools.

Conclusion

Both frameworks have their strengths and can be the better choice depending on your specific requirements. If you are looking for ease of use, quick setup, and an all-in-one testing solution, Karate might be the better choice. On the other hand, if you need more control, flexibility, and integration with a Java ecosystem, RestAssured would be more suitable.

Evaluate your project needs, team skillset, and the complexity of your test scenarios to make the best choice.

=========================================

Why API Automation is better than UI Automation?

API automation is the process of automating interactions with Application Programming Interfaces (APIs) using scripts, tools, or software.

UI automation, or User Interface automation, refers to the process of using software or tools to simulate user interactions with a graphical user interface (GUI) of a software application or system.

Here are some reasons why API automation is considered better than UI automation in certain scenarios:

  • Faster Execution:

API tests tend to run faster than UI tests because they don’t involve rendering web pages or interacting with the user interface. API requests and responses are typically lightweight, leading to quicker test execution.

  • Stability:

UI tests can be fragile and sensitive to changes in the user interface, making them prone to breakage when UI elements or layouts change. API tests are generally more stable because they focus on the underlying business logic and data flow.

  • Coverage:

API tests can provide comprehensive coverage of the application’s functionality, including edge cases and error scenarios. UI tests may not cover all possible user interactions or inputs.

  • Efficiency:

API tests can be more efficient for repetitive tasks like regression testing or load testing because they require fewer resources and can be run in parallel.

  • Data Validation:

API tests are well-suited for data validation because they can easily verify the correctness of data returned by the API. UI tests may require additional effort to extract and validate data displayed on the user interface.

  • Cross-Platform and Cross-Browser Compatibility:

API tests are not dependent on specific browsers or platforms, making them more suitable for testing the backend of applications that need to work across different environments.

  • Early Detection of Issues:

API tests can be integrated into the development pipeline to catch issues early in the development process, promoting a shift-left approach to testing.

  • Reduced Maintenance:

UI automation scripts often require frequent updates due to changes in the user interface. API tests tend to have lower maintenance overhead since they are less affected by UI changes.

  • Scalability:

API automation can easily scale to test multiple endpoints, versions, or services in a micro-services architecture.

  • Isolation:

API tests can be isolated from the user interface, allowing you to test specific functionalities or endpoints independently. This isolation simplifies debugging and makes it easier to identify the root cause of issues.

Let’s illustrate the difference between API automation and UI automation using a simple scenario of testing a login functionality.

I am using two popular frameworks; Postman for API automation & Selenium for UI automation.

API Automation Example (Using Postman)

In this API automation example, we’re using Postman to send a POST request to a login API endpoint. We then assert that the HTTP status code is 200 and that the response contains a “success” attribute set to true.

// Postman test script for API automation
pm.test("Login API Test", function () {
// Define the API endpoint and request parameters
const url = "https://api.example.com/login";
const request = {
method: "POST",
url: url,
header: {
"Content-Type": "application/json",
},
body: {
mode: "raw",
raw: JSON.stringify({
username: "testuser",
password: "password123",
}),
},
};

// Send the API request
const response = pm.sendRequest(request);

// Perform assertions on the API response
pm.expect(response.code).to.equal(200); // Check HTTP status code
pm.expect(response.json().success).to.be.true; // Check a specific JSON attribute
});

UI Automation Example (Using Selenium and Python)

In this UI automation example, we’re using Selenium (with Python) to automate interactions with a web-based login page. We locate elements on the page, enter login credentials, click the login button, then verify the presence of a welcome message to confirm successful login.

from selenium import webdriver

# Set up the Selenium WebDriver for a web browser (e.g., Chrome)
driver = webdriver.Chrome()

# Open the login page
driver.get("https://www.example.com/login")

# Locate the username and password input fields and the login button
username_input = driver.find_element_by_id("username")
password_input = driver.find_element_by_id("password")
login_button = driver.find_element_by_id("login-button")

# Enter login credentials and submit the form
username_input.send_keys("testuser")
password_input.send_keys("password123")
login_button.click()

# Perform assertions on the UI to verify successful login
welcome_message = driver.find_element_by_css_selector(".welcome-message")
assert "Welcome, testuser!" in welcome_message.text

# Close the browser
driver.quit()

As you can see, API automation focuses on making HTTP requests and validating API responses, while UI automation interacts with the user interface of a web application.

Summary