📜 ⬆️ ⬇️

User Interface Cards

A large layer of work with tests UI make up Desktop applications under Windows. In different articles while writing the user interface (PageObject's) maps, the reader is shown writing locators manually using UISpy.

Five years ago, the number of such elements in my tests became too large, the controls became more difficult, and the libraries for UI testing 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 simple PageObject's editor. Auxiliary tools: UIAVerify.

General principles



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 click in the map editor from the desktop tree I transfer all window objects and remove the excess. Locators are automatically inserted. You can add elements manually (for example, for Selenium), the flight of fantasy is limitless
  2. I look at the generated element names. If I don't like them, rename 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:

XML Map
<?xml version="1.0" encoding="utf-8"?> <Map Version="2.0.0.0" Uid="7b797972-8c3c-4dbf-9c30-7cc8ae14afda"> <Assembly Name="Calc" FrameWork="NavyWindows"> <Assembly Name="Map" FrameWork="NavyWindows"> <Element ControlType="Window" Name="" Comment="Window """> <Control Comment="Window "TitleBar"" IsHidden="true" Name="" ControlType="Window"> <Property Name="Name"></Property> <Control Comment="Button "Close"" Name="" ControlType="Button"> <Property Name="AutomationId">Close</Property> </Control> ... </Map> 


Formed map for UIAutomation wrapper
 namespace Calc { public partial class UIWindow : UIWindow { public UIWindow(UIControl control) { Wrap(control); } public UIWindow() { } public static UIWindow Instance { get { return Desktop.Instance.Get<UIWindow>(XPath); } } public static By XPath { get { return By.Xpath("Name="); } } /// <summary> /// Button "plusButton" /// </summary> public UIButton UIButton { get { return Get<UIButton>(By.Xpath(@"AutomationId=plusButton")); } } ... </Map> 


MapExt.cs and all kinds of extensions
 namespace Calc { public static class UIWindowExt { public static int Result(this UIWindow window) { var textValue = window.UIResultText.Text .Replace("  ", "") .Replace(" ", ""); return int.Parse(textValue); } } } 


Test CalculationTests.cs
 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 = UIWindow.Instance; } [TestMethod] public void Sum() { _calc.UIButton.Click(); _calc.UIButton.Click(); _calc.UIButton.Click(); _calc.UIButton.Click(); Assert.AreEqual(6, _calc.Result(), "  "); } public UIWindow _calc { get; set; } Process _process; public void Dispose() { _calc.Close(); } } } 


I think there are already a lot of alternative solutions; throw links and more successful examples in the comments.

Thanks for attention!

Source: https://habr.com/ru/post/325058/


All Articles