NRE on getting the main window

2 posts, 0 answers
  1. Al
    Al avatar
    3 posts
    Member since:
    Aug 2007

    Posted 16 Nov 2013 Link to this post

    I was just about to test drive this, on the first attempt I was trying to run the app, get the main window, but stopped right there. Here's the exception I got on accessing MainWindow:

       at ArtOfTest.Common.Win32.Connector.InjectCode(IntPtr handle, String assemblyAndClass, String pipename, String pid, Boolean waitForDocument)
       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 NServiceBus.Profiler.FunctionalTests.StudioTestBase.Can_show_shell_window() in c:\Projects\NSBProfiler\NServiceBus.Profiler.FunctionalTests\StudioTestBase.cs:line 31

    And what I did was pretty standard:

    public void Can_show_shell_window()
        var appPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), ApplicationProcess);
        var processStartInfo = new ProcessStartInfo
            FileName = appPath,
            UseShellExecute = false,
            CreateNoWindow = true,
            RedirectStandardOutput = true,
            RedirectStandardError = true,
        var config = new Settings();
        var manager = new Manager(config);
        var app = manager.LaunchNewApplication(processStartInfo);
        var mainWindow = app.MainWindow;
        var barManager = mainWindow.Find.ByAutomationId("BarManager");

    The app displays a splash screen on startup, maybe that's why getting the main window fails? Whatever the reason, I didn't expect a NRE.

  2. Velin Koychev
    Velin Koychev avatar
    88 posts

    Posted 20 Nov 2013 Link to this post

    Hi Al,

    One thing that I see that you miss is to start the manager  right before you launch the application. You just need to insert the following line of code:
    right before this line of code: var app = manager.LaunchNewApplication(processStartInfo);

    I hope this helps.

    Velin Koychev
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
Back to Top