2017-03-17 73 views
0

我試圖創建一個運行我的應用程序的測試,然後在使用CodedUI.This領域的文字是我的代碼:編碼的UI:HRESULT E_FAIL已從調用返回至COM組件

var app = ApplicationUnderTest.Launch(@"C:\app.exe"); 
var loginEdit = new WinEdit(); 
loginEdit.SearchProperties.Add(WinEdit.PropertyNames.ControlName, "textEditLogin"); 
loginEdit.Text = "test005"; 

錯誤:System.NotSupportedException: SetProperty "Text" is not supported on control type: Window.

如果我用這個代碼:

Keyboard.SendKeys(loginEdit, "test005"); 

我有錯誤:Microsoft.VisualStudio.TestTools.UITest.Extension.PlaybackFailureException: (Failed to get the message for an exception of type Microsoft.VisualStudio.TestTools.UITest.Extension.PlaybackFailureException due to an exception.) ---> System.Runtime.InteropServices.COMException: HRESULT E_FAIL has been returned from a call to a COM component

這是我WinEdit的屬性: WinEdit

可能是什麼問題呢?

+0

這是一個WinWindow,而不是WinEdit。使用[基礎教程](http://www.evoketechnologies.com/blog/windows-automation-testing-coded-ui/)來獲得這個權利。 –

+0

我真的不明白爲什麼那個控件是WinWindow? 由於此控件的ControlType是「編輯」。如果是WinWindow,我如何在這個控件中輸入文本? –

+0

當我更改loginEdit(WinWindow)的控制類型並嘗試「Keyboard.SendKeys(loginEdit,」test005「);」我有同樣的錯誤。 –

回答

0

問題出在對象瀏覽器,我沒有看到我需要的控件。 我用錄音機找到我的WinEdit並寫下如下代碼:

var loginWindow = new WinWindow(); 


loginWindow.SearchProperties[WinWindow.PropertyNames.Name] = "layoutControl1"; 
loginWindow.SearchProperties.Add(new PropertyExpression(WinWindow.PropertyNames.ClassName, "WindowsForms10.Window", PropertyExpressionOperator.Contains)); 

var loginEdit = new WinEdit(loginWindow); 
loginEdit.WindowTitles.Add("layoutControl1"); 

Keyboard.SendKeys(loginEdit, "test005"); 
+0

未來您可能想採用的一種技術是使用[Draw Highlight](https://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.uitesting.uitestcontrol.drawhighlight.aspx)確定你正試圖與正確的控制進行交互。 – Ryanman

相關問題