API Automation Framework to test Swagger Pet Store API.
This framework is designed to automate API testing for the PetStore application. It integrates popular tools and libraries like RestAssured, TestNG, Cucumber, Allure Reports, SLF4J Logger, and CI/CD - Github Actions to provide a robust and maintainable testing solution.
- The framework follows a standard Maven project structure:
src/test/java/io/swagger/petstore/base: Contains BaseTest.java, the base class for test setup.src/test/java/io/swagger/petstore/data: Includes CommonData.java for managing common test data.src/test/java/io/swagger/petstore/stepdefinitions: Holds Cucumber step definitions, including Hooks.java for setup and teardown.src/test/java/io/swagger/petstore/utils: Contains utility methods in Utils.java.src/test/resources: Includes Cucumber feature files, JSON schemas, and configuration properties.
- Run
git clone https://github.com/srthorat/petstore.git
- Assuming that local setups for Maven and Java are already in place
- If not refer Java 8 Setup, Maven Setup
- Goto to Project repo
cd <BasePath>/petstore - Run
mvn clean install
- Run
mvn clean test - To execute specific tags from command line we can use
mvn test -Dcucumber.filter.tags="@Sanity". - We support two tags -
@Sanity@All_E2E
- Run
mvn allure:serveormvn allure:report - Report will be generated into temp folder. Web server with results will start.
- Go to Actions tab - Actions
- From the left, below All workflows select the workflow - Java CI with Maven
- A
Run workflowdropdown will appear on the right, Select it, then choosebranch - main, and clickRun Workflow. - Refresh Page
- You can now see -
Java CI with Mavenjob is running, While completes, open Java CI with Maven to monitor the test running status and view logs. - Once the
Java CI with Mavenjob complete, thepages build and deployment with artifacts-nextjob will start running automatically, wait for it to complete. - Once the
pages build and deployment with artifacts-nextgets completes, double-click on job name. - You can now see job details, You can see stages like
build ===> report-build-statusandbuild ===> deploy - On the deploy stage, find the link - https://srthorat.github.io/petstore. Open this link to view the Allure report summary for the last run.
-
Navigate to the src/test/resources/features directory.
-
Create a new file named NewTestCase.feature.
-
Add meaningful BDD steps for the new test case scenario.
Feature: New Test Case Scenario: Description of the new scenario Given some initial conditions When an action is performed Then the expected outcome is verified```
- Open
PetStoreStepDefinitions.javaor create new file located insrc/test/java/com/example/petstore/stepdefinitions. - Add step definitions for the new steps in the NewTestCase.feature file.
- Run your test suite to execute the new test case.
- Verify that the test case runs successfully and produces the expected outcomes.
- Issue: Unable to run tests successfully.
- Solution:
- Ensure that the necessary dependencies are installed.
- Verify that the API is accessible.
- Check the correctness of test data and configurations.
- Issue: Maven build fails due to dependency issues.
- Solution:
- Check your
pom.xmlfile for correct dependencies and versions. - Run
mvn clean installto download and install dependencies.
- Check your
- Issue: Tests fail due to inability to connect to the API.
- Solution:
- Check the API base URL in the
BaseTest.javaclass. - Verify network connectivity.
- Ensure the API is running and accessible.
- Check the API base URL in the
- Issue: Tests fail due to API request issues.
- Solution:
- Inspect the request details in the test logs.
- Check the request headers, body, and parameters.
- Ensure that the request format and data are correct.
- Issue: JSON schema validation fails.
- Solution:
- Verify that the expected JSON schema file exists.
- Check for any discrepancies between the response and the schema.
- Update the schema file if necessary.
- Issue: Cucumber reports duplicate step definitions.
- Solution:
- Ensure each step definition has a unique signature.
- Check for duplicate step definitions with similar patterns.
- Adjust step definitions to avoid conflicts.
- Issue: Need to update test data for new scenarios.
- Solution:
- Update the feature file with new scenarios and steps.
- Implement corresponding step definitions in PetStoreStepDefinitions.java.
- Ensure any necessary data (e.g., API endpoints, expected responses) is updated.