如何自动化 xceed updown 控件

2024-04-19

对于我的 WPF 应用程序,我正在使用 TestStack.White 进行 UI 自动化测试。
我在我的应用程序中使用 xceed wpf 工具包中的 DoubleUpDown 控件。
如何在 UI 自动化测试中访问 DoubleUpDown 控件?


通过使用UIA验证 http://uiautomationverify.codeplex.com/,您可以看到 DoubleUpDown 控件被视为三个控件,没有层次结构信息和以下 AutomationId:

  • 自动选择文本框
  • Part_IncreaseButton
  • Part_DecreaseButton

因此,您可以将它们作为普通控件进行自动化,但如果同一窗口中有多个 DoubleUpDown 控件,则会出现问题,因为所有控件都将具有相同的 AutomationId。

下面是一个示例应用程序,其中前两个文本框作为 DoubleUpDown 控件,第三个文本框作为专为自动化设计的自定义控件。

...
<Label Content="Label for DoubleUpDown1" Grid.Row="0" Grid.Column="0" 
                    FontSize="15" Background="Aqua"/>

<xctk:DoubleUpDown Name="test1" Grid.Row="0" Grid.Column="1"
                   FormatString="F3" Value="1564.6749586" Increment=".001"  Maximum="200000.599" 
                   AutomationProperties.AutomationId="006" AutomationProperties.Name="NormalDoubleUpDown1" />

<Label Content="Label for DoubleUpDown2" Grid.Row="1" Grid.Column="0" 
                    FontSize="15" Background="Aqua"/>

<xctk:DoubleUpDown Name="test2" Grid.Row="1" Grid.Column="1"
                   FormatString="F3" Value="1564.6749586" Increment=".001"  Maximum="300000.751" 
                   AutomationProperties.AutomationId="007" AutomationProperties.Name="NormalDoubleUpDown2" />

<Label Content="Label for MyDoubleUpDown" Grid.Row="2" Grid.Column="0" FontSize="15" Background="Aqua" />

<local:MyDoubleUpDown x:Name="test3"  Grid.Row="2" Grid.Column="1"                             
                   FormatString="F3" Value="1564.7749586" Increment=".001"  Maximum="200000.599" 
                   AutomationProperties.AutomationId="008" AutomationProperties.Name="My Custom DoubleUpDown" />
...

在 UIA 验证中,正常的 DoubleUpDown 控件显示为具有相同的 AutomationId。 自定义的与真实的层次结构一起出现,并且可以使用在 XAML 中设置的 AutomationId(此处008).


自定义控件我的双上下,Xceed 的简单子类,但具有自动化对等体。

public class MyDoubleUpDown : Xceed.Wpf.Toolkit.DoubleUpDown
{
    protected override AutomationPeer OnCreateAutomationPeer()
    {
        return new MyDoubleUpDownAutomationPeer(this);
    }
}

public class MyDoubleUpDownAutomationPeer : FrameworkElementAutomationPeer
{
    public MyDoubleUpDownAutomationPeer(MyDoubleUpDown owner)
        : base(owner)
    {
    }
}

这是在窗口中自动化唯一的 DoubleUpDown 控件的默认方法。

// link to the application and retrieve the main window
Application application = Application.Attach("WpfTestApplication1");
var windows = application.GetWindows();
var window = windows.FirstOrDefault();

// get the child components
TextBox theEdit = window.Get<TextBox>("AutoSelectTextBox");
Button increaseButton = window.Get<Button>("PART_IncreaseButton");
Button decreaseButton = window.Get<Button>("PART_DecreaseButton");

// define the value 
theEdit.SetValue("600");

// increase and decrease the value
increaseButton.Click();
increaseButton.Click();
increaseButton.Click();
decreaseButton.Click();

这是基于 Xceed 的自动化自定义控件的代码。

// retrieve the custom control
IUIItem theCustomControl = window.Get(SearchCriteria.ByAutomationId("008"));

// get the childs items                
if(theCustomControl is CustomUIItem)
{
    // retrieve the custom control container
    IUIItemContainer foundCustomControl = (theCustomControl as CustomUIItem).AsContainer();

    // get the child components
    TextBox theEdit3 = foundCustomControl.Get<TextBox>("AutoSelectTextBox");
    Button increaseButton3 = foundCustomControl.Get<Button>("PART_IncreaseButton");
    Button decreaseButton3 = foundCustomControl.Get<Button>("PART_DecreaseButton");

    // perform actions...
    theEdit3.SetValue("800");
    increaseButton3.Click();
    increaseButton3.Click();
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何自动化 xceed updown 控件 的相关文章

随机推荐

  • 参数“ state ”必须在查询字符串中设置,结果我应该进一步做什么

    我做了一个智能家居谷歌动作连接 网络应用程序与谷歌主页链接并授权 我关注了智能家居谷歌的行动 那里需要国家 什么是状态 下面给出的字符串是授权的示例 但我不知道状态字符串 我从哪里添加状态字符串 它的目的是什么 GET https myse
  • mux_client_request_session:会话请求失败:会话打开被对等方拒绝

    我使用 bitbucket 来托管一些 git 存储库 当我尝试这样做时 git pull git push I get mux client request session session request failed Session o
  • XML 验证错误 - 根元素必须与 doctype 匹配

    我正在尝试使用外部 DTD 验证我的 XML 文件 但我每次都会遇到这个错误 Document root element A must match DOCTYPE root test 我不明白这一点 我的 xml 文件的想法是它需要尽可能短
  • VS Code 代码自动自动补全高亮

    当我在 VS Code 中使用自动完成功能时 所选文本会随突出显示的光标位置一起出现 这种突出显示会阻止 VS Code 提供进一步的建议 如何禁用此突出显示 我希望能够连续使用自动完成功能 而不必按 ESC 退出突出显示 VS代码1 44
  • 防止 Spark SQL 中的 SQL 注入 [重复]

    这个问题在这里已经有答案了 我正在使用 Spark SQL 从远程 MYSQL 数据库获取数据 我如何确保 SQL 注入不会发生 因为我似乎无法找到避免 Spark SQl 中 SQL 注入的方法 spark SparkSession bu
  • 计算和显示 ggplot2::geom_密度() 对象峰值的最佳方法是什么?

    我试图找到一种简单直观的方法来计算和显示 ggplot2 geom densis 对象的峰值 这个博客 http ianmadd github io pages PeakDensityDistribution html解释了如何在基础 R
  • python:与cgi脚本中的会话交互

    python cgi 脚本可以向会话写入和读取数据吗 如果是这样怎么办 是否有高级 API 或者我必须推出自己的类 没有 session on cgi 如果您使用的是原始会话 则必须滚动自己的会话处理代码cgi 基本上 会话的工作原理是创建
  • 如何制作仅在系统托盘中运行的 .NET Windows 窗体应用程序?

    我需要做什么才能制作Windows 窗体 https learn microsoft com en us dotnet desktop winforms overview view netdesktop 5 0应用程序能够在系统托盘中运行吗
  • Java:一维数组在内存中总是连续的吗?

    我读过的许多关于这个主题的书籍 文章 以及我使用 Unsafe 编写的一个小程序 都表明 Java 中的一维数组在内存中始终是连续的 那么它是 JLS 规定的还是实施约定 提出这个问题是为了确认这一指示 不 JVM 规范没有任何此类保证 h
  • 如何隐藏 Angular Material mdToast?

    app controller testCtrl function rootScope scope mdToast scope showHideToast function mdToast show template
  • Google Calendar API - 不获取重复事件实例

    我正在尝试使用 V3 API 从 Google 日历获取所有事件 我注意到有关重复事件的问题 对于某些日历上的某些重复事件 仅获取第一个实例 例如 获取总共 8 个实例中的前 5 个实例 一些额外的细节 我已经仔细检查查询日期范围是否正确
  • 协变“Self”类型无法从存储的属性初始值设定项中引用

    在下面的代码中 我不明白为什么在使用时会出现上述错误Self 如果我将其替换为 代码就可以正常工作Fireman final class Fireman var numOfServices 0 private init static var
  • 如何对两个并行数组进行排序? [复制]

    这个问题在这里已经有答案了 我有一个数字数组 int numoftoys 和一个并行的字符串数组 string names 其条目对应于数字 我的作业要求我对数字数组进行排序 因此当我打印时 它首先打印最大的数字 然后打印下一个最高的数字
  • Spring Cloud Config 客户端未从配置服务器加载值

    当我尝试运行 Spring Cloud Config Client 时 我遇到以下问题 Caused by java lang IllegalArgumentException Could not resolve placeholder D
  • Podspec - 排除除子文件夹之外的所有内容

    我有这样的结构 target files target1 target2 target3 例如 我只想包含 target2 并排除其他目标 我如何编写spec exclude files 我找到了这个排除文件的示例 但我不明白如何为整个文件
  • 多项式系数列表

    如何从 SymPy 中的系数列表创建多项式 例如 给定一个列表 1 2 1 我想得到Poly x 2 2 x 1 我试着看看docs http docs sympy org dev modules polys reference html但
  • 弹簧致动器上的不同端口

    我们有以下弹簧设置 我们的应用程序在端口 80 上运行 但我们的 managment server port 设置为 8081 并且我们已经使用此安全端口对管理端点进行多次检查 server port 80 management serve
  • CSS 在自定义 HTML 元素上无法正常工作

    我一直在尝试通过扩展来制作自定义 HTML 元素HTMLElement班级 我尝试通过链接与其他两个文件位于同一目录中的 CSS 文件来添加一些样式 index html and custom css 主文件夹 索引 html 自定义 cs
  • 禁用 Google 同意屏幕上的复选框

    我们正在使用 Gmail NET SDK 实现 Gmail 发送 ASP NET Web 应用程序 为此 我们需要以下所有范围 电子邮件 个人资料 openid https www googleapis com auth gmail sen
  • 如何自动化 xceed updown 控件

    对于我的 WPF 应用程序 我正在使用 TestStack White 进行 UI 自动化测试 我在我的应用程序中使用 xceed wpf 工具包中的 DoubleUpDown 控件 如何在 UI 自动化测试中访问 DoubleUpDown