Information in this topic applies to desktop and web applications. |
With TestComplete, you can test applications running under a different user account. For example, you can check how your application works in an environment with limited access to the file system and registry.
To run your application under a different account, first, you need to add it to the TestedApps collection. Then you can use one of the following approaches:
-
Configure the RunAs run mode for your application in the TestedApps editor.
-
Use the
TestedApps.AppName.RunAs
scripting method.
You can also combine the RunAs and Debug modes to trace exceptions in your application while it is running under another account.
The script examples provided in this topic contain the password of the user account under which the tested application runs as plain text. However, a password is a sensitive piece of information. For information on how to store sensitive data used in tests, see Working With Passwords and Other Sensitive Data. |
Requirements and Notes
-
The user account used to run your application must have a non-empty password.
-
The Secondary Logon service must be running in Windows.
-
You must run TestComplete as an administrator.
-
To test Open Applications under another account, the TestComplete user account must have Default Access Permissions on the computer. For more information, see Settings for Testing Open Applications in RunAs Mode.
-
The tested application must be launched from TestComplete (see Running Tested Applications). If you run your application from Windows Explorer or by using the
runas
command, testing may be slow.
Using the RunAs Run Mode
You can configure the RunAs mode for your application in the TestedApps editor. To do this:
-
Select your application in the TestedApps editor. You will see the application parameters in the right side of the editor.
-
From the Run Mode combo box, select RunAs.
-
Specify the Domain, User name, Password and, optionally, other parameters. For a description of the available parameters, see:
From now on, every time you run your application from tests or from the TestComplete IDE, TestComplete will launch under the specified user account.
You can also specify the needed user account in your tests using the TestedApps.AppName.Params.RunAsParams
object. You can use this approach if you want to run your test using several accounts in a loop, or if you read the password from an external source.
JavaScript, JScript
function RunAsMode()
{
var params = TestedApps.MyApp.Params.RunAsParams;
params.Activate();
params.Domain = "DOMAIN";
params.UserName = "user";
params.Password = "password";
TestedApps.MyApp.Run();
}
Python
def RunAsMode():
params = TestedApps.MyApp.Params.RunAsParams
params.Activate()
params.Domain = "DOMAIN"
params.UserName = "user"
params.Password = "password"
TestedApps.MyApp.Run()
VBScript
Sub RunAsMode
Dim params
Set params = TestedApps.MyApp.Params.RunAsParams
params.Activate
params.Domain = "DOMAIN"
params.UserName = "user"
params.Password = "password"
TestedApps.MyApp.Run
End Sub
DelphiScript
procedure RunAsMode;
var params;
begin
params := TestedApps.MyApp.Params.RunAsParams;
params.Activate;
params.Domain := 'DOMAIN';
params.UserName := 'user';
params.Password := 'password';
TestedApps.MyApp.Run;
end;
C++Script, C#Script
function RunAsMode()
{
var params = TestedApps["MyApp"]["Params"]["RunAsParams"];
params["Activate"]();
params["Domain"] = "DOMAIN";
params["UserName"] = "user";
params["Password"] = "password";
TestedApps["MyApp"]["Run"]();
}
Using the TestedApp.RunAs Method
As an alternative to the RunAs run mode, you can use the TestedApps.AppName.RunAs
method to run your application under another account. In keyword tests, you can call this method using the Call Object Method or Run Code Snippet operation.
The RunAs
method ignores the application’s run mode selected in the TestedApps editor. So, it lets you use the RunAs mode without changing the application’s original run mode.
JavaScript, JScript
TestedApps.MyApp.RunAs("DOMAIN", "user", "password");
Python
TestedApps.MyApp.RunAs("DOMAIN", "user", "password")
VBScript
Call TestedApps.MyApp.RunAs("DOMAIN", "user", "password")
DelphiScript
TestedApps.MyApp.RunAs('DOMAIN', 'user', 'password');
C++Script, C#Script
TestedApps["MyApp"]["RunAs"]("DOMAIN", "user", "password");
Using the RunAs and Debug Modes Together
You can combine the RunAs and Debug modes to trace exceptions, debug strings and other events in your application while it is running under another account. To do this:
-
Select and configure the RunAs mode for your application in the TestedApps editor (see above).
-
Run the application from tests using the
DbgServices.LaunchTestedApplication
method instead of the Run TestedApp operation or theTestedApps.AppName.Run
scripting method.JavaScript, JScript
function Test()
{
var appIndex = TestedApps.Find("MyApp");
DbgServices.LaunchTestedApplication(appIndex);
// Perform testing
// ...
}Python
def Test(): appIndex = TestedApps.Find("MyApp") DbgServices.LaunchTestedApplication(appIndex); # Perform testing # ...
VBScript
Sub Test
Dim appIndex
appIndex = TestedApps.Find("MyApp")
Call DbgServices.LaunchTestedApplication(appIndex)
' Perform testing
' ...
End SubDelphiScript
procedure Test;
var appIndex;
begin
appIndex := TestedApps.Find('MyApp');
DbgServices.LaunchTestedApplication(appIndex);
// Perform testing
// ...
end;C++Script, C#Script
function Test()
{
var appIndex = TestedApps["Find"]("MyApp");
DbgServices["LaunchTestedApplication"](appIndex);
// Perform testing
// ...
}
See Also
About Tested Applications
RunAs Mode Parameters
Working With TestComplete Under a User Accounts
Tracing Events and Exceptions With Debug Services