ExecuteAutomation

Hand coding in Coded UI testing – Part 2

In the last part of Hand coding in Coded UI Testing, we discussed, how to copy paste some of the auto-generated classes from the UIMap.Designer.cs file and create custom classes for the copy pasted codes, technically those classes were specific windows controls like

Problem which we will encounter in long run

We also discussed in the last part that, if we keep on creating these custom control class files, surely in long run, we may end up having many custom class files, since for any given application, there may be many such controls and maintaining them as a separate class file will be cumbersome. Hence, in the part of the post, we are going to simplify the process a little bit and have them all within a single class file as shown in the code snippet below.
        public static void Button8Click()
        {
	   //Instance for WinWindow
            WinWindow calcWindow = new WinWindow();
            calcWindow.SearchProperties[WinWindow.PropertyNames.Name] = "Calculator";
            calcWindow.SearchProperties[WinWindow.PropertyNames.ClassName] = "CalcFrame";

            //Button

            WinButton btn8 = new WinButton(calcWindow);
            btn8.SearchProperties[WinButton.PropertyNames.Name] = "8";

            Mouse.Click(btn8);

            WinButton btn9 = new WinButton(calcWindow);
            btn9.SearchProperties[WinButton.PropertyNames.Name] = "9";
            Mouse.Click(btn9);

            WinButton btnAdd = new WinButton(calcWindow);
            btnAdd.SearchProperties[WinButton.PropertyNames.Name] = "Add";
            Mouse.Click(btnAdd);

            WinButton btn2 = new WinButton(calcWindow);
            btn2.SearchProperties[WinButton.PropertyNames.Name] = "2";
            Mouse.Click(btn2);

            WinButton btn3 = new WinButton(calcWindow);
            btn3.SearchProperties[WinButton.PropertyNames.Name] = "3";
            Mouse.Click(btn3);

            WinButton btnEquals = new WinButton(calcWindow);
            btnEquals.SearchProperties[WinButton.PropertyNames.Name] = "Equals";
            Mouse.Click(btnEquals);
        }
Here is the detailed video of which will give a complete detail on how we achieved the above code. Thank you very much for watching the video and reading the article. Thanks, Karthik KK