2

In Coded UI, I have to confirm a particular text is present in text-box.

I am able to reach up to the dialog box and i know how to enter text. However. now i need to read text from the box.

Is there a WinApplication command that can help me to do so?

1 Answers1

0

You can just read the text out in the same way that an assertion reads the text to check its value. One way of learning how to do this on any control is to use the Coded UI recorder to create an assertion method on the text shown and copy its code. Commonly the assertion will be on the DisplayText field. In fact that is a neat way of getting the relevant UI Controls created for you.

The method created for the assertion (in the UIMap.Designed.cs file) will be similar to:

public void AssertMethod1()
{
    SomeUIType uITTextItem = this.UISomeWindow.UISomewhere.UITextItem;
    Assert.AreEqual(this.AssertMethod1ExpectedValues.UITextItemDisplayText,
                    uITextItem.DisplayText,
                    "A message for a failed assertion");
}

Just copy the whole method into the UIMap.cs file, use the commend in the UI Map editor. Then save all the files.

Edit the method that is now in the UIMap.cs file to something like the following:

public string GetTheUITextItem()
{
    SomeUIType uITTextItem = this.UISomeWindow.UISomewhere.UITextItem;
    return this.AssertMethod1ExpectedValues.UITextItemDisplayText;
}

Now the contents of the test can be obtained by calling GetTheUITextItem().

AdrianHHH
  • 13,492
  • 16
  • 50
  • 87