{"action":"created","issue":{"url":"https://api.github.com/repos/icnocop/cuite/issues/61","repository_url":"https://api.github.com/repos/icnocop/cuite","labels_url":"https://api.github.com/repos/icnocop/cuite/issues/61/labels{/name}","comments_url":"https://api.github.com/repos/icnocop/cuite/issues/61/comments","events_url":"https://api.github.com/repos/icnocop/cuite/issues/61/events","html_url":"https://github.com/icnocop/cuite/issues/61","id":134279801,"number":61,"title":"Can't find controls in a wpf window","user":{"login":"aannenko","id":4640265,"avatar_url":"https://avatars.githubusercontent.com/u/4640265?v=3","gravatar_id":"","url":"https://api.github.com/users/aannenko","html_url":"https://github.com/aannenko","followers_url":"https://api.github.com/users/aannenko/followers","following_url":"https://api.github.com/users/aannenko/following{/other_user}","gists_url":"https://api.github.com/users/aannenko/gists{/gist_id}","starred_url":"https://api.github.com/users/aannenko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aannenko/subscriptions","organizations_url":"https://api.github.com/users/aannenko/orgs","repos_url":"https://api.github.com/users/aannenko/repos","events_url":"https://api.github.com/users/aannenko/events{/privacy}","received_events_url":"https://api.github.com/users/aannenko/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-02-17T13:27:11Z","updated_at":"2016-02-17T13:54:44Z","closed_at":null,"body":"**My platform:** WIn 10 Pro x64, VS 2013 Ultimate Update 5\r\n\r\n**Main project with the app:**\r\n\r\n**MainWindow.xaml**\r\n\r\n```\r\n<Window  x:Class=\"TestWpfApplication.MainWindow\"\r\n        xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"\r\n        xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\"\r\n        Title=\"MainWindow\" Height=\"164\" Width=\"256\" Name=\"TestWpfApplication\">\r\n    <Grid VerticalAlignment=\"Top\">\r\n        <StackPanel Margin=\"8\">\r\n            <TextBox Name=\"FirstNameTextBox\" Height=\"23\" TextWrapping=\"Wrap\" VerticalAlignment=\"Top\" Width=\"120\" Text=\"First Name\"/>\r\n            <TextBox Name=\"LastNameTextBox\" Height=\"23\" Margin=\"0,8\" TextWrapping=\"Wrap\" Text=\"Last Name\" VerticalAlignment=\"Top\" Width=\"120\"/>\r\n            <Button Name=\"GreetingsButton\"  Content=\"Say Hey!\" VerticalAlignment=\"Top\" Width=\"75\" Margin=\"0,0,0,8\" Click=\"Button_Click\"/>\r\n            <TextBlock Name=\"GreetingsTextBlock\" TextAlignment=\"Center\" TextWrapping=\"Wrap\" Text=\"You'll see your greeting here\"/>\r\n        </StackPanel>\r\n    </Grid>\r\n</Window>\r\n```\r\n\r\n**MainWindow.xaml.cs**\r\n\r\n```\r\nusing System.Windows;\r\n\r\nnamespace TestWpfApplication\r\n{\r\n    /// <summary>\r\n    /// Interaction logic for MainWindow.xaml\r\n    /// </summary>\r\n    public partial class MainWindow : Window\r\n    {\r\n        public MainWindow()\r\n        {\r\n            InitializeComponent();\r\n        }\r\n\r\n        private void Button_Click(object sender, RoutedEventArgs e)\r\n        {\r\n            GreetingsTextBlock.Text = \"Hi \" + FirstNameTextBox.Text + \" \" + LastNameTextBox.Text;\r\n        }\r\n    }\r\n}\r\n```\r\n\r\n**Second project - with tests:**\r\n\r\n**MainWindowUiMap.cs**\r\n\r\n```\r\nusing CUITe.Controls.WpfControls;\r\nusing CUITe.SearchConfigurations;\r\n\r\nnamespace CodedUITestProject1.UiMap\r\n{\r\n    public class MainWindowUiMap\r\n    {\r\n        private readonly WpfWindow _uiUnderTest;\r\n\r\n        public MainWindowUiMap()\r\n        {\r\n            _uiUnderTest = new WpfWindow(By.Name(\"TestWpfApplication\"));\r\n        }\r\n\r\n        public string FirstNameTextBox\r\n        {\r\n            get { return _uiUnderTest.Find<WpfEdit>(By.Name(\"FirstNameTextBox\")).Text; }\r\n            set { _uiUnderTest.Find<WpfEdit>(By.Name(\"FirstNameTextBox\")).Text = value; }\r\n        }\r\n\r\n        public string LastNameTextBox\r\n        {\r\n            get { return _uiUnderTest.Find<WpfEdit>(By.Name(\"LastNameTextBox\")).Text; }\r\n            set { _uiUnderTest.Find<WpfEdit>(By.Name(\"LastNameTextBox\")).Text = value; }\r\n        }\r\n\r\n        public string GreetingsTextBlock\r\n        {\r\n            get { return _uiUnderTest.Find<WpfText>(By.Name(\"GreetingsTextBlock\")).DisplayText; }\r\n        }\r\n\r\n        public void ClickSayHeyButton()\r\n        {\r\n            _uiUnderTest.Find<WpfButton>(By.Name(\"GreetingsButton\")).Click();\r\n        }\r\n    }\r\n}\r\n```\r\n\r\n**TestMainWindowGreetings.cs**\r\n\r\n```\r\nusing System.Threading;\r\nusing CodedUITestProject1.UiMap;\r\nusing Microsoft.VisualStudio.TestTools.UITesting;\r\nusing Microsoft.VisualStudio.TestTools.UnitTesting;\r\n\r\nnamespace CodedUITestProject1.Tests\r\n{\r\n    [CodedUITest]\r\n    public class TestMainWindowGreetings\r\n    {\r\n        [TestMethod]\r\n        public void TestGreetings()\r\n        {\r\n            ApplicationUnderTest.Launch(@\"D:\\Roxton\\Documents\\Visual Studio 2013\\Projects\\TestWpfApplication\\TestWpfApplication\\bin\\Debug\\TestWpfApplication.exe\");\r\n            var uiUnderTest = new MainWindowUiMap();\r\n            Thread.Sleep(1000);\r\n            uiUnderTest.FirstNameTextBox = \"John\";\r\n            uiUnderTest.LastNameTextBox = \"Doe\";\r\n            uiUnderTest.ClickSayHeyButton();\r\n            var greetingsTextBlockValue = uiUnderTest.GreetingsTextBlock;\r\n            Assert.AreEqual(\"Hi John Doe\", greetingsTextBlockValue);\r\n        }\r\n    }\r\n}\r\n```\r\n\r\nDuring the execution of the test in the TestMainWindowGreetings class, I'm getting the following exception:\r\n\r\n> Test Name:\tTestGreetings\r\nTest FullName:\tCodedUITestProject1.Tests.TestMainWindowGreetings.TestGreetings\r\nTest Source:\td:\\Roxton\\Documents\\Visual Studio 2013\\Projects\\TestWpfApplication\\CodedUITestProject1\\Tests\\TestMainWindowGreetings.cs : line 13\r\nTest Outcome:\tFailed\r\nTest Duration:\t0:00:07,5583427\r\n\r\n> Result Message:\t\r\nTest method CodedUITestProject1.Tests.TestMainWindowGreetings.TestGreetings threw exception: \r\nMicrosoft.VisualStudio.TestTools.UITest.Extension.UITestControlNotFoundException: The playback failed to find the control with the given search properties. Additional Details: \r\nTechnologyName:  'UIA'\r\nFrameworkId:  'Wpf'\r\nControlType:  'Edit'\r\nName:  'FirstNameTextBox'\r\n Search may have failed at 'TabGroup|ST:0:0:{34e76e81-ee4a-11d0-ae2e-00a0c90ff...' TabList as it may have virtualized children. If the control being searched is descendant of 'TabGroup|ST:0:0:{34e76e81-ee4a-11d0-ae2e-00a0c90ff...' 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.\r\nResult StackTrace:\t\r\nat Microsoft.VisualStudio.TestTools.UITest.Playback.Engine.IScreenElement.FindAllDescendants(String bstrQueryId, Object& pvarResKeys, Int32 cResKeys, Int32 nMaxDepth)\r\n   at Microsoft.VisualStudio.TestTools.UITest.Playback.ScreenElement.FindAllScreenElement(String queryId, Int32 depth, Boolean singleQueryId, Boolean throwException, Boolean resetSkipStep)\r\n   at Microsoft.VisualStudio.TestTools.UITest.Playback.ScreenElement.FindScreenElement(String queryId, Int32 depth, Boolean resetSkipStep)\r\n   at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.FindFirstDescendant(String queryId, Int32 maxDepth, Int32& timeLeft)\r\n --- End of inner exception stack trace ---\r\n    at Microsoft.VisualStudio.TestTools.UITesting.Playback.MapControlNotFoundException(COMException ex, IPlaybackContext context)\r\n   at Microsoft.VisualStudio.TestTools.UITesting.Playback.MapAndThrowComException(COMException innerException, IPlaybackContext context)\r\n   at Microsoft.VisualStudio.TestTools.UITesting.Playback.MapAndThrowException(Exception exception, IPlaybackContext context)\r\n   at Microsoft.VisualStudio.TestTools.UITesting.Playback.MapAndThrowException(Exception exception, String queryId)\r\n   at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.FindFirstDescendant(String queryId, Int32 maxDepth, Int32& timeLeft)\r\n   at Microsoft.VisualStudio.TestTools.UITesting.SearchHelper.GetElement(Boolean useCache, ISearchArgument searchArg)\r\n   at Microsoft.VisualStudio.TestTools.UITesting.SearchHelper.Search(ISearchArgument searchArg)\r\n   at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.FindInternal()\r\n   at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.FindControlIfNecessary()\r\n   at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.SetPropertyPrivate(String propertyName, Object value)\r\n   at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.<>c__DisplayClass3e.<SetProperty>b__3d()\r\n   at Microsoft.VisualStudio.TestTools.UITesting.CodedUITestMethodInvoker.InvokeMethod[T](Func`1 function, UITestControl control, Boolean firePlaybackErrorEvent, Boolean logAsAction)\r\n   at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.SetProperty(String propertyName, Object value)\r\n   at Microsoft.VisualStudio.TestTools.UITesting.WpfControls.WpfEdit.set_Text(String value)\r\n   at CUITe.Controls.WpfControls.WpfEdit.set_Text(String value)\r\n   at CodedUITestProject1.UiMap.MainWindowUiMap.set_FirstNameTextBox(String value) in d:\\Roxton\\Documents\\Visual Studio 2013\\Projects\\TestWpfApplication\\CodedUITestProject1\\UiMap\\MainWindowUiMap.cs:line 18\r\n   at CodedUITestProject1.Tests.TestMainWindowGreetings.TestGreetings() in d:\\Roxton\\Documents\\Visual Studio 2013\\Projects\\TestWpfApplication\\CodedUITestProject1\\Tests\\TestMainWindowGreetings.cs:line 17\r\n\r\nLooks like MainWindow can be found but I can't find a single control in it."},"comment":{"url":"https://api.github.com/repos/icnocop/cuite/issues/comments/185213302","html_url":"https://github.com/icnocop/cuite/issues/61#issuecomment-185213302","issue_url":"https://api.github.com/repos/icnocop/cuite/issues/61","id":185213302,"user":{"login":"FantasticFiasco","id":8513095,"avatar_url":"https://avatars.githubusercontent.com/u/8513095?v=3","gravatar_id":"","url":"https://api.github.com/users/FantasticFiasco","html_url":"https://github.com/FantasticFiasco","followers_url":"https://api.github.com/users/FantasticFiasco/followers","following_url":"https://api.github.com/users/FantasticFiasco/following{/other_user}","gists_url":"https://api.github.com/users/FantasticFiasco/gists{/gist_id}","starred_url":"https://api.github.com/users/FantasticFiasco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FantasticFiasco/subscriptions","organizations_url":"https://api.github.com/users/FantasticFiasco/orgs","repos_url":"https://api.github.com/users/FantasticFiasco/repos","events_url":"https://api.github.com/users/FantasticFiasco/events{/privacy}","received_events_url":"https://api.github.com/users/FantasticFiasco/received_events","type":"User","site_admin":false},"created_at":"2016-02-17T13:54:44Z","updated_at":"2016-02-17T13:54:44Z","body":"I'm on it, but won't be able to provide you with a complete working solution faster than tonight.\r\n\r\nShort story though, never rely on the ``Name`` property when searching for elements in a WPF windows, instead mark your elements with the attached property ``AutomationProperties.AutomationId`` and search for those instead."}}