This project is a Java-based framework that uses Maven for build automation, RestAssured for API testing, and Cucumber for behavior-driven development (BDD) written with Gherkin. The project is configured to run tests and generate reports, which are then deployed to GitHub Pages.
- Java 11
- Maven
- Cucumber
- Node.js
- Git
- Postman (for manual API testing)
-
Clone the repository:
git clone https://github.com/EmrayP/FakeStoreAPI.git
-
Install dependencies:
mvn clean install
-
Configure the base URL in
config.properties:- Open the
config.propertiesfile located in thesrc/main/resourcesdirectory. - Set the
baseURLproperty to the appropriate value:baseURL=https://fakestoreapi.com
- Open the
Run the tests using Maven:
mvn clean test- Open IntelliJ IDEA.
- Navigate to the
src/test/javadirectory in the Project view. - Right-click on the
unitTests.JsonUtilsTestclass. - Select
Run 'JsonUtilsTest'to execute the tests.
- Open a terminal window.
- Navigate to the root directory of your project.
- Run the following command to execute all tests using Maven:
mvn clean test
- Open a terminal window.
- Navigate to the root directory of your project.
- Run the following command to execute all Cucumber feature tests using Maven:
mvn test -Dcucumber.options="src/test/resources/features"
GitHub Actions is configured to run tests based on pull requests (PRs). Whenever a PR happens, GitHub Actions will pick up the code changes.
- Navigate to the Actions tab in the GitHub repository.
- Search for the workflow named
CI: Java CI with Maven-Cucumberto see the test results. - If you want to manually trigger the CI, click the Run workflow button on the right-hand side.
- Navigate to the Actions tab on your GitHub repository.
- Search for the workflow run named
Java CI with Maven-Cucumber. - Click on the run to see the details.
- After the workflow completes, the HTML report will be available under the
gh-pagesbranch.
You can manually test the APIs using the provided Postman collection.
- Open Postman.
- Import the Postman collection
Product Test-FakeStoreAPI.postman_collection.jsonfrom the directory of this repository. - The collection contains requests to test the Fake Store API endpoints.
- Set the API method to
GET. - Click the Send button to run the API requests manually.
- Verify the response data and status code.
To add test scripts in Postman, follow these steps:
- Open the Postman app.
- Go to the
Teststab for a specific request. - Write test scripts to verify requirements.
- Save the request and run it to see the test results.
After running the tests, you can generate Cucumber reports. These reports will be available in the target/Cucumber-Reports directory. After the workflow actions are completed, the pages build and deployment job will run. Under pages build and deployment, you can see the report link. Click on the link to view the report. The report is available at: https://emrayp.github.io/FakeStoreAPI/
After running the tests, Maven will display the test results in the terminal. Look for lines indicating the number of tests run, passed, failed, and skipped.
Example:
[INFO] Results:
[INFO] Tests run: 10, Failures: 0, Errors: 0, Skipped: 0
Maven generates a detailed test report in the target/surefire-reports directory. Open the index.html file in a web browser to view the detailed test results, including:
- Test cases executed
- Pass/fail status
- Error messages and stack traces for any failed tests
Pay attention to the assertions in the test methods. If an assertion fails, it indicates that the expected condition was not met, and the test will fail. Review the assertion messages to understand the cause of the failure.
If any exceptions are thrown during the test execution, they will be logged in the test report. Review the stack traces to identify and fix the issues in the code.
If the artifacts are not getting created, ensure the following:
- The
targetdirectory exists and contains the necessary report files. - The
actions/upload-artifact@v4step is correctly configured. - The
peaceiris/actions-gh-pages@v4step is correctly configured with the correctpublish_dir.
- Make sure the
pom.xmldependencies have the required versions. - You can update the IDE version to get the latest updates.
- Make sure the GitHub Actions workflow file is correctly configured.
- Ensure you have configured the base URL and other necessary configurations in the
config.propertiesfile. - Use the provided Postman collection for manual testing and verification of API endpoints.
- Check the generated Cucumber reports for detailed test execution results and statistics.