Joe Loyzaga

Joe Loyzaga

  • NA
  • 1
  • 1.5k

Newbie needs help with c# and automating a wpf application

Sep 17 2015 8:22 PM
this is my very basic code (i'm trying automate some tests on an application and am using messagebox to display my progress thru the app) I get passed "here 3" but I get stuck further with an error below code

1.Is there a way to highlight all the controls within eventTab2 (or any object that I nominate?like some sort of recursive get?) and also return the type of object it is with all it properties?
2. Could you explain the solution above so I can manipulate it (remember newbie)

THANKS!!!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
var mainWindow1 = new WpfWindow();
mainWindow1.SearchProperties[WpfWindow.PropertyNames.Name] = "IntraBet [1.4.0.103] EQ3WNSTDB11";
mainWindow1.SearchProperties.Add(new PropertyExpression(UITestControl.PropertyNames.ClassName, "HwndWrapper",
PropertyExpressionOperator.Contains));
mainWindow1.WindowTitles.Add("IntraBet [1.4.0.103] EQ3WNSTDB11");
mainWindow1.DrawHighlight();
var eventStack1 = new WpfCustom();
var eventStack0 = new WpfCustom();
var eventTab0 = new WpfTitleBar(mainWindow1);
var eventTab1 = new WpfMenu(mainWindow1);
var eventTab2 = new WpfTabList(mainWindow1);
var eventTab3 = new WpfTreeItem(eventTab2);
var eventTab4 = new WpfText(mainWindow1);
MessageBox.Show("got here0");
eventTab1.SearchProperties[WpfMenu.PropertyNames.AutomationId] = "menubar";
eventTab1.DrawHighlight();
MessageBox.Show("got here2");
eventTab3.SearchProperties[WpfControl.PropertyNames.ClassName] = "MenuItem";
eventTab3.DrawHighlight();
MessageBox.Show("got here4");
eventTab2.SearchProperties[WpfTabList.PropertyNames.AutomationId] = "windows";
eventTab2.DrawHighlight();
MessageBox.Show("got here3");
eventTab0.SearchProperties[WpfCheckBox.PropertyNames.AutomationId] = "chkIncludeSetted";
eventTab0.DrawHighlight();
MessageBox.Show("got here1");


ERRoR
Test Name: CodedUITestMethod1
Test FullName: MSUItest.CodedUITest1.CodedUITestMethod1
Test Source: g:\CodedUITest1.cs : line 39
Test Outcome: Failed
Test Duration: 0:00:51.9135788


Result Message:
Test method MSUItest.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: 'TreeItem'
ClassName: 'MenuItem'
Search may have failed at 'windows' TabList as it may have virtualized children. If the control being searched is descendant of 'windows' 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.
Result StackTrace:
at Microsoft.VisualStudio.TestTools.UITest.Playback.E ngine.IScreenElement.FindAllDescendants(String bstrQueryId, Object& pvarResKeys, Int32 cResKeys, Int32 nMaxDepth)
at Microsoft.VisualStudio.TestTools.UITest.Playback.S creenElement.FindAllScreenElement(String queryId, Int32 depth, Boolean singleQueryId, Boolean throwException, Boolean resetSkipStep)
at Microsoft.VisualStudio.TestTools.UITest.Playback.S creenElement.FindScreenElement(String queryId, Int32 depth, Boolean resetSkipStep)
at Microsoft.VisualStudio.TestTools.UITesting.UITestC ontrol.FindFirstDescendant(String queryId, Int32 maxDepth, Int32& timeLeft)
--- End of inner exception stack trace ---
at Microsoft.VisualStudio.TestTools.UITesting.Playbac k.MapControlNotFoundException(COMException ex, IPlaybackContext context)
at Microsoft.VisualStudio.TestTools.UITesting.Playbac k.MapAndThrowComException(COMException innerException, IPlaybackContext context)
at Microsoft.VisualStudio.TestTools.UITesting.Playbac k.MapAndThrowException(Exception exception, IPlaybackContext context)
at Microsoft.VisualStudio.TestTools.UITesting.Playbac k.MapAndThrowException(Exception exception, String queryId)
at Microsoft.VisualStudio.TestTools.UITesting.UITestC ontrol.FindFirstDescendant(String queryId, Int32 maxDepth, Int32& timeLeft)
at Microsoft.VisualStudio.TestTools.UITesting.SearchH elper.GetElement(Boolean useCache, ISearchArgument searchArg)
at Microsoft.VisualStudio.TestTools.UITesting.SearchH elper.Search(ISearchArgument searchArg)
at Microsoft.VisualStudio.TestTools.UITesting.UITestC ontrol.FindInternal()
at Microsoft.VisualStudio.TestTools.UITesting.UITestC ontrol.FindControlIfNecessary()
at Microsoft.VisualStudio.TestTools.UITesting.UITestC ontrol.DrawHighlightPrivate()
at Microsoft.VisualStudio.TestTools.UITesting.UITestC ontrol.<DrawHighlight>b__36()
at Microsoft.VisualStudio.TestTools.UITesting.CodedUI TestMethodInvoker.InvokeMethod[T](Func`1 function, UITestControl control, Boolean firePlaybackErrorEvent, Boolean logAsAction)
at Microsoft.VisualStudio.TestTools.UITesting.UITestC ontrol.DrawHighlight()
at MSUItest.CodedUITest1.CodedUITestMethod1() in g:\CodedUITest1.cs:line 76