This project implements a Page Object Model (POM) structure and Data Driven Testing Framework for automated testing of the Swag Labs.
Website Link: https://www.saucedemo.com/
The objective of this project is to implement an automated testing framework for the Swag Labs web application using Python Selenium. The primary goals are to:
- Validate Functionalities: Ensure the core functionalities of the Swag Labs platform (such as navigation, login, randomly adding to the cart, and checkout processes) work as expected.
- Improve Test Maintenance: Utilize a structured approach to separate web page interaction logic from test scripts, making it easier to maintain and extend as the application evolves.
- Enhance Test Reusability: Promote reusability of code for interactions with page elements, reducing duplication across test scripts.
- Support Data-Driven Testing: Leverage test data (stored in
TestData/data.py
andTestData/testdata.xlsx
) to run multiple test scenarios with different input sets to verify robustness and edge case handling. - Increase Test Coverage: Automate critical paths such as user authentication, button functionality, and error handling to ensure high test coverage across essential user flows.
- Ensure Browser Compatibility: Run tests across multiple browsers (e.g., Chrome, Firefox, Edge, Safari) to validate cross-browser compatibility and identify potential issues.
- Enable Continuous Testing: Integrate with continuous integration (CI) tools to run tests automatically, ensuring that new changes do not introduce regressions or break existing functionality.
By achieving these objectives, this project aims to create a robust, maintainable, and scalable test automation framework for the Swag Labs platform.
- Test whether you can log in using the usernames
standard_user
,problem_user
,performance_glitch_user
, andlocked_out_user
with the passwordsecret_sauce
. - Verify login success using cookies only.
- Test whether you can log in using the username
guvi_user
and passwordSecret@123
.
- Test whether the Logout button is functioning.
- Test whether the Logout button is visible.
- Test whether the Cart button is visible.
- There are six products mentioned in the inventory. Choose any four products out of the six randomly using Python. Write Python code to get four products randomly. Do not manually fetch the products.
- Fetch the product names and prices.
- Randomly choose four products out of the six mentioned in the inventory using Python. Do not manually fetch the products.
- Add the four products to the cart.
- Verify that the cart button reflects the four products added.
- Click the cart button to verify the products you have added.
- Fetch the product details from the cart.
- Click the checkout button, add your details (First Name, Last Name, and Pin Code/Zip Code) into the given input boxes, and click the Continue button.
- Download a screenshot of the Checkout Overview in PNG/JPEG/JPG format.
- Verify that the products and their details on the page match the products you added.
- Press the Finish button and confirm your action.
- Page Object Model (POM): Separation of test logic and UI interactions. Each web page has its corresponding class defining methods for interacting with the elements on that page.
- Pytest Framework: Used to manage test cases, execute tests, and generate detailed reports.
- Reusable Components: Common actions like login, navigating to sections, and performing shutdown operations are encapsulated in reusable methods, improving maintainability.
- Cross-Platform Compatibility: The framework can be run across different environments, supporting various operating systems and web browsers.
- Automation and Reporting: Automates repetitive tests with detailed reports on test results, making it easier to monitor and debug test executions.
- Programming Language: Python
- Modules: random
- Test Framework: pytest and DDT
- Automation Tool: Selenium WebDriver
- Reporting: pytest-html
- Browser Compatibility: Microsoft Edge, Google Chrome, Mozilla Firefox, Safari
- CI/CD Integration: GitHub Actions
To set up and run this project locally, follow these steps:
-
Clone the Repository:
git clone https://github.com/imranc07/Capstone_Project.git cd Capstone_Project
-
Create a Virtual Environment (optional but recommended):
python3 -m venv env source env/bin/activate # For Windows, use `env\Scripts\activate`
-
Install Dependencies:
pip install -r requirements.txt
-
Set Up Environment Variables:
- Create a
.env
file in the root directory to store sensitive information such as login credentials and URLs. Example:BASE_URL=https://example.com USER_EMAIL=test@example.com USER_PASSWORD=yourpassword
- Create a
To execute tests, use the following commands:
-
Run All Tests:
pytest
-
Generate HTML Report:
pytest --html=Reports/test_report.html
-
Run Tests by Marker (e.g., only "login" tests):
pytest TestScripts/test_04_CartPage.py::test_add_to_cart
-
Headless Browser Execution:
- Set up tests to run in headless mode directly in your test script.
Capstone_Project/
│
├── PageObjects/ # Contains Page Object Models for Swag Labs Web Application
│ ├── LoginPage.py # Handles methods and elements for Login Page
│ ├── InventoryPage.py # Handles methods and elements for Inventory Page
│ ├── CartPage.py # Handles methods and elements for Cart Page
│ └── CheckoutPage.py # Handles methods and elements for Checkout Page
│
├── Reports/ # Contains HTML reports
│ └── test_report.html # HTML reports generated by pytest
│
├── TestData/ # Stores test data for the test cases
│ ├── data.py # Contains reusable test data
│ └── testdata.xlsx # Contains reusable test data and test log
│
├── TestLocators/ # Stores locators for web elements
│ └── locators.py # Contains locators for all web elements used in the tests
│
├── TestScripts/ # Contains all test cases
│ ├── test_01_Login.py # Test script for data-driven login functionality
│ ├── test_02_LoginPage.py # Test cases for Swag Labs Login Page
│ ├── test_03_InventoryPage.py # Test cases for Swag Labs Home Page
│ ├── test_04_CartPage.py # Test cases for Swag Labs Cart Page
│ └── test_05_CheckoutPage.py # Test cases for Swag Labs Checkout Page
│
├── Utilities/ # Contains utility files
│ └── excel_functions.py # Script with functions for handling and testing Excel operations
│
├── requirements.txt # Lists project dependencies
│
└── README.md # Project documentation
This project is open-source and available under the MIT License.
Feel free to adjust the content based on your specific project setup!