Creation of a basic application using QualityMate on a web browser.
The proper solution structure that you should use.
The QualityMate NuGets that you need.
A simple Page Object and application to run in a web browser.
The completed sample solution described in this article can be downloaded here:
Before this guide
This guide assumes that you will use our asset application.
Set up your application environment
To create our first Application with QualityMate, we're going to:
Create a console C# project using the .Net Framework version 4.6.1 or higher and name it HelloWorldUiPlayer. If you're working on Visual Studio, information on how to do this can be found here.
Create an Assets folder inside the project folder.
Decompress the downloaded asset in the Assets folder.
Set the assets files to copy to the output directory. To do this, open your project file (HelloWorldUiPlayer.csproj) and add the following lines:
It's time to create our first Page Object; we're going to do the following:
Create a folder named PageObjects inside the project folder.
Create a Form1.cs file inside the PageObjets folder.
Add the following usings in the Form1.cs file:
using Mobilize.QualityMate.Automation.Entities;
using Mobilize.QualityMate.ControlInterfaces;
Create the UI controls that we are going to use on Form1 class like the following:
usingMobilize.QualityMate.Automation.Entities;usingMobilize.QualityMate.ControlInterfaces; // PageObject that describes the UI controls of the asset application.publicclassForm1:PageObject { // Describes a TextBox control presented on the asset Application.publicITextBox textBox1 { get; set; } // Describes a Button control presented on the asset Application.publicIButton button1 { get; set; } // Describes a Label control presented on the asset Application.publicILabel label1 { get; set; } }
The fields specified in the code snip above represent each UI control of the assets' application.
Create a new UI script
Once we have a PageObject, we can create a new QualityMate script:
Create a HelloWorld.cs file inside the application folder.
Add the following using statements in the HelloWorld.cs file:
using Mobilize.QualityMate.Automation;
using Mobilize.QualityMate.Automation.Configuration;
using Mobilize.QualityMate.Automation.Extensions;
using Mobilize.QualityMate.UiPlayer;
Create the class HelloWorld that will contain our execution script.
Create a UiPlayerConfiguration property inside that class that will hold the UiPlayer parameters.
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.privatevoidHelloWorldScript(UiExecutionController controller) {Form1 form1 =controller.GetPageObject<Form1>();form1.textBox1.Text="Hello World";form1.button1.Click();form1.label1.Validate(label =>label.Text.Equals("Hello World")); }
Create the method ExecuteHelloWorld(), we're going to use this method to start the UiPlayer like the following example:
publicboolExecuteHelloWorld() { // We pass the UiPlayerConfiguration and a function with the UiPlayer script.UiExecutionResult result =UiPlayer.Instance.Execute(configuration, HelloWorldScript);returnresult.Success; }
Run the application
On the Main() function create a new HelloWorld object to call the method ExecuteHelloWorld
publicstaticvoidMain(string[] args) {bool result;string resultString;HelloWorld myUiPlayerClass =newHelloWorld();Console.WriteLine("Starting UiPlayer"); result =myUiPlayerClass.ExecuteHelloWorld(); resultString = result ?"success":"fail";Console.WriteLine($"UiPlayer execution finished with status: {resultString}");Console.ReadLine(); }
Finally, launch the application and see the magic happen. Great isn't it?