Skip to content

killcodeX/Selenium-CSharp-NUnit-Automation-Framework

Repository files navigation

Selenium-CSharp-NUnit-Automation-Framework

E-commerce Test Automation Framework built with Selenium WebDriver, C#, and NUnit using Page Object Model (POM) design pattern.

.NET Selenium NUnit License

๐Ÿ“‹ Table of Contents


๐ŸŽฏ About The Project

This is a robust test automation framework designed to demonstrate best practices in test automation for e-commerce applications. The framework tests the complete user registration flow on AutomationExercise.com including user signup, account creation, and account deletion.

Key Features:

  • โœ… Page Object Model (POM) design pattern
  • โœ… Reusable business flow components
  • โœ… Data-driven testing with random test data generation
  • โœ… Detailed HTML test reports with screenshots
  • โœ… Cross-browser testing support (Chrome, Firefox, Edge)
  • โœ… Parallel test execution capability
  • โœ… Screenshot capture on test failures
  • โœ… CI/CD ready with GitHub Actions

๐Ÿ› ๏ธ Built With

Core Technologies:

  • Language: C# (.NET 6.0)
  • Automation Tool: Selenium WebDriver 4.15
  • Testing Framework: NUnit 3.14
  • Build Tool: MSBuild / Visual Studio 2022
  • Driver Management: WebDriverManager 2.17
  • Reporting: ExtentReports 5.0

๐Ÿ—๏ธ Project Architecture

AutomationExercise/
โ”‚
โ”œโ”€โ”€ ๐Ÿ“‚ Pages/                        # Page Object classes
โ”‚   โ”œโ”€โ”€ BasePage.cs                  # Common page methods
โ”‚   โ”œโ”€โ”€ HomePage.cs                  # Home page interactions
โ”‚   โ”œโ”€โ”€ SignupLoginPage.cs           # Signup/Login page
โ”‚   โ”œโ”€โ”€ SignupPage.cs                # Registration form page
โ”‚   โ”œโ”€โ”€ AccountCreatedPage.cs        # Account success page
โ”‚   โ””โ”€โ”€ AccountDeletedPage.cs        # Account deletion page
โ”‚
โ”œโ”€โ”€ ๐Ÿ“‚ Flows/                        # Business logic flows
โ”‚   โ”œโ”€โ”€ RegistrationFlow.cs         # Complete registration workflow
โ”‚   โ””โ”€โ”€ LoginFlow.cs                 # User login workflow
โ”‚
โ”œโ”€โ”€ ๐Ÿ“‚ Tests/                        # Test cases
โ”‚   โ”œโ”€โ”€ BaseTest.cs                  # Test setup/teardown
โ”‚   โ”œโ”€โ”€ RegistrationTests.cs        # Registration test scenarios
โ”‚   โ””โ”€โ”€ AllTests.cs                  # Main test suite
โ”‚
โ”œโ”€โ”€ ๐Ÿ“‚ Utils/                        # Utility classes
โ”‚   โ”œโ”€โ”€ DriverFactory.cs             # WebDriver initialization
โ”‚   โ”œโ”€โ”€ ConfigReader.cs              # Configuration management
โ”‚   โ”œโ”€โ”€ TestDataGenerator.cs        # Random test data
โ”‚   โ””โ”€โ”€ ScreenshotHelper.cs          # Screenshot utilities
โ”‚
โ”œโ”€โ”€ ๐Ÿ“‚ TestData/                     # Test data models
โ”‚   โ””โ”€โ”€ UserData.cs                  # User data structure
โ”‚
โ”œโ”€โ”€ ๐Ÿ“‚ Reports/                      # Generated test reports
โ”œโ”€โ”€ ๐Ÿ“‚ Screenshots/                  # Failure screenshots
โ”œโ”€โ”€ app.config                       # Application configuration
โ””โ”€โ”€ README.md                        # Project documentation

Design Pattern: Page Object Model (POM)

  • Separates test logic from UI interactions
  • Improves code reusability and maintainability
  • Makes tests more readable and easier to maintain

๐Ÿš€ Getting Started

Prerequisites

  • Visual Studio 2022 or later
  • .NET 6.0 SDK or later
  • Chrome/Firefox/Edge browser installed

Installation

  1. Clone the repository

    git clone https://github.com/YOUR_USERNAME/Selenium-CSharp-NUnit-Automation-Framework.git
    cd Selenium-CSharp-NUnit-Automation-Framework
  2. Open in Visual Studio

    • Open AutomationExercise.sln in Visual Studio
  3. Restore NuGet Packages

    dotnet restore

    Or in Visual Studio: Tools > NuGet Package Manager > Restore NuGet Packages

  4. Build the solution

    dotnet build

Configuration

Edit app.config to customize settings:

<configuration>
  <appSettings>
    <add key="BaseUrl" value="http://automationexercise.com" />
    <add key="Browser" value="Chrome" />
    <add key="ImplicitWait" value="10" />
    <add key="ExplicitWait" value="20" />
    <add key="TakeScreenshotOnFailure" value="true" />
  </appSettings>
</configuration>

๐Ÿ“ Test Cases

Test Case 1: Register User

Scenario: Complete user registration flow

Step Action Expected Result
1 Launch browser Browser opens successfully
2 Navigate to URL Website loads
3 Verify home page Home page is visible
4 Click 'Signup / Login' Navigation successful
5 Verify 'New User Signup!' Text is visible
6 Enter name and email Fields populated
7 Click 'Signup' button Form submits
8 Verify 'ENTER ACCOUNT INFORMATION' Page visible
9 Fill details (Title, Name, Email, Password, DOB) All fields filled
10 Select 'Sign up for newsletter!' Checkbox selected
11 Select 'Receive special offers!' Checkbox selected
12 Fill address details All fields filled
13 Click 'Create Account' Account created
14 Verify 'ACCOUNT CREATED!' Success message shown
15 Click 'Continue' Navigation to logged in state
16 Verify 'Logged in as username' User is logged in
17 Click 'Delete Account' Account deletion initiated
18 Verify 'ACCOUNT DELETED!' Success message shown

โ–ถ๏ธ Running Tests

Run All Tests

dotnet test

Run Specific Test

dotnet test --filter "FullyQualifiedName~RegistrationTests.TestCase1_RegisterUser"

Run by Category

# Run smoke tests
dotnet test --filter TestCategory=Smoke

# Run regression tests
dotnet test --filter TestCategory=Regression

Run with Specific Browser

Modify app.config or pass as parameter:

// In code
DriverFactory.InitDriver("Firefox");

Visual Studio Test Explorer

  1. Open Test Explorer: Test > Test Explorer
  2. Click Run All or right-click specific tests
  3. View results in real-time

๐Ÿ“Š Test Reports

HTML Reports

After test execution, find reports in:

Reports/TestReport_YYYY-MM-DD_HH-MM-SS.html

Report includes:

  • Test execution summary (Pass/Fail/Skip)
  • Detailed step-by-step logs
  • Screenshots for failed tests
  • Execution time for each test
  • Browser and environment details

Screenshots

Failed test screenshots are saved in:

Screenshots/TestName_YYYY-MM-DD_HH-MM-SS.png

โœจ Project Highlights

Why This Framework Stands Out

  1. Industry-Standard Design Pattern

    • Implements Page Object Model for maximum maintainability
    • Separates business logic from test logic
  2. Reusable Components

    • Flow classes enable complex scenario testing
    • DRY (Don't Repeat Yourself) principle throughout
  3. Robust & Reliable

    • Explicit waits prevent flaky tests
    • Screenshot capture for debugging
    • Comprehensive error handling
  4. Scalable Architecture

    • Easy to add new test cases
    • Supports multiple browsers
    • Ready for parallel execution
  5. Professional Reporting

    • Detailed HTML reports with ExtentReports
    • Visual evidence with screenshots
    • Easy to share with stakeholders
  6. CI/CD Ready

    • Can integrate with GitHub Actions
    • Azure DevOps compatible
    • Jenkins pipeline ready

๐Ÿ”ฎ Future Enhancements

  • Integrate with GitHub Actions for CI/CD
  • Add API testing layer
  • Implement Docker containerization
  • Add database validation
  • Cross-browser parallel execution
  • Integrate with Allure reporting
  • Add performance testing metrics
  • Implement BDD with SpecFlow

๐Ÿ“ง Contact

Your Name

Project Link: https://github.com/YOUR_USERNAME/Selenium-CSharp-NUnit-Automation-Framework


๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


๐Ÿ™ Acknowledgments

  • Test scenarios from AutomationExercise.com
  • Selenium WebDriver documentation
  • NUnit framework documentation
  • C# and .NET community

โญ If you found this project helpful, please give it a star!


Made with โค๏ธ by Aaquib Ahmad

About

Selenium-CSharp-NUnit-Automation-Framework

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published