1

I'm new to coded UI testing, can someone help me on how to retrieve a textbox value as I keep on getting null value. I added an assertion to my method which validates the value of a textbox, however if keeps on failing since the actual data is always null. Below is my sample code. Thanks in advance for the help.

Here is my test method in the CodeUItest class

[TestMethod]
    public void TBParameterTest()
    {
        this.UIMap.ValidateTBValue();            
    }


 public void ValidateTBValue()
    {
        #region Variable Declarations
        WinEdit uIItemEdit = this.UIContigoWindow.UIItemCell.UIItemEdit;


        #endregion

        // Verify that the 'Text' property of text box equals '1200'
        Assert.AreEqual(this.ValidateTBValueExpectedValues.UIItemEditText, uIItemEdit.Text, "Not equal to previous value when parameter is not yet modified");
    }

the uIItemEdit.Text is always null even if the value in the webpage is equal to 1200.

Thanks!

4

1 回答 1

0

您可以通过两种不同的方式解决此问题:

  1. 更好的选择是调整搜索属性以搜索一些唯一标识符(名称、类...)。

  2. 第二个选项,如果开发人员无法找到或添加唯一标识符,则使用FindMatchingControls()每个UITestControl人都有的。这将为您提供所有控件,在您的情况下,所有WinEditSearchProperties. 在这个控件集合上,您可以运行链接查询以找到所需的控件,或运行类似的东西:

var controls= myControl.FindMatchingControls()l

foreach (var control in controls) 
{ 
    control.DrawHighlight();
}

这将使您能够找到所需的控件。从这一点开始,您可以直接调用它并获取它的文本值:

var textValue = controls[index].Text;

并将此值用于您的断言。

于 2015-01-29T11:30:57.113 回答