0

I'm attempting to find a document on my window that has a rich text box with text in it using TestStack White, and extract that text.

I've tried to use the UIItem Label & TextBox, but White doesn't seem to be able to find the object during my test. The object can be found using the generic UIItem, but I want to be able to access the text it holds.

I'm implementing it like:

public [Unsure] MyRichTextBox { get { return Window.Get<[Unsure]>(SearchCriteria.ByClassName("RichTextBox")); } }

and I'd like to be able to say:

Assert.That(MyRichTextBox.Text.Equals(x));

But it can't find what I'm looking for if I tag it as a Label or a TextBox, and I don't have access to .Text if I declare it a UIItem.

Suhaib Ahmad
  • 487
  • 6
  • 25
Dumpcats
  • 453
  • 5
  • 21

1 Answers1

2

You want to use the type of TextBox. Then you can use BulkText to access the text in the RichEditBox.

First the Window:

TestStack.White.UIItems.WindowItems.Window _mainWindow;    
app = TestStack.White.Application.Launch(startInfo);
_mainWindow = app.GetWindow("MyDialog");

Then Find the richEditBox:

public string _richeditdocument_ID = "rtbDocument";
private TextBox _richeditdocument_ = null;
public TextBox RichEditDocument 
{ 
    get 
    { 
         if (null == _richeditdocument_) 
                 _richeditdocument_ = _mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId(_richeditdocument_ID)); 
                 return _richeditdocument_;
     } 
}

Then use the following to access the text:

string data = RichEditDocument.BulkText;

Here are the code comments for using the Text Method in White:

    // Summary:
    //     Enters the text in the textbox. The text would be cleared first. This is
    //     not as good performing as the BulkText method. This does raise all keyboard
    //     events - that means that your string will consist of letters that match the
    //     letters of your string but in current input language.
    public virtual string Text { get; set; }

Here are the comments for using BulkText:

        // Summary:
        //     Sets the text in the textbox. The text would be cleared first. This is a
        //     better performing than the Text method. This doesn't raise all keyboard events.
        //      The string will be set exactly as it is in your code.
Matt Johnson
  • 1,913
  • 16
  • 23