Testing ClickOnce Applications - Overview

Applies to TestComplete 14.72, last modified on April 22, 2021

ClickOnce is a .NET technology that allows users to install and run various applications (typically, .NET, WPF or CEF) by clicking a link on a web page. TestComplete supports testing of applications deployed via ClickOnce and provides built-in operations that let you launch ClickOnce applications from tests.

About ClickOnce Applications

ClickOnce applications differ from usual desktop applications in the way applications are installed and launched. Unlike usual applications installed to the Program Files folder or a user-defined folder, ClickOnce applications are installed into the user profile, to a subfolder with an obfuscated name. As a result, it is difficult to know the exact application location on the disk and launch the application’s executable file directly.

From the user’s point of view, ClickOnce applications can be launched in two ways:

  • From a web page on the Internet, intranet or local computer. The web page includes a link to the application deployment manifest (.application), a click on which installs and launches the application on the user’s computer.

  • Using Start Menu or desktop shortcuts (provided so that the application installed them). Note that unlike usual shortcuts (.lnk), a ClickOnce application shortcut (.appref-ms) points to the application deployment manifest rather than the location of the .exe file on the disk. So, it effectively works as if the user launched the application via its manifest.

TestComplete supports and lets you automate both ways of launching ClickOnce applications.

Creating and Recording Tests for ClickOnce Applications

Testing of ClickOnce applications is similar to testing generic .NET and WPF applications. The only difference is the way of launching the tested application.

The general procedure is as follows:

For further information about creating tests for .NET and WPF applications, refer to the following sections:

Testing .NET Applications

Testing WPF Applications

Running ClickOnce Applications From Tests

TestComplete includes built-in operations that let you launch ClickOnce applications from your tests. The application should be added to the Tested Applications collection beforehand. (See Adding ClickOnce Applications to Tested Applications.)

To launch a ClickOnce application from a keyword test, use the Run TestedApp command and select the needed application in the operation parameters.

To launch a ClickOnce application from scripts, use the TestedApps.AppName.Run method, where AppName is the application's name in the Tested Applications collection:

JavaScript, JScript

TestedApps.MyApp.Run();

Python

TestedApps.MyApp.Run();

VBScript

TestedApps.MyApp.Run

DelphiScript

TestedApps.MyApp.Run;

C++Script, C#Script

TestedApps["MyApp"]["Run"]();

Automating the Application Installation Procedure

The installation procedure of a ClickOnce application typically presents a user with a simple dialog box prompting to confirm the installation. Then, the installation proceeds without further user intervention.

The TestComplete Run TestedApp keyword test operation and the TestedApps.AppName.Run scripting method are supposed only to be used for launching ClickOnce applications that are already installed on the computer. They cannot be used to install and launch a new ClickOnce application. That is why the mentioned operations do not return the control to the test until the application is launched, but the installation procedure requires user intervention to continue and launch the application.

To create a test that installs a ClickOnce application, simply record launching the application deployment manifest and interacting with the installation dialog. Then, you can enhance the recorded test by inserting delays to synchronize the test with the installation process to complete. The resulting test would look similar to this:

JavaScript, JScript

function Test()
{
  // The URL of the application's publish page
  var url = "http://server/myapp/publish.htm";

  // Open the application's publish page in a web browser
  Browsers.Item(btIExplorer).Run(url);

  // Install the application and wait until the installation is complete
  Sys.Browser().Page(url).FindChildByXPath("//A[@id='InstallButton']").Click();
  Sys.Process("dfsvc").WinFormsObject("TrustManagerPromptUI").WinFormsObject("tableLayoutPanelOuter").WinFormsObject("tableLayoutPanelButtons").WinFormsObject("btnInstall").ClickButton();
  while (Sys.Process("dfsvc").WaitWinFormsObject("UserInterfaceForm", 1000).Exists)
    aqUtils.Delay(5000);

  // Automate the launched application
  var p = Sys.WaitProcess("MyApp", 60000);
  ...
}

Python

def Test():
  # The URL of the application's publish page
  url = "http://server/myapp/publish.htm";

  # Open the application's publish page in a web browser
  Browsers.Item[btIExplorer].Run(url);

  # Install the application and wait until the installation is complete
  Sys.Browser().Page(url).FindChildByXPath("//A[@id='InstallButton']").Click();
  Sys.Process("dfsvc").WinFormsObject("TrustManagerPromptUI").WinFormsObject("tableLayoutPanelOuter").WinFormsObject("tableLayoutPanelButtons").WinFormsObject("btnInstall").ClickButton();
  while (Sys.Process("dfsvc").WaitWinFormsObject("UserInterfaceForm", 1000).Exists):
    aqUtils.Delay(5000);

  # Automate the launched application
  p = Sys.WaitProcess("MyApp", 60000);
  # ...

VBScript

Sub Test
  Dim url, p
  ' The URL of the application's publish page
  url = "http://server/myapp/publish.htm"

  ' Open the application's publish page in a web browser
  Browsers.Item(btIExplorer).Run url

  ' Install the application and wait until the installation is complete
  Sys.Browser().Page(url).FindChildByXPath("//A[@id='InstallButton']").Click
  Sys.Process("dfsvc").WinFormsObject("TrustManagerPromptUI").WinFormsObject("tableLayoutPanelOuter").WinFormsObject("tableLayoutPanelButtons").WinFormsObject("btnInstall").ClickButton
  Do While Sys.Process("dfsvc").WaitWinFormsObject("UserInterfaceForm", 1000).Exists
    aqUtils.Delay 1000
  Loop

  ' Automate the launched application
  Set p = Sys.WaitProcess("MyApp", 60000)
  ...
End Sub

DelphiScript

procedure Test;
var url, p;
begin
  // The URL of the application's publish page
  url := 'http://server/myapp/publish.htm';

  // Open the application's publish page in a web browser
  Browsers.Item(btIExplorer).Run(url);

  // Install the application and wait until the installation is complete
  //Sys.Browser.Page(url).NativeWebObject.Find('ObjectIdentifier', 'InstallButton', 'A').Click;
  Sys.Browser.Page(url).FindChildByXPath('//A[@id="InstallButton"]').Click;

  Sys.Process('dfsvc').WinFormsObject('TrustManagerPromptUI').WinFormsObject('tableLayoutPanelOuter').WinFormsObject('tableLayoutPanelButtons').WinFormsObject('btnInstall').ClickButton;
  while Sys.Process('dfsvc').WaitWinFormsObject('UserInterfaceForm', 1000).Exists do
    aqUtils.Delay(1000);

  // Automate the launched application
  p := Sys.WaitProcess('MyApp', 60000);
  ...
end;

C++Script, C#Script

function Test()
{
  // The URL of the application's publish page
  var url = "http://server/myapp/publish.htm";

  // Open the application's publish page in a web browser
  Browsers["Item"](btIExplorer)["Run"](url);

  // Install the application and wait until the installation is complete
  Sys["Browser"]()["Page"](url)["FindChildByXPath"]("//A[@id='InstallButton']")["Click"]();
  Sys["Process"]("dfsvc")["WinFormsObject"]("TrustManagerPromptUI")["WinFormsObject"]("tableLayoutPanelOuter")["WinFormsObject"]("tableLayoutPanelButtons")["WinFormsObject"]("btnInstall")["ClickButton"]();
  while (Sys["Process"]("dfsvc")["WaitWinFormsObject"]("UserInterfaceForm", 1000)["Exists"])
    aqUtils["Delay"](5000);

  // Automate the launched application
  var p = Sys["WaitProcess"]("MyApp", 60000);
  ...
}

Knowing the Location of the Application's Deployment Manifest

You need to know the location of the ClickOnce application's deployment manifest (.application) or shortcut (.appref-ms) to be able to run this application from your test. If you installed the tested ClickOnce application from a web page and do not know the location of its manifest file, you can use one of the following approaches to learn it:

  • Ask the application developers.

  • Launch the application and examine the Sys.Process(AppName).AppDomain("DefaultDomain").ApplicationIdentity.CodeBase property value in the Object Browser.

  • Open the application’s publish page in Internet Explorer, right-click the Install link and select the Copy shortcut button from the context menu.

    Obtain the application’s location from the publish page

    Click the image to enlarge it.

    Note: If the application is not installed on the computer, the Install link may point to the installation program (for example, setup.exe) rather than to the application's deployment manifest. In this case, use another approach to learn the manifest location.
  • If the application has a Start menu or a desktop shortcut, open the shortcut file (.appref-ms) in a text editor. The file contents, where the manifest URL is specified at the beginning of the file, look as follows:

    http://www.example.com/myapp/MyApp.application, Culture=neutral, PublicKeyToken=abcdef1234567890, processorArchitecture=x86

See Also

Supported Development Tools
Adding ClickOnce Applications to Tested Applications
About Tested Applications

Highlight search results