我在C ++ MFC中使用Visual Studio 2012专业人员编写了一个应用程序。目前我想使用用C#编写的TestStack.White框架创建一些自动化脚本。
我无法控制列表框和编辑控件。 我正在使用spy ++。编辑控件嵌套在Group Box中,我无法检查自动化ID。
我的代码示例
var psi = new ProcessStartInfo(ExeSourceFile);
application = Application.AttachOrLaunch(psi);
mainWindow = application.GetWindow(SearchCriteria.ByText(applicationName), InitializeOption.NoCache);
其中ExeSourceFile是应用程序的路径。
这是我试过的方式。其中IDC_Edit是设计者的ID。
TextBox TextObj = mainWindow.Get<TextBox> (SearchCriteria.ByAutomationId("IDC_Edit"));
答案 0 :(得分:1)
我使用MFC向导创建一个可视工作室查看应用程序并将一个编辑控件添加到属性窗口,以便我可以测试编辑控件。我无法添加组合框,因为我所知道的CGroupBox不存在。如果你能提供一些关于如何实现组框的代码,我可以将它添加到我的答案中。
希望我能回答你的一些问题。
这是我在C#中编写的控制台应用程序,用于自动化一个&#34; List Box&#34;和&#34;编辑&#34;控制。
using System;
using TestStack.White;
using TestStack.White.UIItems;
using TestStack.White.UIItems.Finders;
using TestStack.White.UIItems.ListBoxItems;
namespace ConsoleApplication1
{
public class Program
{
public static void Main(string[] args)
{
var application = Application.Attach("MFCApplication1");
var window = application.GetWindow("MFCApplication11 - MFCApplication1");
//Edit Control
var propertyPane = window.Get<Panel>(SearchCriteria.ByAutomationId("150"));
var edit = propertyPane.Get<TextBox>(SearchCriteria.ByAutomationId("1"));
//Type this text into the edit control
edit.Text = "Hello World";
//List View
var output = window.Get<Panel>(SearchCriteria.ByAutomationId("149"));
var list = output.Get<ListBox>(SearchCriteria.ByAutomationId("2"));
//Output the count of how many rows exist
Console.Out.WriteLine(list.Items.Count);
//Select the second row
list.Items[1].Select();
}
}
}
这是我使用我自动突出显示的控件测试的应用程序的图像。