在编码的UI测试中仅知道部分窗口标题时查找窗口 [英] Finding a window when only part of the window title is known in Coded UI Tests

查看:109
本文介绍了在编码的UI测试中仅知道部分窗口标题时查找窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为其编写编码的UI测试的应用程序有一个窗口,其中窗口标题的一部分基于为临时文件生成的随机文件名,因此该测试只能知道窗口标题的静态部分。

The application I am writing coded UI tests for has a window where part of the window title is based on a random filename generated for a temporary file, so the test can only know the static part of the window title.

有时,当没有其他窗口打开时,测试运行良好。但是,当其他窗口打开时,这有点问题。如果其他窗口具有类似的控件,则测试选择使用的窗口是不可预测的。

Occasionally, when no other windows are open, the test runs fine. It is a bit problematic when other windows are open, however. If the other windows have similar controls, which window the test picks to work in is unpredictable.

推荐答案

我已经缩小了范围为此:在搜索控件时,编码的UI测试使用搜索属性和控件的树状结构。如果找不到完全匹配的内容,则会找到一个紧密匹配的内容(因此找不到确切的窗口标题名称,它将排除该名称,并继续搜索与任何其他给定属性匹配的窗口),这就是它可以与控件一起使用的原因在其他窗口中。

I've narrowed it down to this: When searching for a control, the Coded UI Test uses search properties and a tree-like structure of controls. If it can't find an exact match it finds a close match (so it can't find the exact window title name, it excludes that and keeps searching for a window that matches any other given properties) which is why it works with controls in other windows.

该解决方案实际上是为其提供更多搜索属性。我使用的一种方法是使用 PropertyExpression 添加属性并通过 PropertyExpressionOperator.Contains

The solution is really to give it more search properties to work with. One method I use is to add a property using a PropertyExpression and pass it PropertyExpressionOperator.Contains.

作为示例,我记录了打开MS Word并关闭它的过程。这将在UIMap中生成一个控件,并且在其构造函数中如下所示:

As an example, I recorded opening MS Word and closing it. This generates a control in the UIMap, and in its constructor is the following:

this.SearchProperties[WinWindow.PropertyNames.Name] = "Document1 - Microsoft Word";
this.SearchProperties[WinWindow.PropertyNames.ClassName] = "OpusApp";

相反,第一行应为:

this.SearchProperties.Add(new PropertyExpression(WinWindow.PropertyNames.Name, "Microsoft Word", PropertyExpressionOperator.Contains));

这篇关于在编码的UI测试中仅知道部分窗口标题时查找窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆