在给定对行中第一个单元格的引用的情况下,访问网格单元格内的WinCheckBox

在给定对行中第一个单元格的引用的情况下,访问网格单元格内的WinCheckBox,checkbox,visual-studio-2015,microsoft-test-manager,Checkbox,Visual Studio 2015,Microsoft Test Manager,我正在尝试使用MTM测试应用程序。内置的录制和播放机制无法处理此应用程序的构建方式,因此我正在尝试构建一个解决方案 我有一个网格,类似于下面的 |[]|[ Fruit ]|[ Read ]|[ Write ]|[ Execute ]| | | apple | [ ] | [ ] | [ ] | | | banana | [ ] | [ ] | [ ] | | | coconut | [ ] | [ ] |

我正在尝试使用MTM测试应用程序。内置的录制和播放机制无法处理此应用程序的构建方式,因此我正在尝试构建一个解决方案

我有一个网格,类似于下面的

|[]|[ Fruit  ]|[ Read ]|[ Write ]|[ Execute ]|
|  | apple    |   [ ]  |   [ ]   |   [ ]     |
|  | banana   |   [ ]  |   [ ]   |   [ ]     |
|  | coconut  |   [ ]  |   [ ]   |   [ ]     |
交叉点中的单元格是复选框。当我了解到香蕉行的Read列的复选框时,它就起作用了。当我尝试学习Write列的复选框时,它认为它已经知道了,但实际上它是Read列的复选框。它只是将其学习为“UIUncheckedCell”,因此实际上只能识别行中的第一个复选框。这就是我试图解决的问题,最好在GUI映射中除了表之外没有任何内容。非常有趣的是,如果我在尝试学习复选框之前先聚焦单元格,它会以不同的方式记录它。这让我有点怀疑

我已经有了一个函数,我可以将它传递到表和水果的名称中,它将在表/网格中搜索第一列有水果的行。到目前为止还不错

public WinCell FindCellInTable( WinTable table, int colIndex, string value )
我想要的是一个函数,我可以给它一个列名,它在表中搜索该列,并返回一个列号。(听起来很简单)

然后,另一个函数,我给它一个单元格引用,指向其中有水果的单元格,它从单元格向上导航到行,然后从行导航到单元格列表,然后使用该索引找到相应列的单元格,最后还给我一个WinCheckBox对象,我可以用它来检查或取消检查单元格

public WinCheckBox GetCheckboxFor( WinCell cell, int colIndex )
{
    // I think this is the way to get there - it compiles at least!
    WinRow row = new WinRow( cell.GetParent() );
    UITestControlCollection cells = row.Cells;
    UITestControl targetCell = cells[colIndex];
    // But then what do I do?
    // I tried this, but it didn't work 
    // (compiles but does not work for setting the checkbox):
    WinCheckBox cb = new WinCheckBox( targetCell );
    return cb;
}
我不知道如何从单元格引用转到单元格中的复选框,或者单元格中是否有复选框,或者它是否看起来像复选框,或者什么


提前感谢您分享您的专业知识

结果表明,单元格中出现的复选框实际上并不存在。当我单击一个单元格并学习复选框时,每个单元格中的所有复选框都作为同一对象学习

解决方案是了解一个复选框UIMap条目,然后单击我尝试与之交互的单元格,以强制该对象出现在UI中。一旦单元格有了焦点,我就可以与commoncheckbox控件元素交互,它可以在可视地显示在网格单元格中的checkbox实例上工作

虽然很难看,但它很管用

如果有人有更好的答案

public WinCheckBox GetCheckboxFor( WinCell cell, int colIndex )
{
    // I think this is the way to get there - it compiles at least!
    WinRow row = new WinRow( cell.GetParent() );
    UITestControlCollection cells = row.Cells;
    UITestControl targetCell = cells[colIndex];
    // But then what do I do?
    // I tried this, but it didn't work 
    // (compiles but does not work for setting the checkbox):
    WinCheckBox cb = new WinCheckBox( targetCell );
    return cb;
}