Welcome to the API Automation Training! This repository serves as the foundation for the training, providing a base API Automation Framework and step-by-step guidance for participants to build their API automation skills.
The training is designed for participants to fork this repository, develop their tests for a mock API, and create Pull Requests (PRs) for feedback and review. Mentors will review pull requests (PRs) regularly, providing feedback and guidance to ensure learning and progress.
Training Objectives
-
Learn the basics of Java: I'd like you to understand the fundamental features of Java, including classes, inheritance, and other key concepts. These concepts will help you write better, more maintainable code for API automation.
-
Understand the Base Framework: Familiarize yourself with the provided Java API Automation Framework using Maven for test execution, Rest Assured for HTTP requests, and JUnit 5 for assertions. Discover how the framework is structured and learn how to use it to meet your testing needs.
-
Learn API Automation Concepts: Grasp core concepts like service modeling (encapsulating API endpoints), organizing test cases, setting up environments with .env files, and strategies for functional and non-functional API testing.
-
Implement Test Automation: Use the base framework to write tests for real-world scenarios using the CatCafeProject API. Implement robust, maintainable test scripts for CRUD operations and edge cases.
-
Collaborate Effectively: Develop skills in using Git workflows for version control and management. Create feature branches, submit Pull Requests (PRs), and respond to feedback from mentors. Learn best practices for working in an asynchronous environment while maintaining high-quality contributions.
- Fork the Repository: Fork this repo to your GitHub account and create a local clone.
- Add collaborators: Add your mentors as collaborators to the repo.
- Branching: Use feature branches (e.g., feature/milestone-1) for your changes.
- Pull Requests: Create PRs for each milestone. Include a description of your changes and any challenges faced. Add your mentor as a reviewer.
- Code Reviews: Mentors/Teachers will review your pull requests (PRs), providing feedback.
- Feedback: Please address feedback promptly and resubmit your PR.
Before starting each milestone, create a feature branch with the milestone's name, e.g., feature/milestone-1. Follow each Milestone without reading the next one.
Objective: Establish the framework and comprehend its structure. Create a service model with methods for the Store service.
-
Move to the framework folder:
cd framework -
Install dependencies and set up your environment:
mvn install copy example.env .env
Note: If the execution does not work because you do not have Maven installed, go to https://maven.apache.org/ and follow the download and install instructions
-
Update .env with the test API base URL:
BASEURL=http://catcafeproject.us-east-1.elasticbeanstalk.com -
Explore the framework:
- Read the README.md file in the framework folder.
- Understand the
ServiceBaseclass and its usage in service models. - Understand the API that will be used: http://catcafeproject.us-east-1.elasticbeanstalk.com/api-docs/
-
Create a new
CatServiceextendingServiceBase. -
Implement methods in
CatServicefor the following operations:GET /catsPOST /catsPUT /cats/{catId}GET /cats/{catId}PATCH /cats/{catId}DELETE /cats/{catId}
-
Add request and response models where appropriate.
-
Write the first test for the POST /cats endpoint to verify that a Cat can be created successfully.
Deliverable:
- Create a pull request (PR) with the change, including a brief description of your implementation process.
Objective: Configure and understand the GitHub Action to run tests on each PR and merge to main.
- If you are not familiar with GitHub Actions, conduct some research to understand the basics, including workflows, jobs, and steps. Refer to the GitHub Actions Documentation.
- Explore the
.github/workflows/main.ymlfile to understand the workflow triggers and steps. - Based on your research on GitHub Actions and your experience running the tests in IntelliJ, adjust the Maven line in the main.yml file so that the tests are run in the pipeline.
- Create a new environment called "Testing" in Settings > Environments > New environment
- Configure the
BASEURLas an environment variable with value:http://catcafeproject.us-east-1.elasticbeanstalk.com
Deliverable:
- Create a pull request (PR) with a summary of what you learned and confirm that the workflow ran successfully in the Actions tab.
Objective: Create and write tests for the Create Cat test Suite.
- Write additional tests for the Create Order (
POST /cats) endpoint. - Include positive and negative tests.
- Use tags like
@Tag("Smoke")or@Tag("Regression")for test categorization.@Tag("Smoke")tests should be the ones that are required to pass.
Deliverable:
- Create a pull request (PR) with the tests and a summary of the scenarios covered. Remember to check the pipeline every time a pull request (PR) is created.
Objective: Write tests for the remaining Cat Service components, adhering to the practices outlined above.
Write a test suite for each of the remaining endpoints in the Cat Service:
- GET /cats
- GET /cats/{catId}
- DELETE /cats/{catId}
- PATCH /cats/{catId}
- PUT /cats/{catId}
- Create a pull request (PR) with the tests and a summary of the scenarios covered. Remember to check the pipeline every time a PR is created.
Objective: Write hooks for pre- and post-conditions.
- Write a before HOOK in the Get Cat test suite. i. Add a Before hook that creates a cat by calling the right method in the CatService model. ii. Obtain and store the catId (the variable for this must be declared above the before hook). iii. See the saved catId in the Get Cat test.
- Write an after HOOK in the Create Cat test suite. This is very useful for cleaning up data after a test execution. i. After every positive test, update the catId variable with the newly created Cat ID. ii. Add an AfterEach hook that deletes the created cat by calling the right method in the CatService model.
Deliverable:
- Create a pull request (PR) with the tests and a summary of the scenarios covered.
Objective: Expand the test suite with basic performance test cases.
- Add performance checks for the endpoints (e.g., response time < 1000ms).
Deliverable:
- Create a pull request (PR) with the new tests and details covered.
Objective: Implement automation for additional services (Adopter and User).
- Repeat the previous steps for Adopter and User service.
- Create at least one user in the DB without deleting it.
Deliverable:
- Create separate pull requests (PRs) for each suite across both services.
Objective: Implement the authentication method. Extend automation for the Staff service.
- Go to the ServiceBase class and find the example authenticate method.
- Read the method and its documentation to understand what it does.
- Now read the CatCafeProject documentation to understand how the authentication works for this API.
- Update the authenticate method in the ServiceBase class and any other part of the code you need, to implement authentication for your Staff tests using the SessionManager.
- Implement the StaffService and its test suite.
- Use the authentication method in your Staff tests: i. Add the USER and PASSWORD environment variables in the framework/.env file, using the data from an existing user that you created on step 2 from Milestone7. ii. Modify the tests to call the authenticate method from a before hook, sending the credentials from your env file. iii. Create the secret variables "USER", "PASSWORD", and "JWT_SECRET" in your "Local" environment on Github.
Deliverable: Create separate PRs for the implementation of the authentication infrastructure and for the Staff service and tests.
- Create separate PRs for each suite across both services.
- Engage Actively: Reach out for help if you're stuck or need clarification.
- Focus on Quality: Write clean, maintainable code and meaningful tests.
- Learn from Feedback: Incorporate mentor feedback to refine your implementation.