2017-03-17 36 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

相关问题