我无法在codedui中选择UWP ListView项目

问题描述 投票:0回答:1

我有一个UWP应用程序,我正在使用CodedUI进行UWP

它包含一个作为ListView创建的报告,我需要验证此列表中的一些值。但是当我尝试使用十字准线工具将其拖动到行或列表上时,应用程序一直挂起,当我成功捕获行时,我运行测试用例失败,因为Codedui无法​​找到控件。

在附图中,我可以捕获“主页”选项卡按钮和其他选项卡以及下方和下方的按钮,但是如果我在列表上拖动交叉头发工具,它会一直挂起应用程序,直到我关闭它

enter image description here

为listitem行enter image description here捕获的visualstudio

在为主窗口运行getchildren之后,然后为listitem控件获取父级层次结构,这就是它们看起来像enter image description here的样子

uwp automated-tests coded-ui-tests
1个回答
0
投票

我可能有你的问题的替代方案。下面的代码将采用父控件并通过它进行筛选,直到所有子项以递归方式添加,尊重控件层次结构。这样,您将在运行时拥有所有可用的listview项。如果在列表视图项集合发生更改时使KeyValuePair保持最新,则控制未找到的异常不应成为问题。

使用这种递归方法:

    public ParentControl GetChildControls(UITestControl parentControl)
    {
        ParentControl parent = new ParentControl();

        if (parentControl != null)
        {
            List<ParentControl> children = new List<ParentControl>();

            foreach (UITestControl childControl in parentControl.GetChildren())
            {
                children.Add(GetChildControls(childControl));
            }

            parent.Children = new KeyValuePair<UITestControl, List<ParentControl>>(parentControl, children);
        }

        return parent;
    }

ParentControl对象:

public class ParentControl
{
    public KeyValuePair<UITestControl, List<ParentControl>> Children { get; set; }
    public string Value
    {
        get
        {
            return Children.Key.Name;
        }
    }
}

儿童酒店是强制性的,其他酒店是可选的。

© www.soinside.com 2019 - 2024. All rights reserved.