Reputation: 16730
I have an application that uses a DataGrid to display a list of contacts. 8 columns, 4 representing customer information (strings) and the other 4 are CheckBoxes (that for testing purposes I will set all to true).
Using TestStack.White I am able to get the DataGrid control through this (even though the element is table):
var distributionGrid = window.Get<Table>(SearchCriteria.ByAutomationId("DistributionGrid"));
But I haven't yet been able to add rows. I tried:
distributionGrid.Rows[0].Cells[0].SetValue(firstName); // firstName is a string
But that didn't work, even though it compiles and runs. When I go back and use the debugger, the value of cell [0,0] is still null.
I can't seem to work this one out. I have also tried using Rows.Add() but I can never get the right syntax it seems.
Upvotes: 1
Views: 5556
Reputation: 1
Another possibility, than cast to ListView, is to read each single row. This was necessary at me, because my DataGrid has different objects inside, which changed the number of some row-columns.
var column3 = mainWindow.GetMultiple(SearchCriteria.ByAutomationId("Column3"));
var column3cell0 = (CheckBox)column3[0];
var column3cell0State = column3cell0.State;
But my problem left is to access the DataGridTextColumn which has only text, but no other UI-object inside. Teststack-white does not recognize this cell as UI-item, and leave the array empty. I think I must change the implementation an add a Textfield.
Upvotes: 0
Reputation: 636
The latest version of TestStack.White does not expose Value property. I'm using the following lines to simulate the User Actions:
var match = FindMatchingRow(SomeSearchCriteria);
var cell = match.Cells[fieldName];
cell.Click();
cell.Enter(fieldValue);
Keyboard.Instance.PressSpecialKey(KeyboardInput.SpecialKeys.RETURN);
Upvotes: 0
Reputation: 17600
I did like this:
var dataGrid = page.Get<ListView>(AutomationIds.MyDataGridId);
var cell = dataGrid.Rows[0].Cells[1];
cell.Click();
cell.Enter("New Value");
dataGrid.Select(1); // lose focus
Felt hacky.
Upvotes: 4
Reputation: 16730
Actually, I have found the answer (sort of).
I can't explain why SetValue wouldn't work, but if I changed the line of code to:
distributionGrid.Rows[0].Cells[0].Value = firstName;
Everything works as expected. Thanks to anyone who looked into this.
Upvotes: 1