Как получить доступ к тексту ClassName RichTextBox

Я пытаюсь найти документ в своем окне, в котором есть текстовое поле с форматированным текстом, используя TestStack White, и извлечь этот текст.

Я пытался использовать UIItem Label & TextBox, но Уайт, похоже, не смог найти объект во время моего теста. Объект можно найти с помощью общего UIItem, но я хочу иметь доступ к тексту, который он содержит.

Я реализую это так:

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

и я хотел бы иметь возможность сказать:

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

Но он не может найти то, что я ищу, если я помечаю его как Label или TextBox, и у меня нет доступа к .Text, если я объявлю его UIItem.


person Dumpcats    schedule 13.09.2016    source источник


Ответы (1)


Вы хотите использовать тип TextBox. Затем вы можете использовать BulkText для доступа к тексту в RichEditBox.

Сначала окно:

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

Затем найдите 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_;
     } 
}

Затем используйте следующее для доступа к тексту:

string data = RichEditDocument.BulkText;

Вот комментарии к коду для использования 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; }

Вот комментарии к использованию 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.
person Matt Johnson    schedule 15.09.2016