This repository contains a Selenium WebDriver script written in Python, designed to test the functionality of the Sauce Demo website. Sauce Demo is a practice e-commerce site specifically created for testing automation tools.
The script demonstrates the use of Selenium for:
- End-to-end web application testing.
- Login validation (valid and invalid credentials).
- Product sorting and validation.
- Cart operations, including adding, removing, and validating items.
- Checkout workflow automation.
- Responsive design testing.
This repository is perfect for learning Selenium automation and understanding how to write robust, reusable test scripts.
- Validates login functionality using correct credentials.
- Tests error handling for invalid credentials.
- Tests sorting options (Name A-Z, Name Z-A, Price Low to High, Price High to Low).
- Validates that the sorting is applied correctly.
- Adds products to the cart.
- Verifies cart contents.
- Removes items from the cart.
- Automates the checkout workflow by filling in user details and completing the order.
- Tests website layout and functionality at various screen resolutions (desktop, tablet, mobile).
To run the script, ensure you have the following installed:
- Python 3.8 or later: Download Python
- Google Chrome: Download Chrome
- pip: Python's package installer, included with Python 3.
Clone this repository to your local machine using:
git clone https://github.com/your-username/python-selenium-web-testing.git
cd python-selenium-web-testingInstall the required Python packages using pip:
pip install -r requirements.txtRun the Selenium test script using:
python test.py- Valid Login: Logs into the website using valid credentials and verifies success.
- Invalid Login: Tests incorrect credentials and validates the error message.
- Sorts products by name and price.
- Extracts and validates sorted product names or prices.
- Adds two products to the cart.
- Validates the number of items in the cart.
- Removes a product and verifies the cart updates correctly.
- Completes the checkout process by filling in user details and submitting the order.
- Adjusts the browser window size to test layouts on desktop, tablet, and mobile resolutions.
sauce_demo_test.py: The main Selenium script containing all test cases.requirements.txt: Lists all Python dependencies required to run the script.screenshots/: (Optional) Folder where screenshots captured during test execution are saved.
The required dependencies are listed in the requirements.txt file:
selenium==4.27.1
webdriver-manager==3.8.6Install them with:
pip install -r requirements.txtScreenshots are automatically captured during the test execution and saved with descriptive filenames. They can be found in the screenshots/ folder (or the current directory if the folder isn't created).
When running the script, you will see outputs like:
- Login Successful: If valid credentials are used.
- Error Message Displayed: If invalid credentials are used.
- Products Sorted by Price: A list of prices will be printed to validate sorting.
- Cart Operations: Confirmation of products added or removed.
- Checkout Successful: Final confirmation after completing the order.
If you'd like to contribute:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Submit a pull request with a detailed explanation.
You are free to copy, modify, and/or distribute as long as for educational purposes only / for practice. Mr-LuaM