🖋️
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
  • Replacing text on a control
  • Repeated step sequences
  • Awaiting for the application to respond
  • Finding child controls

Was this helpful?

  1. Help
  2. Best Practices

Interactions

Replacing text on a control

❌ Don't: Select and replace text with a double click

Emulating what the end user would do is a good practice, but QualityMate already performs similar steps under the hood and these are therefore not necessary.

PageObject.TextBox.Click(MouseButton.Left, ClickType.Single);
PageObject.TextBox.Click(MouseButton.Left, ClickType.Double);
PageObject.TextBox.SendKeys("Hello World");

✔️ Do: Use the control's Text property

Setting the control's Text property will yield the same result and be significantly more readable.

PageObject.TextBox.Text = "Hello World";

✔️ Do: Select and SendKeys in masked text boxes

For masked text box uses the SendKeys method instead of Text property. Remember to select the entire text before sending the keys.

PageObject.MaskedTextBox.SendKeys("[" + Keys.CTRL + "a]"); // Select all the text
PageObject.MaskedTextBox.SendKeys("maskedtext");

Repeated step sequences

❌ Don't: Repeat step sequences in code

PageObject.NameTextBox.Text = "Hello";
PageObject.LastNameTextBox.Text = "World";
PageObject.Button.Click();

// elsewhere in the code

PageObject.NameTextBox.Text = "Hola";
PageObject.LastNameTextBox.Text = "Mundo";
PageObject.Button.Click();

✔️ Do: Abstract repeated steps into page objects

If a repeated sequence of steps makes use of a single PageObject, that functionality should be moved into the PageObject:

// PageObject.cs
public void FillForm(string name, string lastName)
{
    this.NameTextBox.Text = name;
    this.LastNameTextBox.Text = lastName;
    this.Button.Click();
}

✔️ Do: Abstract repeated steps into a private method

If you repeat steps within the same test case file, abstract them into a private method in that test case's class:

// TestCaseFile.cs
private void TestCaseScript(UiExecutionController controller)
{
    string fullUserName = this.GetFullUserName(controller);
}

private void Login(UiExecutionController controller)
{
    string fullUserName = this.GetFullUserName(controller);
}

private string GetFullUserName(UiExecutionController controller)
{
    // code which obtains the full user name
}

✔️ Do: Create a utility class with commonly used steps

If a repeated sequence makes use of multiple PageObjects in multiple test case files, abstract them into a static utilities class with a static public method with the repeated steps:

// TestCaseFile.cs
private void TestCaseScript(UiExecutionController controller)
{
    string fullUserName = TestUtils.GetFullUserName(controller);
}

// TestCaseFile2.cs
private void AnotherTestCaseScript(UiExecutionController controller)
{
    string fullUserName = TestUtils.GetFullUserName(controller);
}

// TestUtils.cs
public static string GetFullUserName(UiExecutionController controller)
{
    // code which obtains the full user name
}

Awaiting for the application to respond

❌ Don't: Use System.Threading.Thread.Sleep

Thread.Sleep is not necessary in QualityMate. It will slow down the execution of your tests and make them fragile because you're not guaranteed that the application will be in the expected state after awaiting.

Thread.Sleep(5000);
PageObject.Button.Click();

❌ Don't: Use a try / catch to retry failed steps

Retrying with a try / catch clause causes code duplication and unnecessary verbosity.

try
{
    PageObject.Button.Click();
}
catch
{
    PageObject.Button.Click();
}

✔️ Do: Simply use the framework

// this will re-attempt to perform the Click and Validate until:
// - they work
// - one of the steps times out
PageObject.Button.Click();
PageObject.Button.Validate(self => self.Text == "Hello");

✔️ Do: Adjust the step and execution timeouts

Retrying in QualityMate doesn't happen forever. Steps and tests timeout according to the StepTimeoutand ExecutionTimeout configuration parameters respectively. You can find more information about how to set these on Setting Up the Configuration.

✔️ Do: Use the Retry static class

If you must await on code that's not an interaction or a validation, use the Retry static class. You can find more information about it on Retries.

Finding child controls

❌ Don't: Cast to a concrete implementation and use concrete methods

Casting a control to it's concrete implementation defeats the purpose of QualityMate: you'll have to modify that code upon changing technologies. Concrete control implementations are not meant to be used by clients.

// this will break on a technology that doesn't support ConcreteControl
Selector selector = new("#label_selector");
(parentControl as ConcreteControl).FindControl(selector);

✔️ Do: Use the Find method

The IElement.Find method has the same functionality as casting to a concrete implementation without requiring a cast. Most control interfaces in QualityMate implement IElement.

// parentControl is a Control which implements IElement
ILabel label = parentControl.Find<ILabel>("#label_selector");
PreviousValidationsNextImage Comparisons

Last updated 2 years ago

Was this helpful?

Repeated code is bug-prone and difficult to maintain.

Control interactions and validations have .

Don't repeat yourself.
built-in retrying