This is a migrated thread and some comments may be shown as answers.

[WPF Extension Error] appears during attempt to work with WPF-application

2 Answers 159 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Anton
Top achievements
Rank 1
Anton asked on 10 May 2012, 12:00 PM
Hi.

Last 1.5 years I work using Free Test Framework - it is awesome! Thanks.
But I used only possibilities to test Web and Silverlight apps, today I've tried to write simple test for WPF application and I have some problems. Tell me please - how to solve them? Where is my bug? Application (Visio) was launched OK, but I can't find any controls inside of it because exception displayed. Why Silverlight is mentioned there? Actually Silverlight is set to false. I use BaseWpfTest here, also I've tried BaseTest, tried to connect to process etc. - results are same.

Code (part of standard NUnit test):

// An Example TestMethod:
[Test]
public void SampleWebAiiTest()
{
           // Launch the application instance
            var wpfApp = Manager.LaunchNewApplication(@"C:\Program Files (x86)\Microsoft Office\Office14\VISIO.EXE");
            var somebutton = wpfApp.MainWindow.Find.ByName<Button>("OpenButton");
}

Problem during execute:
{"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: Object reference not set to an instance of an object.\r\n   at Telerik.TestingFramework.XamlExtension.ClientServices.SerializeNode(DependencyObject root, StringBuilder sb, List`1 popups)\r\n   at Telerik.TestingFramework.XamlExtension.ClientServices.SerializeAllVisualTrees()\r\n   at Telerik.TestingFramework.XamlExtension.ClientProcessor.ProcessCommand(String command)\r\n   at ArtOfTest.WebAii.Wpf.WpfProxy.ExecuteSLCommand(SilverlightCommand cmd)\r\n   at ArtOfTest.WebAii.Wpf.WpfProxy.GetAllVisualTrees()\r\n   at ArtOfTest.WebAii.Wpf.WpfWindow.RefreshVisualTrees()\r\n   at ArtOfTest.WebAii.Silverlight.VisualFind.RefreshRoot()\r\n   at ArtOfTest.WebAii.Silverlight.VisualWait.WaitForExistsByFindInfo(VisualFindInfo findInfo)\r\n   at ArtOfTest.Common.WaitAsync._worker_DoWork[T,V](Object waitParam)"}

2 Answers, 1 is accepted

Sort by
0
Anthony
Telerik team
answered on 14 May 2012, 09:37 PM
Hello Anton,

I don't believe Microsoft Visio is a WPF application. If you download a trial of Test Studio, you'll be able to use its interface to determine whether you're testing a valid WPF app.

Once you target a valid WPF app, you can use sample code as seen below. The following is a basic NUnit test written with the Framework:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
using ArtOfTest.WebAii.Controls.HtmlControls;
using ArtOfTest.WebAii.Controls.HtmlControls.HtmlAsserts;
using ArtOfTest.WebAii.Core;
using ArtOfTest.WebAii.ObjectModel;
using ArtOfTest.WebAii.TestAttributes;
using ArtOfTest.WebAii.TestTemplates;
using ArtOfTest.WebAii.Win32.Dialogs;
 
using ArtOfTest.WebAii.Silverlight;
using ArtOfTest.WebAii.Controls.Xaml.Wpf;
using ArtOfTest.WebAii.Wpf;
 
using NUnit.Framework;
using Core = NUnit.Core;
using Telerik.WebAii.Controls.Xaml.Wpf;
 
namespace TestStudioProject2
{
    [TestFixture]
    public class HelloWorldUnitTest1 : BaseWpfTest
    {
        #region [Setup / TearDown]
 
        [SetUp]
        public void MyTestInitialize()
        {
            #region WebAii Initialization
 
            Initialize(new TestContextWriteLine(Console.Out.WriteLine));
 
            #endregion
        }
 
        [TearDown]
        public void MyTestCleanUp()
        {
            #region WebAii CleanUp
 
            this.CleanUp();
 
            #endregion
        }
 
        [TestFixtureTearDown]
        public void FixtureCleanup()
        {
            ShutDown();
        }
 
        #endregion
 
        [Test()]
        public void HelloWorld()
        {
            WpfApplication app = Manager.LaunchNewApplication("C:\\AppFolder\\WPFHelloWorld.exe");
 
            TextBox tb = app.MainWindow.Find.ByName<TextBox>("txtName");
            tb.SetText(true, "TELERIK", 10, 100, false);
 
            Button b = app.MainWindow.Find.ByName<Button>("btnClick");
            b.User.Click();
 
            System.Threading.Thread.Sleep(1000);
        }
    }
}


Greetings,
Anthony
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Anton
Top achievements
Rank 1
answered on 14 May 2012, 09:47 PM
Thanks, Anthony. It seems that you are right ;)
Anyway I can automate Visio even if it is not WPF application using Windows Manager - this way isn't easy but I can at least try to do this :)
(I like this framework and I hope that [may be] in future it will be possible to easily automate apps like Visio too)
Tags
General Discussions
Asked by
Anton
Top achievements
Rank 1
Answers by
Anthony
Telerik team
Anton
Top achievements
Rank 1
Share this question
or