コード化されたuitestレコーダーから取得したコードをリバースエンジニアリングして、コンボボックスからアイテムを取得しようとしています。コードでは、マウス座標を使用して値が選択されているようですが、コンボボックスコントローラーを使用して値を選択したいと思います
最初に 2 つの方法を次に示します。完全なコードを以下に示します (ご協力いただきありがとうございます)。
public void CodedUITestMethod1()
{
// To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items.
// For more information on generated code, see http://go.microsoft.com/fwlink/?LinkId=179463
this.UIMap.SelectedComboBoxValue();
this.UIMap.AssertSelectedText();
}
public void SelectedComboBoxValue()
{
#region Variable Declarations
WinClient uITaiwanChinaClient = this.UIAGORAActivitiesPortfWindow.UIActivitiesPortfolioWindow.UICharacteristicsGroup.UITaiwanChinaClient;
WinEdit uIItemEdit = this.UIAGORAActivitiesPortfWindow.UIActivitiesPortfolioWindow.UIItemWindow.UIItemEdit;
#endregion
// Click 'Taiwan, China' client
Mouse.Click(uITaiwanChinaClient, new Point(280, 13));
// Type '{Down}{Enter}' in 'Unknown Name' text box
Keyboard.SendKeys(uIItemEdit, this.SelectedComboBoxValueParams.UIItemEditSendKeys, ModifierKeys.None);
}
public void AssertSelectedText()
{
#region Variable Declarations
WinEdit uIItemEdit = this.UIAGORAActivitiesPortfWindow.UIActivitiesPortfolioWindow.UIItemWindow.UIItemEdit;
#endregion
// Verify that 'Unknown Name' text box's property 'SelectionText' equals 'Tajikistan'
Assert.AreEqual(this.AssertSelectedTextExpectedValues.UIItemEditSelectionText, uIItemEdit.SelectionText);
// Verify that 'Unknown Name' text box's property 'Text' equals 'Tajikistan'
Assert.AreEqual(this.AssertSelectedTextExpectedValues.UIItemEditText, uIItemEdit.Text);
}
-----------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by coded UI test builder.
// Version: 10.0.0.0
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
// ------------------------------------------------------------------------------
namespace TestProject16
{
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.WinControls;
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", "10.0.30319.1")]
public partial class UIMap
{
/// <summary>
/// SelectedComboBoxValue - Use 'SelectedComboBoxValueParams' to pass parameters into this method.
/// </summary>
public void SelectedComboBoxValue()
{
#region Variable Declarations
WinClient uITaiwanChinaClient = this.UIAGORAActivitiesPortfWindow.UIActivitiesPortfolioWindow.UICharacteristicsGroup.UITaiwanChinaClient;
WinEdit uIItemEdit = this.UIAGORAActivitiesPortfWindow.UIActivitiesPortfolioWindow.UIItemWindow.UIItemEdit;
#endregion
// Click 'Taiwan, China' client
Mouse.Click(uITaiwanChinaClient, new Point(280, 13));
// Type '{Down}{Enter}' in 'Unknown Name' text box
Keyboard.SendKeys(uIItemEdit, this.SelectedComboBoxValueParams.UIItemEditSendKeys, ModifierKeys.None);
}
/// <summary>
/// AssertSelectedText - Use 'AssertSelectedTextExpectedValues' to pass parameters into this method.
/// </summary>
public void AssertSelectedText()
{
#region Variable Declarations
WinEdit uIItemEdit = this.UIAGORAActivitiesPortfWindow.UIActivitiesPortfolioWindow.UIItemWindow.UIItemEdit;
#endregion
// Verify that 'Unknown Name' text box's property 'SelectionText' equals 'Tajikistan'
Assert.AreEqual(this.AssertSelectedTextExpectedValues.UIItemEditSelectionText, uIItemEdit.SelectionText);
// Verify that 'Unknown Name' text box's property 'Text' equals 'Tajikistan'
Assert.AreEqual(this.AssertSelectedTextExpectedValues.UIItemEditText, uIItemEdit.Text);
}
#region Properties
public virtual SelectedComboBoxValueParams SelectedComboBoxValueParams
{
get
{
if ((this.mSelectedComboBoxValueParams == null))
{
this.mSelectedComboBoxValueParams = new SelectedComboBoxValueParams();
}
return this.mSelectedComboBoxValueParams;
}
}
public virtual AssertSelectedTextExpectedValues AssertSelectedTextExpectedValues
{
get
{
if ((this.mAssertSelectedTextExpectedValues == null))
{
this.mAssertSelectedTextExpectedValues = new AssertSelectedTextExpectedValues();
}
return this.mAssertSelectedTextExpectedValues;
}
}
public UIAGORAActivitiesPortfWindow UIAGORAActivitiesPortfWindow
{
get
{
if ((this.mUIAGORAActivitiesPortfWindow == null))
{
this.mUIAGORAActivitiesPortfWindow = new UIAGORAActivitiesPortfWindow();
}
return this.mUIAGORAActivitiesPortfWindow;
}
}
#endregion
#region Fields
private SelectedComboBoxValueParams mSelectedComboBoxValueParams;
private AssertSelectedTextExpectedValues mAssertSelectedTextExpectedValues;
private UIAGORAActivitiesPortfWindow mUIAGORAActivitiesPortfWindow;
#endregion
}
/// <summary>
/// Parameters to be passed into 'SelectedComboBoxValue'
/// </summary>
[GeneratedCode("Coded UITest Builder", "10.0.30319.1")]
public class SelectedComboBoxValueParams
{
#region Fields
/// <summary>
/// Type '{Down}{Enter}' in 'Unknown Name' text box
/// </summary>
public string UIItemEditSendKeys = "{Down}{Enter}";
#endregion
}
/// <summary>
/// Parameters to be passed into 'AssertSelectedText'
/// </summary>
[GeneratedCode("Coded UITest Builder", "10.0.30319.1")]
public class AssertSelectedTextExpectedValues
{
#region Fields
/// <summary>
/// Verify that 'Unknown Name' text box's property 'SelectionText' equals 'Tajikistan'
/// </summary>
public string UIItemEditSelectionText = "Tajikistan";
/// <summary>
/// Verify that 'Unknown Name' text box's property 'Text' equals 'Tajikistan'
/// </summary>
public string UIItemEditText = "Tajikistan";
#endregion
}
[GeneratedCode("Coded UITest Builder", "10.0.30319.1")]
public class UIAGORAActivitiesPortfWindow : WinWindow
{
public UIAGORAActivitiesPortfWindow()
{
#region Search Criteria
this.SearchProperties[WinWindow.PropertyNames.Name] = "AGORA - [Activities Portfolio]";
this.SearchProperties[WinWindow.PropertyNames.ClassName] = "ThunderRT6MDIForm";
this.WindowTitles.Add("AGORA - [Activities Portfolio]");
#endregion
}
#region Properties
public UIActivitiesPortfolioWindow UIActivitiesPortfolioWindow
{
get
{
if ((this.mUIActivitiesPortfolioWindow == null))
{
this.mUIActivitiesPortfolioWindow = new UIActivitiesPortfolioWindow(this);
}
return this.mUIActivitiesPortfolioWindow;
}
}
#endregion
#region Fields
private UIActivitiesPortfolioWindow mUIActivitiesPortfolioWindow;
#endregion
}
[GeneratedCode("Coded UITest Builder", "10.0.30319.1")]
public class UIActivitiesPortfolioWindow : WinWindow
{
public UIActivitiesPortfolioWindow(UITestControl searchLimitContainer) :
base(searchLimitContainer)
{
#region Search Criteria
this.SearchProperties[WinWindow.PropertyNames.ControlId] = "32769";
this.WindowTitles.Add("AGORA - [Activities Portfolio]");
#endregion
}
#region Properties
public UICharacteristicsGroup UICharacteristicsGroup
{
get
{
if ((this.mUICharacteristicsGroup == null))
{
this.mUICharacteristicsGroup = new UICharacteristicsGroup(this);
}
return this.mUICharacteristicsGroup;
}
}
public UIItemWindow UIItemWindow
{
get
{
if ((this.mUIItemWindow == null))
{
this.mUIItemWindow = new UIItemWindow(this);
}
return this.mUIItemWindow;
}
}
#endregion
#region Fields
private UICharacteristicsGroup mUICharacteristicsGroup;
private UIItemWindow mUIItemWindow;
#endregion
}
[GeneratedCode("Coded UITest Builder", "10.0.30319.1")]
public class UICharacteristicsGroup : WinGroup
{
public UICharacteristicsGroup(UITestControl searchLimitContainer) :
base(searchLimitContainer)
{
#region Search Criteria
this.SearchProperties[WinControl.PropertyNames.Name] = "Characteristics";
this.WindowTitles.Add("AGORA - [Activities Portfolio]");
#endregion
}
#region Properties
public WinWindow UITaiwanChinaWindow
{
get
{
if ((this.mUITaiwanChinaWindow == null))
{
this.mUITaiwanChinaWindow = new WinWindow(this);
#region Search Criteria
this.mUITaiwanChinaWindow.SearchProperties[WinWindow.PropertyNames.Name] = "Taiwan, China";
this.mUITaiwanChinaWindow.SearchProperties[WinWindow.PropertyNames.ClassName] = "AfxOleControl42";
this.mUITaiwanChinaWindow.WindowTitles.Add("AGORA - [Activities Portfolio]");
#endregion
}
return this.mUITaiwanChinaWindow;
}
}
public WinClient UITaiwanChinaClient
{
get
{
if ((this.mUITaiwanChinaClient == null))
{
this.mUITaiwanChinaClient = new WinClient(this);
#region Search Criteria
this.mUITaiwanChinaClient.SearchProperties[WinControl.PropertyNames.Name] = "Taiwan, China";
this.mUITaiwanChinaClient.WindowTitles.Add("AGORA - [Activities Portfolio]");
#endregion
}
return this.mUITaiwanChinaClient;
}
}
#endregion
#region Fields
private WinWindow mUITaiwanChinaWindow;
private WinClient mUITaiwanChinaClient;
#endregion
}
[GeneratedCode("Coded UITest Builder", "10.0.30319.1")]
public class UIItemWindow : WinWindow
{
public UIItemWindow(UITestControl searchLimitContainer) :
base(searchLimitContainer)
{
#region Search Criteria
this.SearchProperties[WinWindow.PropertyNames.ControlId] = "110";
this.SearchProperties[WinWindow.PropertyNames.Instance] = "7";
this.WindowTitles.Add("AGORA - [Activities Portfolio]");
#endregion
}
#region Properties
public WinEdit UIItemEdit
{
get
{
if ((this.mUIItemEdit == null))
{
this.mUIItemEdit = new WinEdit(this);
#region Search Criteria
this.mUIItemEdit.WindowTitles.Add("AGORA - [Activities Portfolio]");
#endregion
}
return this.mUIItemEdit;
}
}
#endregion
#region Fields
private WinEdit mUIItemEdit;
#endregion
}
}