UI Test possible within same process as WPF app?

2 posts, 0 answers
  1. Lars
    Lars avatar
    11 posts
    Member since:
    Oct 2015

    Posted 18 Jul 2018 Link to this post


    for some reasons (one of them simpler test construction) I'd like to run the WPF app to be tested within the same process as the test runner, thus being able to access some interfaces in the running app, e.g. setting some properties in the ViewModel.

    I suceeded to some degree by constructing the app instance in the preparation of the test, then running it in a separate thread and then doing a ConnectToApplication(Process.GetCurrentProcess()). Access to the ViewModel also works fine via Dispatcher.Invoke on the app's UI thread.


    01.public void MyTest()
    03.      // run app in-process
    04.      MyApp app;
    05.      var dispatcher = DispatcherFactory.CreateDispatcher("Hugo", ApartmentState.STA);
    06.      dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
    07.      {
    08.        app = new MyApp();
    09.        app.Run();
    10.      }));
    12.      // wait for app window
    13.      var testApp = Manager.Current.ConnectToApplication(Process.GetCurrentProcess());
    14.      var appWnd = testApp.WaitForWindow("MyApp");
    16.      // access some app API
    17.      dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { SingletonInApp.Foo(); }));
    19.      // stimulate some UI action
    20.      var theButton = appWnd.Find.ByAutomationId<Button>("a_idTheButton"); // <=== THIS FAILS
    21.      theButton.User.Click();
    23.      // ...


    However, as soon as I subsequently use any method to find an UI element, it fails with the error shown below.
    Is there any reason why the above construction would not work in general? How can I overcome that error?


    System.ApplicationException : Exception thrown during the wait for a condition.
    Error: Unexpected error while waiting on condition.
    Error: ArtOfTest.WebAii.Silverlight.ExecuteSilverlightCommandException:
    [WPF Extension Error] Details: System.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
       bei Telerik.TestingFramework.XamlExtension.ClientServices.SerializeNode(DependencyObject root, StringBuilder sb, List`1 popups)
       bei Telerik.TestingFramework.XamlExtension.ClientServices.SerializeAllVisualTrees()
       bei Telerik.TestingFramework.XamlExtension.ClientProcessor.ProcessCommand(String command)
       bei ArtOfTest.WebAii.Wpf.WpfProxy.ExecuteSLCommand(SilverlightCommand cmd)
       bei ArtOfTest.WebAii.Wpf.WpfProxy.GetAllVisualTrees()
       bei ArtOfTest.WebAii.Wpf.WpfWindow.RefreshVisualTrees()
       bei ArtOfTest.WebAii.Silverlight.VisualFind.RefreshRoot()
       bei ArtOfTest.WebAii.Silverlight.VisualWait.WaitForExistsByFindInfo(VisualFindInfo findInfo)
       bei ArtOfTest.Common.WaitAsync._worker_DoWork[T,V](Object waitParam)
    Stack Trace:
         bei ArtOfTest.Common.WaitSync.CheckResult(WaitSync wait, String extraExceptionInfo, Object target)
         bei ArtOfTest.Common.WaitSync.For[T](Predicate`1 predicate, T target, Boolean invertCondition, Int32 timeout, WaitResultType errorResultType)
         bei ArtOfTest.WebAii.Silverlight.VisualWait.ForExistsInternal(Int32 timeout, Boolean invertCondition)
         bei ArtOfTest.WebAii.Silverlight.VisualWait.ForVisible(Int32 timeout)
         bei ArtOfTest.WebAii.Silverlight.VisualFind.ReturnOrThrow(FrameworkElement e, String throwMessage)
         bei ArtOfTest.WebAii.Silverlight.VisualFind.ByAutomationId(String id, String xamlTag)
         bei ArtOfTest.WebAii.Silverlight.VisualFind.ByAutomationId[T](String id)


  2. Elena
    Elena avatar
    1159 posts

    Posted 23 Jul 2018 Link to this post

    Hello Lars,

    Thank you for the shared details. 

    What you are trying to accomplish will not be possible. As you have tried already the application under test will start and you will be able to access the ViewModel to change its properties. Though the specifics of how the Testing Framework communicates with the WPF extension will prevent all of these to run in the same process. 

    I hope this will be helpful to you. However, in case of further questions, please let me know! 

    Elena Tsvetkova
    Progress Telerik
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
Back to Top