【问题标题】:How to done the LeanFt testing for DataGrid in WPF?如何在 WPF 中对 DataGrid 进行 LeanFt 测试?
【发布时间】:2017-02-14 01:35:09
【问题描述】:

我已经创建了leaft 项目并使用DataGrid 创建了一个示例,但是它抛出了 table is not found 异常,而且我不确定在leaft 中测试DataGrid 的方式。有人可以帮忙解决这个问题吗?

数据网格示例:

<Window x:Class="WpfApplication12.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        x:Name="datagrid_window"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <DataGrid x:Name="msdatagrid" AutoGenerateColumns="True">            
        </DataGrid>
    </Grid>
</Window>

我已经从后面的代码中设置了这个数据网格的 itemsource。

Leanft 测试方法:

public void TestMethod1()
{
    SDK.Init(new SdkConfiguration());
    Reporter.Init(new ReportConfiguration());
    Process.Start(@"..\..\..\Debug\WpfApplication12.exe");
    IWindow win = Desktop.Describe<IWindow>(new WindowDescription
        {
            IsChildWindow = false,
            IsOwnedWindow = false,
            AccessibleName = @"datagrid_window",
        });

    ITable table = win.Describe<ITable>(new TableDescription
        {
            Name = @"msdatagrid"
        });

    table.SelectCell(1, 1);
}

【问题讨论】:

    标签: wpf testing wpfdatagrid leanft


    【解决方案1】:

    未找到测试对象异常意味着您没有为测试对象或其父对象创建正确的描述。 尝试使用对象识别中心来监视数据网格,复制描述(使用底部的第二个左按钮)并将其粘贴到您的测试中。

    更多关于 OIC 的信息在这里: http://leanft-help.saas.hp.com/en/latest/HelpCenter/Content/HowTo/TestObjects_OIC.htm

    在你的情况下,它看起来像这样:

    var table = Desktop.Describe<IWindow>(new WindowDescription
    {
        ObjectName = @"datagrid_window",
        FullType = @"window",
        WindowTitleRegExp = @"MainWindow"
    }).Describe<ITable>(new TableDescription
    {
        ObjectName = @"msdatagrid"
    });
    

    这是您可以访问数据网格单元格的方式,例如:

    var firstCell = table.Rows[0].Cells[1];
    Assert.AreEqual("World", firstCell.Value);
    firstCell.SetValue("World1");
    

    确保根据您使用的技术添加了正确的 using 语句。 每个技术测试对象都定义在一个专用的命名空间中。 对于 WPF,它应该是:

    using HP.LFT.SDK.WPF;
    

    您使用了 HP.LFT.SDK.StdWin 命名空间中的 WindowDescription(根据其属性)。 HP.LFT.SDK.StdWin 是本机 Windows 控件测试对象的命名空间,您无法从 StdWin 命名空间描述 Window 上的 WPF 测试对象。

    请注意,对于桌面应用程序,最好只运行一个应用程序实例。

    我还可以看到您正在初始化 SDK 和 Reporter。 建议使用 Visual Studio LeanFT 项目模板,该模板已经包含您需要的所有内容(引用、初始化)来开始编写测试代码。 模板可以在 Visual Studio 的 New Project 对话框的 C#\Test 部分下找到。

    希望对你有帮助!

    【讨论】:

      猜你喜欢
      • 2010-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多