FYI logo

Mastering Selenium C# with NUnit: In-Depth Guide to Page Object Model (POM) and Data Object Model (DOM)

NUnit Page Object Model (POM) & Data Object Model (DOM) - Selenium with C#

By Jignect TechnologiesPublished about a year ago 5 min read

In this fast changing software development environment, application reliability and quality can only be ensured by efficient test automation solutions that scale well. Selenium is an open-source tool for automating browser interactions. It is very flexible in terms of usage because one may choose to use any language like C# along with it and thus has become much-needed for the automation framework. However, increased complexity in applications makes it difficult to maintain the robust framework of automation.

Such complexities are addressed by the powerful use of design patterns like Page Object Model and Data Object Model, which prove extremely advantageous in organizing the test code for maximum efficiency without much redundancy. The Page Object Model is a design approach where it structures the test code so that test scripts are segregated from the application’s UI elements, encapsulating each page’s structure and behavior into dedicated classes. This allows QA teams to control page interactions by themselves, and tests become more readable, maintainable, and flexible with UI changes.

Data Object Model (DOM) is an extension of POM that separates test data from test logic for facilitating easy input management and testing usability of various scenarios. Its structure is suitable for huge projects where huge quantities of data are being handled and many variants are supported; it makes the testers easily reuse their test logic with various different sets of data.

We’ll show you how to implement POM and DOM using Selenium with C# from setup to best practices and concrete examples. Understanding these patterns will give you the power to design an automation framework that scales well across its needs when your tests are at once simple and robust.

🎯Understanding POM and DOM

What is the Page Object Model (POM)?

Page Object Model (POM) is a design pattern for test automation wherein a different class or “Page Object” is created for every web page in an application. Every page object can be considered as an abstraction layer that encapsulates the page’s structure or locators and the behavior of the page or methods or actions by which any user could perform on that specific page.

Key Features of POM:

Abstraction of UI Elements: Having elements and actions defined in separate classes maintains the cleanliness of test scripts, which are basically focused on test logic rather than low-level details about the structure of the page.

Modularity: A different class for each web page means testing for each web page can be done independently, especially when UI changes are perceived.

Code Reusability: Methods that interact with specific elements can be reused by several tests without duplication.

Read and Maintainability: Tests are much easier to read and maintain because the page structure is abstracted from the test’s logic. Changes in the UI have to be updated only in one place.

Example of a POM Class for a Login Page in C#:

using OpenQA.Selenium;

public class LoginPage

{

private readonly IWebDriver driver;

private readonly By usernameField = By.Id("username");

private readonly By passwordField = By.Id("password");

private readonly By loginButton = By.Id("login");

public LoginPage(IWebDriver driver)

{

this.driver = driver;

}

public void EnterUsername(string username)

{

driver.FindElement(usernameField).SendKeys(username);

}

public void EnterPassword(string password)

{

driver.FindElement(passwordField).SendKeys(password);

}

public void ClickLoginButton()

{

driver.FindElement(loginButton).Click();

}

}

In this example, the LoginPage class has specific methods to interact with the login page, making it easy to call EnterUsername, EnterPassword, and ClickLoginButton within test scripts without handling the low-level details of element locators.

What is the Data Object Model (DOM)?

Data Object Model (DOM) is a data interface with programming language-related technologies. Another design pattern for test automation is the Data Object Model. The test data here is separated from the logic for the test. It means that in DOM, test data will be stored in a structured format to enable data-driven tests. DOM enables testers to create versatile, reusable tests by storing inputs and expected outputs externally in files (e.g., JSON, CSV, XML, databases) rather than hardcoding them within test scripts.

Benefits of DOM:

Data-Driven Testing: DOM makes it easy to run tests with multiple data sets, supporting broader test coverage and scenario variation.

Simplifies Data Management: Test data is centralized and organized, making it easy to update or modify data without altering the test scripts.

Reusability and Scalability: DOM supports test reusability across different scenarios and environments, especially useful for applications with complex data inputs.

Example of Data-Driven Testing with NUnit and DOM in C#:

[Test, TestCaseSource("LoginData")]

public void TestLogin(string username, string password)

{

var loginPage = new LoginPage(_driver);

loginPage.EnterUsername(username);

loginPage.EnterPassword(password);

loginPage.ClickLoginButton();

Assert.IsTrue(IsLoggedIn());

}

public static IEnumerable<TestCaseData> LoginData()

{

yield return new TestCaseData("user1", "pass1");

yield return new TestCaseData("user2", "pass2");

}

Here, LoginData provides different sets of usernames and passwords, allowing the test to validate the login functionality across multiple scenarios without changing the code in TestLogin.

Why POM and DOM are Essential for Test Automation?

POM and DOM are absolutely necessary for the development of a robust, maintainable test automation framework. They offer modularity, scalability, and reusability for making the entire process of automated test development much more efficient and reliable. Here’s why each pattern is essential:

Modularity and Separation of Concerns: POM helps separate test scripts from the UI elements of the application. Similarly, DOM separates data from the test scripts. This separation reduces the impact of application changes on the test suite and centralizes changes.

Maintainability: Both POM and DOM reduce the need to modify multiple tests when UI or data changes occur. POM isolates changes within the page classes, while DOM centralizes data updates.

Reusability: POM allows testers to reuse page classes across different tests, while DOM enables the reuse of data across test scenarios. This reduces redundancy and speeds up the test creation process.

Enhanced Readability and Collaboration: By following these patterns, automation code is easier to read, update, and understand, making it accessible to both developers and testers. This also enables better collaboration and integration in agile environments.

Together, POM and DOM form the foundation of a scalable, maintainable test automation framework. By adopting these patterns, teams can build flexible test suites that adapt quickly to application changes and support a wide range of test scenarios.

Setting Up Your Environment

For setting up Selenium C#, you can refer to our Selenium C# blog, which covers everything from installation to configuration, ensuring you’re ready to start building robust automation tests in no time.

Read more about In-Depth Guide to Page Object Model (POM) and Data Object Model (DOM).

Science

About the Creator

Jignect Technologies

At JigNect Technologies, we believe that software testing is an art, a science, and a passion. Our team of experts combines years of experience, cutting-edge technology.

Reader insights

Be the first to share your insights about this piece.

How does it work?

Add your insights

Comments (1)

Sign in to comment
  • Dharrsheena Raja Segarranabout a year ago

    Hey, just wanna let you know that this is more suitable to be posted in the 01 community 😊

Find us on social media

Miscellaneous links

  • Explore
  • Contact
  • Privacy Policy
  • Terms of Use
  • Support

© 2026 Creatd, Inc. All Rights Reserved.