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
Calculators Main Window
Calculators UI Item Window
Calculators Button property
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
Post Author:
Karthik kk
5 Replies to “Hand coding in Coded UI testing – Part 2”
hi
i want a copy of all the code which i can use to design my project accordingly.
is there a chance please.
thanks for your guidance
can you please help me to write a customized method for the confirmation message displayed after loggining in successfully on the second screen of the WPF application .
This is the recorded code
// ——————————————————————————
//
// This code was generated by coded UI test builder.
// Version: 12.0.0.0
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
//
// ——————————————————————————
namespace vri
{
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Drawing;
using System.Text.RegularExpressions;
using System.Windows.Input;
using Microsoft.VisualStudio.TestTools.UITest.Extension;
using Microsoft.VisualStudio.TestTools.UITesting;
using Microsoft.VisualStudio.TestTools.UITesting.WpfControls;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Keyboard = Microsoft.VisualStudio.TestTools.UITesting.Keyboard;
using Mouse = Microsoft.VisualStudio.TestTools.UITesting.Mouse;
using MouseButtons = System.Windows.Forms.MouseButtons;
[GeneratedCode(“Coded UITest Builder”, “12.0.31101.0”)]
public partial class UIMap
{
// Click pane
Mouse.Click(uIItemPane, new Point(531, 54));
}
///
/// AssertMethod1 – Use ‘AssertMethod1ExpectedValues’ to pass parameters into this method.
///
public void AssertMethod1()
{
#region Variable Declarations
WpfText uILoggedinasandintosysText = this.UIA4TicketingWindow.UIItemCustom.UIItemPane.UILoggedinasandintosysText;
#endregion
// Verify that the ‘HelpText’ property of ‘Logged in as and into system…’ label contains ‘Logged in as and into system’
StringAssert.Contains(uILoggedinasandintosysText.HelpText, this.AssertMethod1ExpectedValues.UILoggedinasandintosysTextHelpText, “failed login”);
}
#region Properties
public virtual AssertMethod1ExpectedValues AssertMethod1ExpectedValues
{
get
{
if ((this.mAssertMethod1ExpectedValues == null))
{
this.mAssertMethod1ExpectedValues = new AssertMethod1ExpectedValues();
}
return this.mAssertMethod1ExpectedValues;
}
}
public UIA4TicketingWindow UIA4TicketingWindow
{
get
{
if ((this.mUIA4TicketingWindow == null))
{
this.mUIA4TicketingWindow = new UIA4TicketingWindow();
}
return this.mUIA4TicketingWindow;
}
}
#endregion
///
/// Parameters to be passed into ‘AssertMethod1’
///
[GeneratedCode(“Coded UITest Builder”, “12.0.31101.0”)]
public class AssertMethod1ExpectedValues
{
#region Fields
///
/// Verify that the ‘HelpText’ property of ‘Logged in as and into system…’ label contains ‘Logged in as and into system’
///
public string UILoggedinasandintosysTextHelpText = “Logged in as and into system”;
#endregion
}
[GeneratedCode(“Coded UITest Builder”, “12.0.31101.0”)]
public class UIA4TicketingWindow : WpfWindow
{
#region Properties
public WpfText UILoggedinasandintosysText
{
get
{
if ((this.mUILoggedinasandintosysText == null))
{
this.mUILoggedinasandintosysText = new WpfText(this);
#region Search Criteria
this.mUILoggedinasandintosysText.SearchProperties[WpfText.PropertyNames.Name] = “Logged in as and into system…”;
this.mUILoggedinasandintosysText.WindowTitles.Add(“A4 Ticketing”);
#endregion
}
return this.mUILoggedinasandintosysText;
}
}
#endregion
#region Fields
private WpfText mUILoggedinasandintosysText;
#endregion
}
}
please help meto write a customised code for verifying the text displayed on successful login of a WPF application
hi
i want a copy of all the code which i can use to design my project accordingly.
is there a chance please.
There is an advanced course which has all the source code including an enhanced framework right here https://www.udemy.com/framework-development-with-cuit
Thanks,
Karthik KK
Hi Karthik
thanks for your guidance
can you please help me to write a customized method for the confirmation message displayed after loggining in successfully on the second screen of the WPF application .
thanks
Roopa
This is the recorded code
// ——————————————————————————
//
// This code was generated by coded UI test builder.
// Version: 12.0.0.0
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
//
// ——————————————————————————
namespace vri
{
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Drawing;
using System.Text.RegularExpressions;
using System.Windows.Input;
using Microsoft.VisualStudio.TestTools.UITest.Extension;
using Microsoft.VisualStudio.TestTools.UITesting;
using Microsoft.VisualStudio.TestTools.UITesting.WpfControls;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Keyboard = Microsoft.VisualStudio.TestTools.UITesting.Keyboard;
using Mouse = Microsoft.VisualStudio.TestTools.UITesting.Mouse;
using MouseButtons = System.Windows.Forms.MouseButtons;
[GeneratedCode(“Coded UITest Builder”, “12.0.31101.0”)]
public partial class UIMap
{
///
/// RecordedMethod1
///
public void RecordedMethod1()
{
#region Variable Declarations
WpfPane uIItemPane = this.UIA4TicketingWindow.UIItemPane;
#endregion
// Click pane
Mouse.Click(uIItemPane, new Point(531, 54));
}
///
/// AssertMethod1 – Use ‘AssertMethod1ExpectedValues’ to pass parameters into this method.
///
public void AssertMethod1()
{
#region Variable Declarations
WpfText uILoggedinasandintosysText = this.UIA4TicketingWindow.UIItemCustom.UIItemPane.UILoggedinasandintosysText;
#endregion
// Verify that the ‘HelpText’ property of ‘Logged in as and into system…’ label contains ‘Logged in as and into system’
StringAssert.Contains(uILoggedinasandintosysText.HelpText, this.AssertMethod1ExpectedValues.UILoggedinasandintosysTextHelpText, “failed login”);
}
#region Properties
public virtual AssertMethod1ExpectedValues AssertMethod1ExpectedValues
{
get
{
if ((this.mAssertMethod1ExpectedValues == null))
{
this.mAssertMethod1ExpectedValues = new AssertMethod1ExpectedValues();
}
return this.mAssertMethod1ExpectedValues;
}
}
public UIA4TicketingWindow UIA4TicketingWindow
{
get
{
if ((this.mUIA4TicketingWindow == null))
{
this.mUIA4TicketingWindow = new UIA4TicketingWindow();
}
return this.mUIA4TicketingWindow;
}
}
#endregion
#region Fields
private AssertMethod1ExpectedValues mAssertMethod1ExpectedValues;
private UIA4TicketingWindow mUIA4TicketingWindow;
#endregion
}
///
/// Parameters to be passed into ‘AssertMethod1’
///
[GeneratedCode(“Coded UITest Builder”, “12.0.31101.0”)]
public class AssertMethod1ExpectedValues
{
#region Fields
///
/// Verify that the ‘HelpText’ property of ‘Logged in as and into system…’ label contains ‘Logged in as and into system’
///
public string UILoggedinasandintosysTextHelpText = “Logged in as and into system”;
#endregion
}
[GeneratedCode(“Coded UITest Builder”, “12.0.31101.0”)]
public class UIA4TicketingWindow : WpfWindow
{
public UIA4TicketingWindow()
{
#region Search Criteria
this.SearchProperties[WpfWindow.PropertyNames.Name] = “A4 Ticketing”;
this.SearchProperties.Add(new PropertyExpression(WpfWindow.PropertyNames.ClassName, “HwndWrapper”, PropertyExpressionOperator.Contains));
this.WindowTitles.Add(“A4 Ticketing”);
#endregion
}
#region Properties
public WpfPane UIItemPane
{
get
{
if ((this.mUIItemPane == null))
{
this.mUIItemPane = new WpfPane(this);
#region Search Criteria
this.mUIItemPane.SearchProperties[WpfPane.PropertyNames.ClassName] = “Uia.ScrollViewer”;
this.mUIItemPane.WindowTitles.Add(“A4 Ticketing”);
#endregion
}
return this.mUIItemPane;
}
}
public UIItemCustom UIItemCustom
{
get
{
if ((this.mUIItemCustom == null))
{
this.mUIItemCustom = new UIItemCustom(this);
}
return this.mUIItemCustom;
}
}
#endregion
#region Fields
private WpfPane mUIItemPane;
private UIItemCustom mUIItemCustom;
#endregion
}
[GeneratedCode(“Coded UITest Builder”, “12.0.31101.0”)]
public class UIItemCustom : WpfCustom
{
public UIItemCustom(UITestControl searchLimitContainer) :
base(searchLimitContainer)
{
#region Search Criteria
this.SearchProperties[WpfControl.PropertyNames.ClassName] = “Uia.Home”;
this.WindowTitles.Add(“A4 Ticketing”);
#endregion
}
#region Properties
public UIItemPane UIItemPane
{
get
{
if ((this.mUIItemPane == null))
{
this.mUIItemPane = new UIItemPane(this);
}
return this.mUIItemPane;
}
}
#endregion
#region Fields
private UIItemPane mUIItemPane;
#endregion
}
[GeneratedCode(“Coded UITest Builder”, “12.0.31101.0”)]
public class UIItemPane : WpfPane
{
public UIItemPane(UITestControl searchLimitContainer) :
base(searchLimitContainer)
{
#region Search Criteria
this.SearchProperties[WpfPane.PropertyNames.ClassName] = “Uia.ScrollViewer”;
this.WindowTitles.Add(“A4 Ticketing”);
#endregion
}
#region Properties
public WpfText UILoggedinasandintosysText
{
get
{
if ((this.mUILoggedinasandintosysText == null))
{
this.mUILoggedinasandintosysText = new WpfText(this);
#region Search Criteria
this.mUILoggedinasandintosysText.SearchProperties[WpfText.PropertyNames.Name] = “Logged in as and into system…”;
this.mUILoggedinasandintosysText.WindowTitles.Add(“A4 Ticketing”);
#endregion
}
return this.mUILoggedinasandintosysText;
}
}
#endregion
#region Fields
private WpfText mUILoggedinasandintosysText;
#endregion
}
}
please help meto write a customised code for verifying the text displayed on successful login of a WPF application
Thanks in advance
Roopa
Hi Karthik
i have been struggling to identify the page;
first page has login functionality
Second page has some information
both the pages have same properties
the code i have written fails to identify the second page.
can you please help me with
thanks
Roo