RunAs Method

Applies to TestComplete 15.63, last modified on April 10, 2024

Description

Use this method to launch one or several instances of a tested application under a specific user account (see Testing Applications Running Under Another User Account). Use the TestedApp.Run method to run the application under the same user account as TestComplete.

To close an application under test, you can use the TestedApp.Close or TestedApp.Terminate methods. To close any process in the system, call Process.Close or Process.Terminate.

Declaration

TestedAppObj.RunAs(Domain, UserName, Password, WorkFolder, Parameters, Count, IgnoreRunning, Timeout)

TestedAppObj An expression, variable or parameter that specifies a reference to a TestedApp object
Domain [in]    Required    String    
UserName [in]    Required    String    
Password [in]    Required    String    
WorkFolder [in]    Optional    String Default value: Empty string   
Parameters [in]    Optional    String Default value: Empty string   
Count [in]    Optional    Integer Default value: -1   
IgnoreRunning [in]    Optional    Boolean Default value: False   
Timeout [in]    Optional    Integer Default value: -1   
Result A Process object

Applies To

The method is applied to the following object:

Parameters

The method has the following parameters:

Domain

Specifies the domain to which the user belongs.

UserName

Specifies the user name under whose account the tested application will be launched.

Note: Specify an account that has a password. TestComplete will not launch the tested application under an account that does not have a password.

Password

Specifies the user’s password.

WorkFolder

Specifies the working folder for the tested application, that is the folder that is created for the application after it has been launched.

Parameters

Specifies command-line arguments for the application.

Count

Specifies the number of application instances to be run. If Count is less than 0, the method will run as many instances as the TestedApp.Count property specifies. If Count is 0, no instances will be run. By default, the Count value is -1.

Note: The number of instances to be launched depends on the IgnoreRunning parameter. If this parameter is True, the RunAs method launches as many application instances as the Count parameter specifies.

If the IgnoreRunning parameter is False (default), the total number of running instances cannot exceed the value specified by the Count parameter. Suppose, the Count parameter holds seven, meaning that TestComplete can run a maximum of seven instances of your tested application. Suppose also, that five instances are already running. In this scenario, the RunAs method will only run 2 new instances of the tested application (2 + 5 = 7).

IgnoreRunning

The method can start several instances of the tested application (see note in the Count parameter description). The IgnoreRunning parameter specifies whether the method will ignore or take into account the number of running instances when launching the tested application.

Timeout

Specifies the number of milliseconds the method will wait until the specified number of application instances have started. If Timeout is -1 the waiting time is unlimited.

Result Value

The Process object that corresponds to the last launched application instance.

Remarks

  • Using the RunAs method requires that the Secondary Logon service be running in Windows.

  • In order for TestComplete to be able to test the application that is launched with the RunAs method, it is recommended that TestComplete is running under the administrator account. If TestComplete is running under a user account, it may not have enough permissions to retrieve information about the tested application’s windows and objects.

    In addition, in order for TestComplete to be able to work with Open Applications running under another user account, you need to set the Default Access Permissions for the account used by TestComplete. For more information, see Settings for Testing Open Applications in RunAs Mode.

  • In order to launch a tested application in RunAs mode, TestComplete must be running with administrator permissions (see Using TestComplete With Administrator Privileges).

  • The application is not launched if the Launch property of TestedAppObj is False.

Sometimes the TestedApp.RunAs method hangs the application. To call the application process, this method uses the WaitForInputIdle method, which is part of the Win32 API. When WaitForInputIdle hangs, TestComplete hangs as well. To avoid this behavior, use the following workaround: create a batch file (.bat) that will call your application and add this file to the list of tested applications instead of the application.

Example

The following example tries to launch the first application in the list of tested applications under the TESTCOMP\tester account with the psswrd password. It then uses the Exists property of the returned object to check if the application process was launched successfully.

JavaScript, JScript

var p = TestedApps.Items(0).RunAs("TESTCOMP", "tester", "psswrd");
if (!p.Exists)
  // Application was not launched
...

Python

p = TestedApps.Items(0).RunAs("TESTCOMP", "tester", "psswrd")
if not p.Exists:
    Log.Message("Application was not launched")
    # ...

VBScript

Set p = TestedApps.Items(0).RunAs("TESTCOMP", "tester", "psswrd")
If Not p.Exists Then
  ' Application was not launched
End If
...

DelphiScript

var p : OleVariant;
...
p := TestedApps.Items(0).RunAs('TESTCOMP', 'tester', 'psswrd');
if not p.Exists then
  // Application was not launched
...

C++Script, C#Script

var p = TestedApps["Items"](0)["RunAs"]("TESTCOMP", "tester", "psswrd");
if (!p["Exists"])
  // Application was not launched
...

See Also

Testing Applications Running Under Another User Account
Count Property
Run Method
Launch Property
Terminate Method
Close Method
TestedApps.RunAll
Close Action (Process and Browser Objects)
Terminate Method (Process and Browser Objects)

Highlight search results