Skip to content
AleksSharkov edited this page May 15, 2019 · 16 revisions

Navy Page Editor = CUITe + TestStack.White + Microsoft UITest Maps

A large layer of work with tests of the user interface of the desktop application under Windows. When you write maps, the user interface (PageObject's) reader shows writing locators manually using UISpy.

Five years ago, the number of such elements in my tests became too large, and testing libraries for the user interface began to grow like mushrooms.

Routine for finding the necessary XPath, it was decided to transform into joy. At first I used Visual Studio UIMap Editor: the more complex the applications were, the less it did not suit me in terms of speed and locator substitution. I will describe the reasons in a separate article on UIAutomation and its wrappers (TestStack.White, Cuite, Microsoft UITest, etc.).

So, the task

Make a simple PageObject’s editor. Auxiliary tools: UIAVerify.

General Principles

  • each control (control) of a desktop has search properties and may contain child elements
  • controls the grouped elements (elements), elements are grouped in a namespace (assembly)
  • Encapsulation, inheritance, polymorphism
  • Ability to use ready-made cards. For example, I have ready-made maps and extensions for DevExpress, AvalonDock, OpenFileDialog, etc. I transfer them between projects

What happened

On the example of addition in the Windows 10 calculator:
  1. I make a map for the "Calculator" window, for this purpose in one map editor in the map editor from the desktop tree I transfer all window objects, and remove the excess. Locators are automatically inserted. You can also add elements manually (for example, for Selenium), the flight of fantasy is limitless
  2. I’m looking at the generated item names. If I don’t like them, rename them manually
  3. I save the map for the UIAutomation wrapper (Normal XML Converter => C #. Any wrapper can be used, Selenium, MS UITest, TestStack.White)
Time for everything: three minutes

On the right is an analogue of the UIAVerify desktop tree. Left: map

image

Result

Four files are sent under version control: Калькулятор Close ...
namespace Calc
{
	public partial class UIКалькуляторWindow : UIWindow
	{
		public UIКалькуляторWindow(UIControl control) { Wrap(control); }
		public UIКалькуляторWindow() {  }
		public static UIКалькуляторWindow Instance 
		{ 
			get { return Desktop.Instance.Get(XPath); }
		}
	public static By XPath { get { return By.Xpath("Name=Калькулятор"); } }
	
	/// <summary>
	/// Button "plusButton"
	/// </summary>
	public UIButton UIПлюсButton
	{
	 	get { return Get<UIButton>(By.Xpath(@"AutomationId=plusButton")); }
	}

...

namespace Calc
{
	public static class UIКалькуляторWindowExt
	{ 
        public static int Result(this UIКалькуляторWindow  window)
        {
            var textValue = window.UIResultText.Text
                .Replace("На экране показано", "")
                .Replace(" ", "");
            return int.Parse(textValue);
        }
	}
}
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Calc;
using System.Diagnostics;
using System;

namespace CalcTests { [TestClass] public class CalculationTests : IDisposable { public CalculationTests() { _process = Process.Start("calc.exe"); _calc = UIКалькуляторWindow.Instance; }

    [TestMethod]
    public void Sum()
    {
        _calc.UIОдинButton.Click();
        _calc.UIПлюсButton.Click();
        _calc.UIПятьButton.Click();
        _calc.UIРавноButton.Click();
        Assert.AreEqual(6, _calc.Result(), "Не совпадает результат");
    }

    public UIКалькуляторWindow _calc { get; set; }
    Process _process;

    public void Dispose()
    {
        _calc.Close();
    }
}

}

You can’t perform that action at this time.