🖋️
QualityMate
  • QualityMate
  • Getting Started
    • Introduction
    • Why QualityMate
    • Architecture
    • Supported Web Browsers
    • Glossary
  • Components
    • UI Player
      • Basic Concepts
      • UiPlayer
      • MSTest Integration
      • Samples
        • QualityMate Sample Desktop
        • QualityMate Sample Web
        • QualityMate MSTest Integration Sample Desktop
        • QualityMate MSTest Integration Sample Web
        • QualityMate Integration with Test Frameworks
        • Web Authentication Sample
      • QualityMate Project Template
    • UI Recorder
      • Basic Concepts
      • Setting Up the Recorder
      • Validating an Element
      • Generating QualityMate Solution
  • Tools
    • File Comparators
    • Image Processor
    • Project Merger
    • Test Case Generator
      • Filters
      • Rename Recorded Controls
  • Basic Concepts
    • Page Object
      • Work Guide
    • Controls
      • Control Types
        • Generic Types
        • Desktop types
        • Web Types
        • WebMap types
          • Kendo PowerBuilder
          • Kendo WinForms
          • Kendo Silverlight
      • Interactions
        • SendKeys
        • Validate
    • Selectors
      • Selectors in Code
      • Default Selector
      • Shared Selector
      • Selectors Category
        • CSS Selector
        • XPath Selector
        • Image Selector
        • Frame Selector
      • Identifying Selector
        • Identify for Windows Desktop
        • Identify for Web
  • How to Guides
    • Setting Up the Configuration
      • Parameters
      • Context
      • Loading External Data
    • Awaiting for the Application
      • Busy Loaders
      • Retries
    • Defining Controls
      • Extending Controls
      • Control Slice
      • Control Collection
    • Logging on Tests
      • QualityMate Reports
      • Logging
  • Help
    • Best Practices
      • Environment
      • Tests
      • Page Objects
      • Validations
      • Interactions
      • Image Comparisons
    • Known Issues
    • Continuous Integration
      • Agents Session
    • Upgrading QualityMate
      • From version 7 to version 8
      • Previous Versions
      • How to switch from TestFeature to UiTest
    • VS Test
      • Command Line
      • Generate Reports
  • API
    • Control Interfaces
      • IButton
      • ICheckBox
      • IComboBox
      • IControl
      • IControlSlice
      • IDateTimePicker
      • IElement
      • IGrid
      • IGroupBox
      • ILabel
      • IListBox
      • IMenu
      • INumericUpDown
      • IPageObject
      • IProgressBar
      • IRadioButton
      • IRadioButtonGroup
      • ISplitButton
      • IStatusStrip
      • ITab
      • ITextBox
      • IToggleButton
      • IToolBar
      • ITreeView
    • Behavior
      • ICheckableControl
      • IList
      • ITextControl
    • Enums
      • ClickType
      • KeyModifiers
      • MouseButton
  • Changelog
    • Changelog
      • Version 8
      • Version 7
      • Version 6
      • Version 5
      • Version 4
      • Version 3
Powered by GitBook
On this page
  • Page object members
  • Responsibility of a page object
  • Complex page objects
  • Inner page object instantiation
  • Using control collections

Was this helpful?

  1. Help
  2. Best Practices

Page Objects

Page object members

❌ Don't: Leave unused members in page objects

Doing this bloats your page objects and makes them harder to navigate.

✔️ Do: Remove unused page object members

If a member in a page object is not used, simply remove it from the page object.

Responsibility of a page object

❌ Don't: Add non-UI code to page objects

Page objects represent an application's view. They are not a controller. Any backend or businness code should be on an appropriate, separate module.

// MyPageObject.cs
public string GetSQLStatement(string param)
{
    // Oh no! SQL in a PageObject!
    return $"UPDATE table SET value = {param} WHERE other_value = 1";
}

✔️ Do: Keep page objects tightly coupled to the UI

Complex page objects

❌ Don't: Have copies of the same page object for different scenarios

This can confuse contributors since they won't know which page object to modify when needed.

[Selector("#MyPageObjectId")]
public class MyPartialPageObject1 : PageObject
{
    public IButton myButton { get; set; }
}

[Selector("#MyPageObjectId")]
public class MyPartialPageObject2 : PageObject
{
    public ITextBox myTextBox { get; set; }
}

If possible, use a single page object per screen or page:

[Selector("#MyPageObjectId")]
public class MyPageObject : PageObject
{
    public IButton myButton { get; set; }
    public ITextBox myTextBox { get; set; }
}

Some screens or pages are too complex to fit in a single page object. If that's the case, they likely have container controls in them: panels, tabs, divs, etc. Split them up per container into smaller page objects and add them as members inside a larger page object. These are called Inner Page Objects:

public class MyPageObject : PageObject
{
    public InnerPageObject InnerPageObject { get; set; }
    public AnotherInnerPageObject AnotherInnerPageObject { get; set; }
}

public class InnerPageObject : PageObject
{
    public IButton myButton { get; set; }
    // more controls...
}

public class AnotherInnerPageObject : PageObject
{
    public ITextBox myTextBox { get; set; }
    // more controls...
}

Inner page object instantiation

❌ Don't: Instantiate inner page objects via the controller

This will result in a duplicate instantiation because inner page objects should instantiate automatically.

public class InnerPageObject : PageObject { }

public class ParentPageObject : PageObject
{
    public InnerPageObject InnerPageObject { get; set; }
    
    // Invoking this method duplicates InnerPageObject's instantiation!
    public void Initialize(UiExecutionController controller)
    {
        this.InnerPageObject = controller.GetPageObject<InnerPageObject>();
    }
}

✔️ Do: Declare inner page objects

All page objects declared as members of a parent page object are instantiated when the parent is.

public class InnerPageObject : PageObject { }

public class ParentPageObject : PageObject
{
    // This will get instantiated alongside ParentPageObject
    public InnerPageObject InnerPageObject { get; set; }
}

Using control collections

❌ Don't: Create control collections from scratch using concrete control implementations

Concrete control implementations can be used to find a control's children. This is used internally by QualityMate and is not intended for clients.

((ElementControl)MyPageObject.MyControl.Controls.First())
        .FindAllControlsFromInterface<IButton>(new Selector("mySelector"));

✔️ Do: Use a Control Collection

Control Collection is a class which allows you to create collections of controls without having to resort to concrete control implementations.

PreviousTestsNextValidations

Last updated 2 years ago

Was this helpful?

Methods in page objects are highly encouraged, but they also should be added carefully. Your page object should respect the by only performing UI operations.

✔️ Do: Use a single

✔️ Do: Split up complex UIs into

Single Responsibility Principle
page object
inner page objects