How to switch from TestFeature to UiTest

Change the inheritance from TestFeature to UiTest.

Before:

public class MyTest : TestFeature 
{    
}

After:

public class MyTest : UiTest 
{    
}

Change from RunScenario to Execute method

Before:

this.RunScenario(given => this.FirstStep(), then => this.SecondStep());

After:

this.Execute(this.TestCaseSteps);

The Execute method receives a delegate, this means that it can be a lambda or another method with an UiExecutionController as a parameter. If you have multiple steps in RunScenario these can be passed to a new method like this:

public void TestCaseSteps(UiExecutionController controller)
{
    this.FirstStep(controller);
    this.SecondStep(controller);
}

Change how to get the Page Objects

Now the methods need to explicitly receive an UiExecutionController as a parameter. This object is used to call the GetPageObject method. As follows:

Before:

private void FirstStep()
{
    MyPageObject myPageObject = this.GetView<MyPageObject>();
    myPageObject.ListBox.ClickItem("item2");
}

After:

private void FirstStep(UiExecutionController controller)
{
    MyPageObject myPageObject = controller.GetPageObject<MyPageObject>();
    myPageObject.ListBox.ClickItem("item2");
}

A common pattern was to use a property to get the Page Object as follows:

public class MyTest : TestFeature
{
    private MyPageObject MyPageObject => this.GetView<MyPageObject>();
}

This pattern is no longer supported because, with the new architecture, QualityMate can run more than one UiPlayer at the same time. An UiExecutionController is created on every Execute call and you need to explicitly get the PageObjects from it.

Change the way a configuration is modified before Execution

Before:

this.ConfigurationManager.CreateContext(new Dictionary<string, string>
{
    [ParameterName.Technology] = Technology.DesktopWinForms.ToString(),
    [ParameterName.Application] = AssetPaths.WinAppPath,
});

this.RunScenario(given => this.FirstStep(), then => this.SecondStep());

After:

Dictionary<string, string> newConfiguration = new Dictionary<string, string>
{
    [ParameterName.Technology] = Technology.DesktopWinForms.ToString(),
    [ParameterName.Application] = AssetPaths.WinAppPath,
};

this.Execute(this.TestCaseSteps, this.newConfiguration);

If all the configuration is in the .runsettings it is not necessary to pass the configuration on the Execute method.

this.Execute(this.testCaseSteps;)

Change the UiPlayer managers to WebManager

Before:

this.UiPlayer.NavigationManager;
this.UiPlayer.AlertManager;
this.UiPlayer.BrowserManager;

After:

controller.WebManager.Navigation;
controller.WebManager.Alert;
controller.WebManager.Browser;

Complete examples for comparison

TestFeature example:

[TestClass]
public class MyTest: TestFeature
{
    private void ChangeConfiguration()
    {
        this.ConfigurationManager.CreateContext(new Dictionary<string, string>
        {
            [ParameterName.Technology] = Technology.DesktopWinForms.ToString(),
            [ParameterName.Application] = AssetPaths.WinAppPath,
        });
    }

    [TestMethod]
    public void MyTestMethod()
    {
        this.ChangeConfiguration();
        this.RunScenario(given => this.FirstStep(), then => this.SecondStep());
    }

    private void FirstStep()
    {
        MyPageObject myPageObject = this.GetView<MyPageObject>();
        myPageObject.ListBox.ClickItem("item2");
        
    }

    private void SecondStep()
    {
        MyPageObject myPageObject = this.GetView<MyPageObject>();
        myPageObject.ListBox.Validate(self => self.SelectedItem == "item2");
    }
}

UiTest example:

[TestClass]
public class MyTest: UiTest
{
    private UiPlayerConfiguration newConfiguration = new UiPlayerConfiguration
            {
                Technology = Technology.DesktopWinForms,
                Application = AssetPaths.WinAppPath,
            };

    [TestMethod]
    public void FirstStep_SecondStep()
    {
        this.Execute(this.TestCaseSteps, this.newConfiguration);
    }

    private void TestCaseSteps(UiExecutionController controller)
    {
        this.FirstStep(controller);
        this.SecondStep(controller);
    }

    private void FirstStep(UiExecutionController controller)
    {
        MyPageObject myPageObject = controller.GetPageObject<MyPageObject>();
        myPageObject.ListBox.ClickItem("item2");
    }

    private void SecondStep(UiExecutionController controller)
    {
        MyPageObject myPageObject = controller.GetPageObject<MyPageObject>();
        myPageObject.ListBox.Validate(self => self.SelectedItem == "item2");
    }
}

Last updated