2016-09-13 30 views
-1

我試圖在我的窗口中使用TestStack White在其中具有文本框的文本框中查找文檔,並提取該文本。如何訪問ClassName RichTextBox的文本

我試過使用UIItem標籤& TextBox,但White在我的測試過程中似乎無法找到對象。該對象可以使用通用UIItem找到,但我希望能夠訪問它所保存的文本。

我實現它想:

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

,我想能夠說:

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

但它無法找到我什麼尋找是否將它標記爲Label或TextBox,如果我將其聲明爲UIItem,則無法訪問.Text。

回答

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; 

以下是使用代碼註釋白色文本方法:

// 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.