Selenium C# Automation with ChromeDriver

Module: Complete Selenium Automation using ChromeDriver in C#

This guide takes you step-by-step through downloading ChromeDriver, setting up a Selenium project in Visual Studio using NUnit, automating actions on the OrangeHRMS demo site, and generating test reports. No prior coding or test automation experience required.


1. Download ChromeDriver

  • Open https://chromedriver.chromium.org/downloads
  • Find your current Chrome version: Open Chrome → 3-dot menu → Help → About Google Chrome
  • Download the matching version of ChromeDriver ZIP file
  • Extract and place the chromedriver.exe file into a known location (e.g., C:\WebDrivers)

2. Install Visual Studio and Create Project

Step-by-Step:
  • Install Visual Studio 2022
  • Choose .NET desktop development during installation
  • After opening Visual Studio → Create New Project → Choose NUnit Test Project (.NET Core)
  • Project Name: OrangeHRMSAutomation

3. Add Selenium and Reporting Packages

Right-click the project → Manage NuGet Packages → Install:
  • Selenium.WebDriver
  • Selenium.WebDriver.ChromeDriver
  • NUnit (if not already added)
  • ExtentReports for HTML reporting: ExtentReports.Core

4. Set Up Basic Selenium Test

Create a test class LoginTest.cs:

using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using AventStack.ExtentReports;
using AventStack.ExtentReports.Reporter;

namespace OrangeHRMSAutomation
{
    public class LoginTest
    {
        IWebDriver driver;
        ExtentReports extent;
        ExtentTest test;

        [OneTimeSetUp]
        public void SetupReporting()
        {
            var htmlReporter = new ExtentHtmlReporter("TestReport.html");
            extent = new ExtentReports();
            extent.AttachReporter(htmlReporter);
        }

        [SetUp]
        public void StartBrowser()
        {
            driver = new ChromeDriver(@"C:\WebDrivers"); // Update path
            driver.Manage().Window.Maximize();
            driver.Navigate().GoToUrl("https://opensource-demo.orangehrmlive.com/");
        }

        [Test]
        public void LoginToOrangeHRMS()
        {
            test = extent.CreateTest("Login Test").Info("Test Started");

            try
            {
                driver.FindElement(By.Name("username")).SendKeys("Admin");
                driver.FindElement(By.Name("password")).SendKeys("admin123");
                driver.FindElement(By.CssSelector("button[type='submit']")).Click();

                Assert.IsTrue(driver.Url.Contains("dashboard"));
                test.Pass("Login successful");
            }
            catch (Exception ex)
            {
                test.Fail("Test failed: " + ex.Message);
                throw;
            }
        }

        [TearDown]
        public void EndTest()
        {
            driver.Quit();
        }

        [OneTimeTearDown]
        public void GenerateReport()
        {
            extent.Flush();
        }
    }
}
    

5. Run Your Test

From Visual Studio:
  • Open Test Explorer (View → Test Explorer)
  • Build your solution
  • Click Run All
💡 After the test runs, check your project folder for TestReport.html. Open it in a browser to view a detailed report.

6. Add More Tests: Add New Employee (Example)

Continue recording actions using Chrome → Inspect → Copy Locators
  • Click Admin → Users → Add
  • Fill user details
  • Click Save

Use the same approach in a new test method.


7. Page Object Model (Bonus)

  • Create a separate class for each page (e.g., LoginPage.cs)
  • Define methods like Login() and reuse them across test classes
  • Makes your tests modular, reusable, and maintainable

8. Summary

  • ✅ Downloaded ChromeDriver and configured it
  • ✅ Set up Selenium in Visual Studio using NUnit
  • ✅ Automated login to OrangeHRMS
  • ✅ Generated professional HTML test reports
  • ✅ Learned how to expand and modularize test cases