Search code examples
c#.netautomated-testscoded-ui-tests

Coded UI Application Under Test


Just started implementing a coded ui test automation solution but keep running into an issue when starting the application.

The application seems to start just fine but no matter what I always get an exception stating:

Microsoft.VisualStudio.TestTools.UITest.Extension.FailedToLaunchApplicationException: "The application cannot be started. This could be due to one of the following reasons: 1) Another instance of the application is already running and only one instance can be running at a time. 2) The application started another process and has now stopped. You may need to launch the process directly. 3) You do not have sufficient privileges for this application."

The application is a little strange as it currently is setup to run off of a setup.exe so the user always has the latest version.

Am I missing something in my code (sample below)? Or does the application need to be better set up before I start writing the automation tests. EXE is located in a network location.

ApplicationUnderTest aut = ApplicationUnderTest.Launch(@"\\test.com\\applicationdir\\testenv\\application\\setup.exe");

WpfEdit userName = new WpfEdit(aut);
userName.SearchProperties.Add(WpfEdit.PropertyNames.AutomationId, "PART_UserName");

userName.Text = "TEST";

Solution

  • Currently using a workaround where I start the app via Process and then pass it to the application under test FromProcess(). Seemed to fix the issue.

    Probably not the best solution and have to use a Thread.Sleep() but it works for now.

    Example:

    var process = Process.Start(@"pathToApplication");

    Thread.Sleep(2000);

    process = Process.GetProcessesByName("process.Name")[0];

    ApplicationUnderTest aut = ApplicationUnderTest.FromProcess(process);