vendredi 19 février 2016

Accessing a WinCheckBox within a cell of a grid, given a reference to the first cell in the row

I am trying to test an application using MTM. The built-in record-and-playback mechanism is unable to deal with the way this application is built, so I'm trying to construct a work-around.

I have a grid, something akin to the following

|[]|[ Fruit  ]|[ Read ]|[ Write ]|[ Execute ]|
|  | apple    |   [ ]  |   [ ]   |   [ ]     |
|  | banana   |   [ ]  |   [ ]   |   [ ]     |
|  | coconut  |   [ ]  |   [ ]   |   [ ]     |

The cells in the intersections are check boxes. When I learn the checkbox for the Read column for the Banana row, it works. When I try to learn the checkbox for the Write column, it thinks it already knows it, but it is really the one for the Read column. It just learns it as "UIUncheckedCell" and as a result really only can recognize the first checkbox in the row. This is what I'm trying to work around, preferably without anything in the GUI map except the Table. What is very interesting is that it records it differently if I have focused the cell first before I try to learn the checkbox or not. That makes me a bit suspicious.

I've already got a function that I can pass in the table and the name of the fruit, and it will search the table/grid for the row that has that fruit in the first column. So far so good.

public WinCell FindCellInTable( WinTable table, int colIndex, string value )

What I would like is a function that I can give a column name, and it searches the table for the column, and returns a column number. (Sounds easy enough)

public int FindColumnOfHeader( WinTable table, String columnName )

Then, another function, I give it the cell reference to the cell with the fruit in it, and it navigates up from the Cell to the Row, then from the Row to the Cells list, and then uses that index to find the Cell for the appropriate column, and finally hands me back a WinCheckBox object that I can use to check or uncheck the cell.

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

I can't figure out how to go from the cell reference to the checkbox within the cell, or even if there is a checkbox in the cell, or if it just looks like a checkbox, or what.

Thanks in advance for sharing your expertise!




Aucun commentaire:

Enregistrer un commentaire