End-to-End Test Case: Automating E-Commerce Website Checkout

 End-to-End Test Case: Automating E-Commerce Website Checkout

Test Case Overview

Objective:

Verify that a user can successfully complete the checkout process from adding a product to the cart through payment and order confirmation.


Test Type:

End-to-End (E2E) Automated Test


Test Tools (example):


Selenium WebDriver (for browser automation)


Test framework: Jest, Mocha, or NUnit


Language: JavaScript, Python, C#, etc.


Preconditions

User has a valid account or the site supports guest checkout.


Products exist in the catalog.


Payment gateway is accessible (can be mocked/stubbed in test environments).


Test environment is stable.


Test Steps

Step No Action Expected Result

1 Navigate to the homepage Homepage loads successfully

2 Search for a specific product (e.g., “Wireless Mouse”) Product list displays relevant items

3 Select the desired product from the list Product details page loads with correct info

4 Click “Add to Cart” Product is added to the shopping cart

5 Open the shopping cart Cart shows the correct product and quantity

6 Proceed to checkout Checkout page loads with order summary

7 Enter shipping details (name, address, phone) Details are accepted without errors

8 Select shipping method Selected method updates order summary

9 Enter payment information (card number, expiry, CVV) Payment info accepted (or mocked)

10 Review order and click “Place Order” Order confirmation page appears with order number

11 Verify order confirmation details Correct product, price, shipping, and payment info shown


Sample Selenium WebDriver (JavaScript) Code Snippet

javascript

Copy

Edit

const { Builder, By, until } = require('selenium-webdriver');


(async function checkoutTest() {

  let driver = await new Builder().forBrowser('chrome').build();


  try {

    // Step 1: Go to homepage

    await driver.get('https://example-ecommerce.com');


    // Step 2: Search product

    let searchBox = await driver.findElement(By.name('search'));

    await searchBox.sendKeys('Wireless Mouse');

    await driver.findElement(By.css('button.search-button')).click();


    // Wait for product list

    await driver.wait(until.elementLocated(By.css('.product-item')), 5000);


    // Step 3: Select product

    await driver.findElement(By.css('.product-item a')).click();


    // Step 4: Add to cart

    await driver.wait(until.elementLocated(By.id('add-to-cart')), 5000);

    await driver.findElement(By.id('add-to-cart')).click();


    // Step 5: Open cart

    await driver.findElement(By.id('cart-icon')).click();


    // Step 6: Proceed to checkout

    await driver.findElement(By.id('checkout-button')).click();


    // Step 7: Enter shipping details

    await driver.findElement(By.name('fullname')).sendKeys('John Doe');

    await driver.findElement(By.name('address')).sendKeys('123 Elm Street');

    await driver.findElement(By.name('phone')).sendKeys('1234567890');


    // Step 8: Select shipping method

    await driver.findElement(By.id('shipping-standard')).click();


    // Step 9: Enter payment info (mocked example)

    await driver.findElement(By.name('cardnumber')).sendKeys('4111111111111111');

    await driver.findElement(By.name('expiry')).sendKeys('12/26');

    await driver.findElement(By.name('cvv')).sendKeys('123');


    // Step 10: Place order

    await driver.findElement(By.id('place-order')).click();


    // Step 11: Verify confirmation

    await driver.wait(until.elementLocated(By.id('order-confirmation')), 5000);

    let confirmationText = await driver.findElement(By.id('order-confirmation')).getText();

    console.log(confirmationText.includes('Order Number') ? 'Test Passed' : 'Test Failed');


  } finally {

    await driver.quit();

  }

})();

Additional Tips

Use test data management to reset environment state between runs.


Mock external services like payment gateways for stability.


Add assertions after each step to verify intermediate states.


Implement retries and waits for elements to load asynchronously.


Run tests in headless mode for CI/CD pipelines.

Learn Selenium Python Training in Hyderabad

Read More

πŸ“ˆ Advanced & Real-World Use Cases

Integrating Selenium Tests with Jenkins for CI/CD

Parallel Test Execution using pytest-xdist and Selenium

Building a Page Object Model (POM) in Python

Visit Our Quality Thought Training in Hyderabad

Get Directions


Comments

Popular posts from this blog

Understanding Snowflake Editions: Standard, Enterprise, Business Critical

Installing Tosca: Step-by-Step Guide for Beginners

Why Data Science Course?