Automate "ClickOnce" WPF Application


To automate a WPF application it is necessary to configure the path to the executable file of the app. It is a problem when there is a WPF ClickOnce application. Then each new version of the app is installed in a different location. Here is a possible approach to the problem where a mixed test list containing a Web and WPF test is used.


It is necessary to create a stand alone class file (Utility) which static property (pathFile) will be used to store the path to the latest app version:

public class Utility
    public static string pathFile = string.Empty;
Public Class Utility

    Public Shared pathFile As String = String.Empty

End Class

The following scenario assumes that the app is downloaded form a web destination, installed and ran from a browser. In such case the first test in the list will be a Web test that will complete the app installation part. At the end of the installation the latest app version will be up and running. This test have to end with a coded step that will save in a variable path to the new application as given bellow:

// check if there is running process with same name
var runningApp = System.Diagnostics.Process.GetProcesses().Where(p => p.ProcessName == "YourClickOnceWpfApp");

// get the process
var proc = runningApp.FirstOrDefault();

// log the name of the process to the Execution Log

// save the full path to a common variable
Utility.pathFile = proc.MainModule.FileName.ToString();

Dim runningApp = System.Diagnostics.Process.GetProcesses().Where(Function(p) p.ProcessName = "YourClickOnceWpfApp")

Dim proc = runningApp.FirstOrDefault()


Utility.pathFile = proc.MainModule.FileName.ToString()

Next step is to create a WPF test that begins with a coded step and is configured to run a dummy WPF app. In the coded step the initially started mock app will be closed. Then depending on the latest version state (running/stoped) Test Studio will connect to or open it for next test steps execution:

// Shut down "mock" app

// check if there is running process with same name
var runningApp = System.Diagnostics.Process.GetProcesses().Where(p => p.ProcessName == "YourClickOnceWpfApp");

// if there is same app running - connect to it
if (runningApp.Count() != 0)
    // or - launch new application


Dim runningApp = System.Diagnostics.Process.GetProcesses().Where(Function(p) p.ProcessName = "YourClickOnceWpfApp")

If runningApp.Count() <> 0 Then




End If

The project view is given on the next screenshot for a reference:


Is this article helpful? Yes / No
Thank you for your feedback!

Give article feedback

Tell us how we can improve this article