0

I have created leanft project and created a sample with DataGrid, but it throws table was not found exception and also I am not sure the way of testing of DataGrid in leanft. Could you anyone help on this to fix this?

Datagrid sample:

<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>

I have set the itemsource for this datagrid from the code behind.

Leanft Test method:

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);
}
Motti
  • 110,860
  • 49
  • 189
  • 262
krish bala
  • 49
  • 8

1 Answers1

3

A test object not found exception means you didn’t create a correct description for your test object or its parent. Try using the object identification center to spy for the datagrid, copy the description (using the second left button on the bottom) and paste it into your test.

More info about OIC is here: http://leanft-help.saas.hp.com/en/latest/HelpCenter/Content/HowTo/TestObjects_OIC.htm

In your case it will look like this:

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

This is how you can access datagrid cells for example:

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

Make sure you added the correct using statement according to the technology you are using. Each technology test objects are defined in a dedicated namespace. For WPF it should be:

using HP.LFT.SDK.WPF;

You used WindowDescription from the HP.LFT.SDK.StdWin namespace (according to its properties). HP.LFT.SDK.StdWin is a namespace for native windows controls test objects and you can’t describe a WPF test object on a Window from StdWin namespace.

Note that for desktop applications, it is better if only one instance of the application is running.

I can also see that you are initializing the SDK and the Reporter. It is recommended to use the visual studio LeanFT project template that already contain all you need (references, initialization) to start coding your tests. The templates can be found under the C#\Test section in the New Project dialog of visual studio.

Hope it helps!

Roman Mirochnik
  • 196
  • 1
  • 8