How can I manipulate DataGrid values โ€‹โ€‹while testing with TestStack.White?

I have an application that uses a DataGrid to display a list of contacts. 8 columns, 4 representing customer information (rows), and the remaining 4 columns are CheckBoxes (for testing purposes, I set all to true).

Using TestStack.White I can get a DataGrid control through this (although the element is a table):

var distributionGrid = window.Get<Table>(SearchCriteria.ByAutomationId("DistributionGrid")); 

But I have not yet been able to add the lines. I tried:

 distributionGrid.Rows[0].Cells[0].SetValue(firstName); // firstName is a string 

But this did not work, although it compiles and runs. When I go back and use the debugger, the value of the cell [0,0] is still zero.

I can not work with this. I also tried using Rows.Add (), but I can never get the correct syntax that seems.

+1
source share
4 answers

Actually, I found the answer (sort of).

I cannot explain why SetValue does not work, but if I changed the line of code to:

 distributionGrid.Rows[0].Cells[0].Value = firstName; 

Everything works as expected. Thanks to everyone who looked into this.

+1
source

I like it:

 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 is hacked.

+4
source

The latest version of TestStack.White does not provide a Value property. I use the following lines to simulate user actions:

  var match = FindMatchingRow(SomeSearchCriteria); var cell = match.Cells[fieldName]; cell.Click(); cell.Enter(fieldValue); Keyboard.Instance.PressSpecialKey(KeyboardInput.SpecialKeys.RETURN); 
0
source

Another option than casting to a ListView is to read each row. This was necessary for me, because inside my DataGrid there were different objects that changed the number of column rows.

 var column3 = mainWindow.GetMultiple(SearchCriteria.ByAutomationId("Column3")); var column3cell0 = (CheckBox)column3[0]; var column3cell0State = column3cell0.State; 

But I still have a problem with accessing the DataGridTextColumn, which has only text but no other UI object inside. Teststack-white does not recognize this cell as a user interface element and leaves the array empty. I think I should change the implementation to add a text box.

0
source

Source: https://habr.com/ru/post/1241589/


All Articles