使用TestStack.White测试时如何处理DataGrid值? [英] How can I manipulate DataGrid values when testing with TestStack.White?
问题描述
我有一个使用DataGrid来显示联系人列表的应用程序. 8列,其中4列代表客户信息(字符串),其余4列为CheckBox(出于测试目的,我将全部设置为true).
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).
使用TestStack.White,我可以通过它获得DataGrid控件(即使元素是表格):
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
但是,即使它可以编译并运行,也无法正常工作.当我返回并使用调试器时,单元格[0,0]的值仍然为空.
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.
我似乎无法解决这个问题.我也尝试过使用Rows.Add(),但似乎永远无法获得正确的语法.
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.
推荐答案
实际上,我已经找到了答案(有点).
Actually, I have found the answer (sort of).
我无法解释为什么SetValue不起作用,但是如果我将代码行更改为:
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.
这篇关于使用TestStack.White测试时如何处理DataGrid值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!