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

Code: Open WPF application, connect to manager, wait for close

6 Answers 110 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 2
Daniel asked on 06 Sep 2013, 05:35 PM
I apologize, I'm sure this has been asked and I promise you I spent the better part of the morning searching for an answer.

I'm using a combination of Test Studio standalone and Visual Studio for the code behind.

Scenario:

Have a series of Web Test's (recorded steps and scripted steps (Utility Class)) that go out and collect baselines based off tables on a website and export them to CSV files in the Data directory of the project.

Have another series of Web Test's that are simply scripted steps that compare the baseline to another generated file. 

I've written a small WPF application that enumerates the directory containing the CSV files and simply asks the user which one they would like to compare to the baseline with.

I am able to open the WPF application using the Manager.LaunchNewApplication along with a bunch of other settings.  I can make assertions based on the contents of the WPF app, however the manager does not wait for the application to close and test continues through steps.

Is there a way that I am missing that would allow the Manager to wait for the WPF application to close?  I am sure it is simple (I am newer to programming versus system admin scripting), I am just missing it.  Using the latest public build of Test Studio.

Below is a super stripped down version of what I am trying to accomplish.

public static class PCCSR
{          
    public static string root = ExecutionContext.Current.DeploymentDirectory + @"\Data\";
     
    public static void NSRtestWPF()
    {
        Manager.Current.LaunchNewApplication(root + @"PCCNSR.exe", "Admin");
        ListBox b = Manager.Current.ActiveApplication.MainWindow.Find.ByName<ListBox>("lstbxFiles");
        Assert.IsTrue(b.Items.Contains("Baseline_Security_Roles_Admin.csv"), "File not found");
    }
}

I have looked at http://www.telerik.com/automated-testing-tools/support/documentation/user-guide/code-samples/wpf/connect-to-running-wpf-app.aspx along with searching the forums.

6 Answers, 1 is accepted

Sort by
0
Daniel
Top achievements
Rank 2
answered on 06 Sep 2013, 06:02 PM
I believe I resolved this myself using a different method.

I'm now opening the WPF app using System.Diagnostics.Process, connecting to it using Manager.ConnectToApplication, and then just doing a WaitForExit() while hopefully (don't have this part done yet) collecting the information I need.

Not perfect, but working for now.
0
Daniel
Top achievements
Rank 2
answered on 06 Sep 2013, 06:40 PM

I would delete this thread if I saw how, but instead I'll just keep updating it.

System.Diagnostics.Process did not work out.

The following is working to launch the WPF app and return values from it without incident.

WpfApplication app = Manager.Current.LaunchNewApplication(root + @"PCCNSR.exe", "Admin");
Manager.Current.ActiveApplication.MainWindow.RefreshVisualTrees();
  
ListBox b = Manager.Current.ActiveApplication.MainWindow.Find.ByName<ListBox>("lstbxFiles");
Assert.IsTrue(b.Items.Contains("Baseline_Security_Roles_Admin.csv"), "File not found");
return b.Items.Count.ToString();

WfpApplication gave me the HasExited() option, which should help this along now.
0
Cody
Telerik team
answered on 06 Sep 2013, 08:06 PM
Hello Daniel,

Let me start with a little bit of design architecture details. When you launch a WPF application using LaunchNewApplication, Test Studio assumes that application is going to stay running until you explicitly call Close() on that application.

With this in mind I am now a little confused by your statement "the manager does not wait for the application to close and test continues through steps". Yes this is our expected behavior. Why would you expect the manager to wait for it to be closed... and what technical problem does this actually present i.e. how does this behavior present a problem to you?

What about calling ActivateApplication.Close() after your Assert.IsTrue?

Regards,
Cody
Telerik
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Daniel
Top achievements
Rank 2
answered on 06 Sep 2013, 08:17 PM
I'm all over the place, I apologize.

I'm running out of time for today, so I'll circle back Monday with more details.

Basically I have a Web Test.  First step of that Web Test is scripted, and is opening a WPF application with a listbox that contains a list of CSV's in a specific directory (filtered by WPF launch arguments).

Based on the selected item that user picks (not automated) and then is (hopefully) returned to my coded step, other test/steps will be run on that extracted information.

All other steps are automated, just this one input is not.

I've looked at creating a custom windows form, and assumed that the WPF application would be easiest to interact with.

If I didn't require the option to select the file that the user needs to use, this wouldn't be so complicated.
0
Accepted
Cody
Telerik team
answered on 10 Sep 2013, 10:46 PM
Hello Daniel,

Ah OK, that paints a much clearer picture. You want the WPF application launched, have Test Studio wait for it to run (so user can manually interact with the WPF app) and exit before proceeding to the step. Do I have that sequence correct?

I would get the process and wait for the process to exit via code like this shown here:
http://stackoverflow.com/questions/3147911/wait-till-a-process-ends
The difference is that instead of launching the process as shown in the code, you'll get the process id:
http://www.dotnetfunda.com/forums/thread3330-find-process-id-of-my-application.aspx
Then just wait for it to exit. Then the rest of the test steps will take over the way you want.

Regards,
Cody
Telerik
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Daniel
Top achievements
Rank 2
answered on 12 Sep 2013, 12:03 PM
Thank you for the idea.  I gave up on this implementation earlier in the week due.  I've since changed to another idea and that will work for now.

If I decide to come back to this, I'll try that implementation.

Thanks,

Dan
Tags
General Discussions
Asked by
Daniel
Top achievements
Rank 2
Answers by
Daniel
Top achievements
Rank 2
Cody
Telerik team
Share this question
or