当我使用 Coded UI 测试记录“登录场景”的测试方法时,它会生成这样的代码
生成的代码
public void LoginMethod()
{
#region Variable Declarations
WinEdit uIItemEdit = this.UIDiagnosoftVIRTUEWindow.UIItemWindow.UIItemEdit;
WinEdit uIItemEdit1 = this.UIDiagnosoftVIRTUEWindow.UIItemWindow1.UIItemEdit;
WinComboBox uIItemComboBox = this.UIDiagnosoftVIRTUEWindow.UIItemWindow2.UIItemComboBox;
WinButton uIConnectButton = this.UIDiagnosoftVIRTUEWindow.UIConnectWindow.UIConnectButton;
#endregion
// Type 'username' in 'Unknown Name' text box
uIItemEdit.Text = this.LoginMethodParams.UIItemEditText;
// Type '********' in 'Unknown Name' text box
Keyboard.SendKeys(uIItemEdit1, this.LoginMethodParams.UIItemEditSendKeys1, true);
// Select 'facility' in 'Unknown Name' combo box
uIItemComboBox.SelectedItem = this.LoginMethodParams.UIItemComboBoxSelectedItem;
// Click 'Connect' button
Mouse.Click(uIConnectButton, new Point(64, 14));
}
我更新此代码以允许包含用户名、密码、....的数据驱动源、CSV 文件。这是更新后的代码
更新代码
public void LoginMethod(string username,string password,string facility)
{
#region Variable Declarations
WinEdit uIItemEdit = this.UIDiagnosoftVIRTUEWindow.UIItemWindow.UIItemEdit;
WinEdit uIItemEdit1 = this.UIDiagnosoftVIRTUEWindow.UIItemWindow1.UIItemEdit;
WinComboBox uIItemComboBox = this.UIDiagnosoftVIRTUEWindow.UIItemWindow2.UIItemComboBox;
WinButton uIConnectButton = this.UIDiagnosoftVIRTUEWindow.UIConnectWindow.UIConnectButton;
#endregion
// Type 'msameeh' in 'Unknown Name' text box
uIItemEdit.Text = username;
// Type '{Tab}' in 'Unknown Name' text box
uIItemEdit.Text=password;
// Select 'diagnosoft.com' in 'Unknown Name' combo box
uIItemComboBox.SelectedItem = facility;
// Click 'Connect' button
Mouse.Click(uIConnectButton, new Point(64, 14));
}
并且我运行测试方法并且效果很好但是当我编辑 UIMap 以添加未使用的控件(例如“取消按钮”)或此链接中的任何其他控件时
http://blogs.microsoft.co.il/blogs/shair/archive/2010/08/08/coded-ui-test-tip-4-add-unused-controls-to-ui-map.aspx UIMap。 Designer.CS 文件覆盖了我的登录方法使用生成的代码更新了代码
提前致谢