0
votes

I am working on a WPF application which has several custom controls. I am using coded UI test builder to create a script for my application testing. When I run the test, it gives me an exception and the exception occurs at the line shown below.

uIRadComboBoxComboBox.SelectedItem = this.SelectingWeddingParams.UIRadComboBoxComboBoxSelectedItem;

I have tried using mouse clicks and changing the coordinates but that does not work as well.

The code for the function is

region Variable Declarations

        WpfCustom uIItemCustom = this.UIIntelliClientWindow.UIItemCustom;
        WpfComboBox uIRadComboBoxComboBox = this.UIIntelliClientWindow.UIEventInfoRegionCustom1.UIPleasewaitProgressBar.UIRadComboBoxComboBox;
        #endregion


        // Click custom control
        Mouse.Click(uIItemCustom, new Point(448, 307));

        // Select 'Wedding' in 'RadComboBox' combo box
        uIRadComboBoxComboBox.SelectedItem = this.SelectingWeddingParams.UIRadComboBoxComboBoxSelectedItem;

The exception is pasted below.

Result StackTrace:
at Microsoft.VisualStudio.TestTools.UITest.Playback.Engine.IScreenElement.FindAllDescendants(String bstrQueryId, Object& pvarResKeys, Int32 cResKeys, Int32 nMaxDepth) at Microsoft.VisualStudio.TestTools.UITest.Playback.ScreenElement.FindAllScreenElement(String queryId, Int32 depth, Boolean singleQueryId, Boolean throwException, Boolean resetSkipStep) at Microsoft.VisualStudio.TestTools.UITest.Playback.ScreenElement.FindScreenElement(String queryId, Int32 depth, Boolean resetSkipStep) at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.FindFirstDescendant(String queryId, Int32 maxDepth, Int32& timeLeft) --- End of inner exception stack trace --- at Microsoft.VisualStudio.TestTools.UITesting.Playback.MapControlNotFoundException(COMException ex, IPlaybackContext context) at Microsoft.VisualStudio.TestTools.UITesting.Playback.MapAndThrowComException(COMException innerException, IPlaybackContext context) at Microsoft.VisualStudio.TestTools.UITesting.Playback.MapAndThrowException(Exception exception, IPlaybackContext context) at Microsoft.VisualStudio.TestTools.UITesting.Playback.MapAndThrowException(Exception exception, String queryId) at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.FindFirstDescendant(String queryId, Int32 maxDepth, Int32& timeLeft) at Microsoft.VisualStudio.TestTools.UITesting.SearchHelper.GetElement(Boolean useCache, ISearchArgument searchArg) at Microsoft.VisualStudio.TestTools.UITesting.SearchHelper.Search(ISearchArgument searchArg) at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.FindInternal() at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.FindControlIfNecessary() at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.SetPropertyPrivate(String propertyName, Object value) at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.<>c__DisplayClass180_0.b__0() at Microsoft.VisualStudio.TestTools.UITesting.CodedUITestMethodInvoker.InvokeMethod[T](Func`1 function, UITestControl control, Boolean firePlaybackErrorEvent, Boolean logAsAction) at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.SetProperty(String propertyName, Object value) at Microsoft.VisualStudio.TestTools.UITesting.WpfControls.WpfComboBox.set_SelectedItem(String value) at AddingEventUsingDataDrivenTesting.UIMap.SelectingWedding() in C:\Users\Dev2\source\repos\AddingEventUsingDataDrivenTesting\AddingEventUsingDataDrivenTesting\UIMap.Designer.cs:line 166 at AddingEventUsingDataDrivenTesting.CodedUITest1.CodedUITestMethod1() in C:\Users\Dev2\source\repos\AddingEventUsingDataDrivenTesting\AddingEventUsingDataDrivenTesting\CodedUITest1.cs:line 30 Result Message: Test method AddingEventUsingDataDrivenTesting.CodedUITest1.CodedUITestMethod1 threw exception: Microsoft.VisualStudio.TestTools.UITest.Extension.UITestControlNotFoundException: The playback failed to find the control with the given search properties. Additional Details: TechnologyName: 'UIA' FrameworkId: 'Wpf' ControlType: 'ComboBox' HelpText: 'RadComboBox' Instance: '2' Search may have failed at '' TabList as it may have virtualized children. If the control being searched is descendant of '' TabList then including it as the parent container may solve the problem. ---> System.Runtime.InteropServices.COMException: Error HRESULT E_FAIL has been returned from a call to a COM component.

1
Custom controls need to be written to support Coded UI. Perhaps you should ask the authors or the providers of the custom controls about what level of support they provide for Coded UI. - AdrianHHH

1 Answers

0
votes

I face the same issue when I try to automate the wpf controls with coded UI. The best solution I would like to suggest is to use Appium WinAppDriver(If it is possible for you) as it supports the wpf controls as mentioned my Microsoft team.

here is the guide to : How to use WinAppDriver

CodedUI will be deprecated after Visual studio 2019(mentioned by one of the member of microsoft team in a video) although support will be there.

And for the work around I would suggest you to use the Keyboard.Sendkeys() to set the combobox. for exmaple :-

UITestControl combobox = new UITestControl(); 
//add properties of combobox

WinEdit textboxOfCombobox = new WinEdit(comboBox);

textboxOfCombobox.SendKeys("value to enter");
// Add code to verify if the combobox has the correct value selected.

This workaround I use personally and it works for me. I hope this helps.