Web Automation Testing : Comprehensive Guide to Testing an E-Commerce Website




By Next SolutionLab on 2024-10-23 05:41:22

Overview

This guide provides a detailed, step-by-step approach to E-Commerce Automation Testing for the Demoblaze website using Python and Selenium, with support for manual testing via Excel. The goal is to ensure a seamless shopping experience for users and validate the website's performance throughout its development lifecycle, from initial development to production deployment. This testing suite covers everything from user authentication to purchase completion, ensuring that all features work as expected. 

Project Description  

Demoblaze is an e-commerce platform offering a variety of products in categories like phones, laptops, and monitors. The E-Commerce Automation Testing suite is designed to validate the functionality and user experience of this platform throughout its development. The platform’s open-source nature allows for comprehensive testing, including UI (User Interface) automation, API (Application Programming Interface) testing, and manual testing through Excel.

Key Features of the Demoblaze E-Commerce Website:

User Authentication: A process that verifies a user's identity by checking the provided username and password. This allows users to log into their accounts securely.

Product Categories: The website is organized into three main product categories: Phones, Laptops, and Monitors, making it easier for users to find what they need.

Shopping Experience:

                A. After logging in, users can:

                          1. Browse products across categories.

                          2. Add items to their cart for purchase.

                          3. Complete an order form with payment and shipping details.

                          4. Finalize purchases with a confirmation of their order.

Core Technologies Used

Python: A high-level programming language known for its readability and versatility. It is used here to write automation scripts for testing.

Selenium: A tool for automating web browsers, enabling us to simulate user actions like clicking, typing, and navigating web pages.

Pytest: A testing framework for Python that makes it easy to write simple and scalable test cases. It supports fixtures and parameterized testing.

Allure: A framework for generating test reports. It visualizes the results of test executions in a readable format, making it easier to understand what has passed or failed.

Webdriver-manager: A utility that automatically manages browser drivers (e.g., ChromeDriver for Google Chrome), simplifying the setup for running Selenium tests.

Requests: A Python library for sending HTTP requests, useful for testing the backend APIs of web applications.

Excel: Utilized for manual testing and tracking test cases, especially when dealing with non-automatable scenarios or data validation.

Project Structure

The project is organized into two main directories:

                   1 . WEB (containing 5 subdirectories)

                   2. API (containing 2 subdirectories)

Diagram

The General Flow Chart Diagram for the Overall Project

Pages to be automated :

Welcome Page :

Demoblaze Homepage


Sign Up Page


Log In Page

Contact Page

Product Page

Cart Page

Place Order page


Confirmation page 

Step-by-Step Guide to Running Tests

Step 1: Set Up the Environment

Clone the Repository:

git clone https://github.com/kazalbrur/Demoblaze_Selenium_API_Web_Testing.git
cd Demoblaze_Selenium_API_Web_Testing

Install Dependencies:

pip install -r requirements.txt

This will install necessary packages like selenium, pytest, requests, allure, and more.

Step 2: Web Testing with Selenium

The Web directory contains tests for UI interactions on the Demoblaze website.

Navigate to the Web Tests Directory:

cd Web/tests

Test Case 1 : User Login - Validates user login functionality.

def test_user_login(setup):
    login_page = LoginPage(setup)
    login_page.login("testuser", "password")
    assert "Welcome" in setup.page_source

Run the test:

pytest test_login.py --html=report.html

Test Case 2: Adding Products to Cart - Adds a product and verifies it appears in the cart.

def test_add_product_to_cart(setup):
    product_page = ProductPage(setup)
    product_page.select_product("Samsung galaxy s6")
    product_page.add_to_cart()
    assert "Product added" in setup.page_source

Run the test:

pytest test_add_product_to_cart.py --html=report.html

Step 3: API Testing

The API directory focuses on backend validation using the requests library.

Navigate to the API Tests Directory:

cd API/tests

Test Case 3: Get Products List - Fetches product data from the API.

def test_get_products():
    response = requests.get("https://www.demoblaze.com/api/products")
    assert response.status_code == 200
    assert len(response.json()["items"]) > 0

Run the test:

pytest test_get_products.py

Test Case 4: Add a New Order - Places an order via the API.

def test_add_order():
    order_data = {
        "user_id": "12345",
        "product_id": "2",
        "quantity": 1,
        "total_price": 299
    }
    response = requests.post("https://www.demoblaze.com/api/orders", json=order_data)
    assert response.status_code == 201

Run the test:

pytest test_add_order.py

 

Step 4: Generate and View Allure Reports

Run Tests with Allure Results:

pytest --alluredir=/tmp/my_allure_results

Generate and Serve the Allure Report:

allure serve /tmp/my_allure_results

This will open a browser window displaying a detailed report of your test results, including passed, failed, and skipped tests.

Allure Report

 

Step 5: Continuous Integration with GitHub Actions

Automate test execution using GitHub Actions:

Create a Workflow File.github/workflows/ci.yml

name: Run Tests

on:
  push:
    branches:
      - master

jobs:
  test:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout code
      uses: actions/checkout@v2

    - name: Set up Python
      uses: actions/setup-python@v2
      with:
        python-version: 3.x

    - name: Install dependencies
      run: pip install -r requirements.txt

    - name: Run tests
      run: pytest --alluredir=/tmp/my_allure_results

Push the Workflow to GitHub:

git add .github/workflows/ci.yml
git commit -m "Add CI with GitHub Actions"
git push origin master

This configuration will run tests automatically on each push to the master branch.

Step 6: Manual Testing with Excel

For tracking manual tests or maintaining test case data, use Excel sheets to record:

Test Case IDs: Unique identifiers for each manual test.

Steps: Detailed steps to execute.

Expected vs. Actual Results: Record results and discrepancies.

Status: Pass/Fail status.

This is especially useful for non-automated test scenarios or when performing regression testing.

Step 7: Best Practices for Automation

Follow the Page Object Model (POM) for better code organization.

Keep API and UI tests separate for clarity and maintainability.

Parameterize Tests with pytest to test multiple data inputs.

Leverage CI/CD to maintain code quality with every update.

Capture Screenshots for debugging failed test cases.

Conclusion

The Demoblaze Python Final Project is a robust framework for automating tests for a dynamic web application. It leverages the power of Selenium for UI testing, requests for API validation, and Pytest for structured test cases. With Allure for reports and GitHub Actions for automation, it ensures a seamless and reliable testing process.

This guide helps you set up, execute, and analyze tests, providing a solid foundation for building automated testing solutions. Adapt the provided steps and scripts to suit your specific project needs, and enjoy the journey of creating high-quality software!

Let us know your interest

At Next Solution Lab, we are dedicated to transforming experiences through innovative solutions. If you are interested in learning more about how our projects can benefit your organization.

Contact Us