QualityMate MSTest Integration Sample Desktop

What does this guide cover?

  • Creation of a test solution that integrates QualityMate with MSTest Framework.

  • The proper solution structure that you should use.

  • The QualityMate NuGets that you need.

  • A basic .runsetting parameters file.

  • A simple Page Object and Test Case to run on a Desktop application.

The completed sample solution described in this article can be downloaded here:

Desktop MSTest Integration Sample

Before this guide

This guide assumes that you will use our asset application.

Download Desktop Sample App

Set up your application environment

To create our first Test Case with QualityMate MSTest Integration, we're going to:

  1. Create a test C# project using the .Net Framework version 4.6.1 or higher and name it HelloWorldUiTesting. If you're working on Visual Studio, information on how to do this can be found here.

  2. The test class should be named TC_HelloWorld.cs.

  3. Create an Assets folder inside the project folder.

  4. Decompress the downloaded assets on the Assets folder.

  5. Set the assets files to copy to the output directory. To do this, open your project file (HelloWorldUiTesting.csproj) and add the following lines:

    <ItemGroup>
      <None Update="Assets\*">
        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      </None>
    </ItemGroup>
  6. Create a TestCases folder inside the project folder in which we will save our test class.

  7. Add the Mobilize.QualityMate.UiTesting.MsTest package through the NuGet package manager.

The project folder structure should look like the following example:

🗔 MyFirstSample
 ┣ 📂 HelloWorldUiTesting
 ┃  ┣ 📂 Assets
 ┃  ┣  ┗ 🗔 SampleApp.exe
 ┃  ┣ 📂 TestCases
 ┃  ┣  ┗ 📜 TC_HelloWorld.cs
 ┃  ┗ 📜 HelloWorldUiTesting.csproj
 ┗ 📜 HelloWorldUiTesting.sln

Describe the UI of the target application

It's time to create our first Page Object; we're going to do the following:

  1. Create a folder named PageObjects inside the project folder.

  2. Create a C# class file namedForm1.cs inside the PageObjets folder.

  3. Add the following usings in the Form1.cs file:

    using Mobilize.QualityMate.Automation.Entities;
    using Mobilize.QualityMate.ControlInterfaces;
  4. Create the UI controls that we are going to use on Form1 class like the following:

     // PageObject that describes the UI controls of the asset application.
     public class Form1 : PageObject
     {
         // Describes a TextBox control presented on the asset Application.
         public ITextBox textBox1 { get; set; }
    
         // Describes a Button control presented on the asset Application.
         public IButton button1 { get; set; }
    
         // Describes a Label control presented on the asset Application.
         public ILabel label1 { get; set; }
     }

The fields specified in the code snip above represent each UI control of the assets' application.

Define the configuration parameters

We are going to specify the behavior of QualityMate by doing the following:

  1. Create a MyRunParameters.runsettings file inside the project folder.

  2. Specify the parameters that QualityMate will use as the following example:

     <RunSettings>
         <TestRunParameters>
             <Parameter name="Application" value=".\assets\SampleApp.exe" />
             <Parameter name="Technology" value="Desktop" />
         </TestRunParameters>
     </RunSettings>
  3. Load the MyRunParameters.runsettings file on your IDE. If you're working on Visual Studio, information on how to do this can be found here.

Create a new UI script

Once we have a PageObject, we can create a new QualityMate script on the TC_HelloWorld.cs file:

  1. Add the following using statements in the TC_HelloWorld.cs file:

    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using Mobilize.QualityMate.Automation.Extensions;
    using Mobilize.QualityMate.UiPlayer;
    using Mobilize.QualityMate.UiTesting.MsTest;
  2. The TC_HelloWorld test class should be inherited from UiTest class and has the TestClass attribute.

    [TestClass]
    public class TC_HelloWorld : UiTest
  3. Create the method HelloWorldScript(UiExecutionController controller), this method will let us interact with the UI using the controller with the next code:

     // This method receives an UiExecutionController which is in charge of executing the UI interactions 
     // using our PageObjects.
     private void HelloWorldScript(UiExecutionController controller)
     {
         Form1 form1 = controller.GetPageObject<Form1>();
         form1.textBox1.Text = "Hello World";
         form1.button1.Click();
         form1.label1.Validate(label => label.Text.Equals("Hello World"));
     }
  4. Create a new test method HelloWorld() that will call our script using the UiTest's Execute() method.

         // The TestMethod attribute will run as entry point for VSTest.
         [TestMethod]
         public void HelloWorld()
         {
             this.Execute(HelloWorldScript);
         }

What's next?

Compile the test project and run the test case to see the magic happen. Great isn't it?

Last updated

Was this helpful?