TecNimbus

Let’s build better software—and a more balanced life—together.

Petstore API Demo – Test Scenarios for API Automation

đź§© Scenario 1: Add a new pet to the store

Purpose:
Verify that a new pet can be successfully created in the store and that the response contains the expected data.

Steps:

  1. Send a POST /pet request with a valid pet object.
  2. Verify that the response status code is 200.
  3. Verify that the response body contains a valid pet id.
  4. Store this id for use in later requests.

Expected Result:
The new pet is created successfully, and a valid pet ID is returned in the response.


đź§© Scenario 2: Update an existing pet

Purpose:
Confirm that an existing pet’s details can be updated using the previously created pet ID.

Steps:

  1. Send a PUT /pet request using the saved petId.
  2. Modify one or more attributes (e.g., name, status).
  3. Verify that the response status code is 200.
  4. Verify that the updated values appear in the response.

Expected Result:
The pet’s details are successfully updated and reflected in the response.


đź§© Scenario 3: Find pet by ID

Purpose:
Ensure that the system can retrieve a specific pet using a valid pet ID.

Steps:

  1. Send a GET /pet/{petId} request using the saved petId.
  2. Verify that the response status code is 200.
  3. Verify that the returned id matches the expected petId.

Expected Result:
The correct pet details are returned for the given ID.


đź§© Scenario 4: Pet not found

Purpose:
Validate that the API correctly handles cases when a pet does not exist.

Steps:

  1. Send a GET /pet/{invalidId} request with a non-existent pet ID (e.g., 999999).
  2. Verify that the response status code is 404.
  3. Verify that the response message indicates “Pet not found” or similar.

Expected Result:
The API returns a proper error response indicating the pet does not exist.

Fature scenarios

Feature: PetStore API Testing
  This feature tests the PetStore API endpoints for creating, updating, retrieving, and handling non-existent pets.

  Background:
    Given the PetStore API is available
    And I have the base URL "https://petstore.swagger.io/v2"

  @create
  Scenario: Add a new pet to the store
    When I send a POST request to "/pet" with the following body:
      """
      {
        "id": 0,
        "name": "fluffy",
        "status": "available"
      }
      """
    Then the response status code should be 200
    And the response should contain a valid "id"
    And I store the "id" as "petId"

  @update
  Scenario: Update an existing pet
    Given I have a stored "petId"
    When I send a PUT request to "/pet" with the following body:
      """
      {
        "id": {{petId}},
        "name": "fluffy-updated",
        "status": "sold"
      }
      """
    Then the response status code should be 200
    And the response body should contain "fluffy-updated" as the name
    And the status should be "sold"

  @get
  Scenario: Find pet by ID
    Given I have a stored "petId"
    When I send a GET request to "/pet/{{petId}}"
    Then the response status code should be 200
    And the response body should contain "id" equal to {{petId}}

  @notfound
  Scenario: Pet not found
    When I send a GET request to "/pet/999999"
    Then the response status code should be 404
    And the response body message should contain "Pet not found"