c# - 无法使用 TestStack.White 自动编辑控件和列表框

标签 c# c++ mfc white-framework

我有一个使用 Visual Studio 2012 Professional 在 C++ MFC 中编写的应用程序。目前我想使用用 C# 编写的 TestStack.White 框架创建一些自动化脚本。

我无法控制列表框和编辑控件。 我正在使用 spy ++。编辑控件嵌套在组框内,我无法检查自动化 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"));
  1. 如何控制“列表框”检查/计数行数据(目前我使用向上和向下箭头作为解决方法)?
  2. 如何控制组框内的“编辑控件”(目前我正在使用 Tab 键更改焦点)?

我试图通过 ID 获取 MFC 控件,但失败了。我应该使用 Spy++ 以外的工具还是其他框架?

编辑:

这是屏幕截图表单检查。 Inspect screenshot

我尝试使用 ID“1221”和“0x1221”但没有成功。

最佳答案

我使用 MFC 向导制作了一个外观类似于 Visual Studio 的应用程序,并向属性窗口添加了一个编辑控件,以便我可以测试该编辑控件。我无法添加组框,因为据我所知,CGroupBox 不存在。如果您可以提供一些关于如何实现分组框的代码,我也许可以将其添加到我的答案中。

希望我能回答您的一些问题。

这是我用 C# 编写的控制台应用程序,用于自动执行“列表框”和“编辑”控件。

 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();
         }
     }
 }

这是我使用自动突出显示的控件测试的应用程序的图像。

MFC Example Application

关于c# - 无法使用 TestStack.White 自动编辑控件和列表框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34175627/

相关文章:

c++ - 在 MFC 中使用静态库

c# - 处理数据类型转换的通用函数

声明结构时的 C++ 问题

c++ - QT 是适合我的跨平台应用程序的解决方案吗?

c++ - 在 MFC 中使用套接字

c++ - 使用较旧版本的 MFC 和较新版本的 Visual Studio

c# - System.Text.Json 将空字符串全局序列化为空字符串

c# - MEF CachedAssemblyCatalog - 程序集的延迟加载

c# - 使用新处理程序附加事件处理程序与直接分配它

c++ - 模拟以退出代码 : 132 终止