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

NullReferenceException

2 Answers 148 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 14 Sep 2016, 01:26 PM

Hi,

I am new to using Telerik Framework. I am trying to write automated tests for a WPF application that we have, but I keep getting a null reference exception when I try and use the code described in this page http://docs.telerik.com/teststudio/testing-framework/write-tests-in-code/silverlight-wpf-automation-wtc/wpf-ui-automation. 

 

This happens in the line that is launching the application 'WpfApplication foo = myManager.LaunchNewApplication(@"C:\Users\e-ddcr\Documents\GAV\2.0\gav-app\PokeMoon\PokeMoon.Startup\bin\Debug\PokeMoon.Startup.exe"); '. Unfortunately the error does not seem to give me very much to go on, and I could not find anything online that helped resolve the issue. 

Below you have the details of the error and my code. Any help would be hugely appreciated.

 

Many thanks,

 

Error:

Test Name: Open_Application
Test FullName: UnitTestProject2.TelerikNUnitTest1.Open_Application
Test Source: C:\Users\e-ddcr\Documents\GAV\2.0\gav-app\PokeMoon\UnitTestProject2\TelerikNUnitTest1.cs : line 37
Test Outcome: Failed
Test Duration: 0:00:10,4944389

Result StackTrace:
at ArtOfTest.Common.Win32.Connector.InjectCode(IntPtr handle, String assemblyAndClass, String pipename, String pid, Boolean waitForDocument, Int32 waitForDocumentTimeout)
   at ArtOfTest.WebAii.Wpf.WpfWindow.ConnectToWindow(IntPtr handle, String pipename, String pid)
   at ArtOfTest.WebAii.Wpf.WpfApplication.get_MainWindow()
   at ArtOfTest.WebAii.Core.Manager.LaunchNewApplication(ProcessStartInfo pinfo)
   at ArtOfTest.WebAii.Core.Manager.LaunchNewApplication(String path, String[] args)
   at UnitTestProject2.TelerikNUnitTest1.Open_Application() in C:\Users\e-ddcr\Documents\GAV\2.0\gav-app\PokeMoon\UnitTestProject2\TelerikNUnitTest1.cs:line 48
Result Message:
Test method UnitTestProject2.TelerikNUnitTest1.Open_Application threw exception: 
System.NullReferenceException: Object reference not set to an instance of an object.

 

Code:

using ArtOfTest.WebAii.Core;
using ArtOfTest.WebAii.TestTemplates;
using ArtOfTest.WebAii.Wpf;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace UnitTestProject2
{
    /// <summary>
    /// Summary description for TelerikNUnitTest1
    /// </summary>
    [TestClass]
    public class TelerikNUnitTest1 : BaseWpfTest
    {

        private TestContext testContextInstance;

        public WpfApplication foo { get; private set; }

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>

        [TestMethod]
        public void Open_Application()
        {
            // Create my own Settings object and then modify the defaults
            Settings mySettings = new Settings();
            mySettings.ClientReadyTimeout = 60000;

            // Use my Settings object to construct my Manager object
            Manager myManager = new Manager(mySettings);

            // Launch the application instance from its location in file system
            WpfApplication foo = myManager.LaunchNewApplication(@"C:\Users\e-ddcr\Documents\GAV\2.0\gav-app\PokeMoon\PokeMoon.Startup\bin\Debug\PokeMoon.Startup.exe"); 

            //// Validate the title of the homepage
            //ArtOfTest.Common.UnitTesting.Assert.IsTrue(foo.MainWindow.Window.Caption.Equals("MainWindow"));
         
            Button np = foo.MainWindow.Find.ByName<Button>("New project...");
            np.User.Click();
        }
        
    }
}

 

2 Answers, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 15 Sep 2016, 09:27 AM
Hi david,

It seems like what you are missing is the starting of the new Manager you have created:
myManager.Start();
 
 // Launch the application instance from its location in file system
WpfApplication foo = myManager.LaunchNewApplication(@"C:\Users\e-ddcr\Documents\GAV\2.0\gav-app\PokeMoon\PokeMoon.Startup\bin\Debug\PokeMoon.Startup.exe");

Hope this would help.

Regards,
Georgi
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
David
Top achievements
Rank 1
answered on 16 Sep 2016, 11:53 AM

Hi Georgi,

That did the job! Thanks for your help.

All the best,

David

Tags
General Discussions
Asked by
David
Top achievements
Rank 1
Answers by
Georgi
Telerik team
David
Top achievements
Rank 1
Share this question
or