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

NRE on getting the main window

1 Answer 57 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Al
Top achievements
Rank 1
Al asked on 16 Nov 2013, 09:08 AM
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:

[Test]
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");
    Assert.IsNotNull(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.

1 Answer, 1 is accepted

Sort by
0
Velin Koychev
Telerik team
answered on 20 Nov 2013, 01:46 PM
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:
manager.Start();
right before this line of code: var app = manager.LaunchNewApplication(processStartInfo);

I hope this helps.

Regards,
Velin Koychev
Telerik
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Tags
General Discussions
Asked by
Al
Top achievements
Rank 1
Answers by
Velin Koychev
Telerik team
Share this question
or