Skip to main content
Skip table of contents

Scripting Functions Overview

Overview

This section provides an introduction to the key functions available for scripting within the Login Enterprise Virtual Appliance. Our scripting framework offers a comprehensive set of tools to enhance automation and control over Windows applications.

  1. Basic Functions: Essential commands for managing application execution and performance, including launching and closing applications, measuring action durations, and logging key events.

  2. Window Functions: Tools for interacting with and controlling windows and their elements, allowing precise manipulation and error handling in your automation scripts.

  3. Mouse and Keyboard Functions: Functions that simulate user input through typing and mouse actions, enabling you to script user interactions and test application workflows effectively.

  4. File and Registry Functions: Capabilities for managing file operations and interacting with the Windows registry, ensuring smooth automation of file and registry tasks.

  5. Browser Functions: Functions designed to control web browsers, navigate URLs, and interact with web elements, streamlining browser automation for web interactions.

  6. Native Automation Scripting: Advanced capabilities for deeper control over Windows applications using native OS elements, allowing for precise targeting and robust UI automation.

  7. Control Flow Functions: Conditional logic and iteration tools that enable dynamic scripting, error handling, and adaptable automation workflows.

Login Enterprise also comes with the Script Editor, a tool designed to assist administrators in creating custom application workflows. These workflows can be seamlessly incorporated into various testing scenarios, including Application, Load, and Continuous Tests. By leveraging the Script Editor, administrators can streamline test creation and execution, ensuring comprehensive and efficient testing processes tailored to specific application requirements.

  • For more details on the Script Editor, its benefits, use cases, and more, see Using the Script Editor.

  • The Script Editor comes with v1 of the Script Recorder, capable of recording WinApps. To learn more about the Script Recorder, see Using the Script Recorder.

Basic Functions

Basic functions offer essential tools for managing application execution and performance. Commands such as START and STOP are used to launch and close applications, while StartTimer and StopTimer help measure the duration of actions within your scripts. You can log key events, take screenshots for validation, and capture environment variables. These functions also include error-handling features, providing greater control and visibility over script execution, which ensures smooth automation of your testing processes.

Start

START executes the associated application and creates the mainWindow variable. The START command will auto-detect the application's title, class, and process name. All parameters are optional.

Syntax

CODE
START(string mainWindowTitle = null, string mainWindowClass = null, string processName = null, int timeout = 180, bool continueOnError = false);

Parameters

Type

Default Value

Description

mainWindowTitle

string

 

Window title. Example: "Untitled - Notepad"

mainWindowClass

string

 

Window class. Example: "Win32 Window:Notepad"

processName

string

 

Window process name. Example: "notepad"

timeout

int

180

Timeout in seconds for the window to appear

continueOnError

bool

false

Continue with the script on the error

Code Example

CODE
START(mainWindowTitle:"Untitled - Notepad", mainWindowClass:"Win32 Window:Notepad", processName:"notepad", timeout:10);

Stop

The STOP command terminates the associated application. The timeout parameter specifies the maximum number of seconds an application can take to gracefully stop. After the timeout is reached, the application is closed forcefully.

Syntax

CODE
STOP(int timeout = 5);

Parameter

Type

Default Value

Description

timeout

int

5

Timeout in seconds to close an application

Code Example

CODE
STOP(timeout:5);

StartTimer

The StartTimer function allows you to create a custom timer to measure the time one or more actions take within a script. The timers are reported back to the Login Enterprise server as measurements and can be used to trigger a notification if the measurement is over the configured threshold. Measurements are displayed in the Login Enterprise dashboard and charts. StartTimer must be stopped with either CancelTimer or StopTimer.

Syntax

CODE
StartTimer(string name);

Parameter

Type

Default Value

Description

name

string

 

Defines the name of the timer, max of 32 characters

The timer name must only contain alphanumeric characters and underscores.

Code Example

CODE
StartTimer(name:"Create_New_File");
StopTimer(name:"Create_New_File");

StopTimer

StopTimer is used to stop a timer that's started by StartTimer. The StopTimer name should be the same as the StartTimer.

Syntax

CODE
StopTimer(string name);

Parameter

Type

Default Value

Description

name

string

 

Defines the name of the timer, max of 32 characters

The timer name must only contain alphanumeric characters and underscores.

Code Example

CODE
StartTimer(name:"Save_File_To_Network");
StopTimer(name:"Save_File_To_Network");

CancelTimer

The CancelTimer command is used to cancel a timer. The CancelTimer name should be the same as the StartTimer.

Syntax

CODE
CancelTimer(string name);

Parameter

Type

Default Value

Description

name

string

 

Defines the name of the timer, max of 32 characters

The timer name must only contain alphanumeric characters and underscores.

Code Example

CODE
StartTimer(name:"Create_New_File");
CancelTimer(name:"Create_New_File");

SetTimer

Create your own custom timers with the SetTimer function. In many cases, you could call an external value of a system resource, like CPU % utilization, and have it be visible in the Login Enterprise reporting.

SetTimer does not require a start and stop function as it collects an integer at the time it is executed.

Syntax

CODE
SetTimer("name", value);

Parameter

Type

Default Value

Description

name

string

 

Defines the name of the timer, max of 32 characters

value

integer

 

Value collected when the timer is called

The timer name must only contain alphanumeric characters and underscores.

Code Example

CODE
int myCounter = {some code that gets a Windows performance counter in milliseconds};
SetTimer(“MyTimer”,myCounter);

Wait

The Wait function will wait for an X amount of time in seconds before continuing with the script.

Syntax

CODE
Wait(double seconds);

Parameter

Type

Default Value

seconds

double

 

showOnScreen

boolean

true

onScreenText

string

 

Code Example

CODE
Wait(seconds:10, showOnScreen:true, onScreenText:"Waiting 10 seconds");

Log

The log function will log to the console if you are using the Scriptrunner. When using it as part of the Login Enterprise appliance, it logs to %temp%\LoginPI\Logs.

Syntax

CODE
Log(string message);
Log(object component);

Parameters

Type

Default Value

message

string

 

component

object

 

Code Example

CODE
Log(message:"Log Message");
Log(component:MainWindow);

Abort

Abort is used to gracefully exit the script and throw an error message. The error will be shown as an 'Application failure' on the Login Enterprise dashboard, under events.

Syntax

CODE
ABORT(string error);

Parameter

Type

Default Value

error

string

 

Code Example

CODE
ABORT(error:"An error occurred");

ShellExecute

Run a script or application in the Windows Shell

Syntax

CODE
ShellExecute(string commandLine, string workingFolder = "", bool waitForProcessEnd = true, int timeout = 180, bool forceKillOnExit = true);

Parameter

Type

Default Value

Description

commandLine

string

 

 

workingFolder

string

 

 

waitForProcessEnd

bool

true

Waits for the process to finish before continuing.

timeout

int

180

Defines how long to wait for the process to end before it's killed.

forceKillOnExit

bool

true

Forces the application/process to close or stay open after the command has ended. The default is true.

Code Example

CODE
ShellExecute("mspaint", waitForProcessEnd: false, timeout: 15, forceKillOnExit: false);

Create Event

The CreateEvent function will generate a custom event on the Enterprise appliance, which is shown in the results page of a Continuous, Load, and Application Test.

Syntax

CODE
CreateEvent(title:"", description:"");

Parameters

Type

Default Value

Title

string

 

Description

string

 

Code Example

CODE
CreateEvent(title:"Windows Update Available", description:"Update is available on hostname x");

Get Environment 

GetEnvironmentVariable is used, as the name suggests, to retrieve an environment variable. The GetEnvironmentVariable can be stored in a variable to use multiple times in your script. Note that if a continueOnError is not set and if you do not have permission to retrieve the variable, the script will stop.

Syntax

CODE
GetEnvironmentVariable(variableName:"", continueOnError:false);

Parameters

Type

Default Value

variableName

string

 

continueOnError

bool

false

Code Example

CODE
var TempEnv = GetEnvironmentVariable("temp", continueOnError:true);
Log ($"The environment path = {TempEnv}");
Type ($"{TempEnv}");

Take Screenshot

The TakeScreenshot() command is used to create custom screenshots that are sent to the Login Enterprise appliance as Events. This functionality can be used to verify the visual output of an application. You must enable “Custom Screenshots” in the Test configuration to allow this function.  This function is not available for Load Tests.

The Event created has a subject of “The script screenshot '{name}' was created”. The description is the {description} field in your function call. The screenshot bitmap is attached to the Event.

The name field cannot handle spaces; these need to be underscored.

Syntax

CODE
TakeScreenshot(name:"", description:"");

Parameters

Type

Default Value

name

string

 

description

string

null

Code Example

CODE
 TakeScreenshot(name:"Notepad",description: "Check if notepad has loaded the correct file");

Window Functions

Window functions provide capabilities for interacting with and controlling windows and their elements in a Windows environment. Use FindWindow to detect windows by title, class, or process name. The FindControl and FindControlWithXPath functions enable interaction with specific controls, such as buttons or text fields. You can manipulate windows and controls using Click, Maximize, and GetBounds, allowing for precise actions and automation. Additionally, DumpHierarchy is available for troubleshooting by exporting a control tree to a file. These functions offer granular control over window elements and include conditional error handling.

FindWindow

FindWindow can be used to detect a new window or a window that is already open. Each window has a set of information: class, title, and process name, which can be searched on. The ApplicationXRay tool can be used to detect the title, class, and process name of a window or control to allow you to find it in code later.

Syntax

CODE
FindWindow(string title = null, string className = null, string processName = null, int timeout = 30, bool continueOnError = false);

Parameter

Type

Default Value

Description

title

string

 

Find a window matching the title

className

string

 

Find a window matching the classname

processName

string

 

Find a window matching the process name

timeout

int

30

Timeout in seconds to find the window

continueOnError

bool

false

Continue with the script if an error is encountered

Code Example

CODE
FindWindow(title:"*Untitled*", timeout: 5);

FindWindows

Find all windows by title, class, and/or process. If you specify multiple parameters, only the windows matching all criteria will be returned. The parameters do accept wildcards (*). This method will return whenever even if zero windows are found. If no window is found within the given timeout, it will return an empty array.

Syntax

CODE
var windowList = FindWindows(title:"", classname:"", processname:"", timeout = 30);
foreach (var myWindow in windowList) {
    ....
}

Parameter

Type

Default Value

Description

title

string

 

Title of window

className

string

 

Window class

processName

string

 

Name of Windows process

timeout

int

30

Timeout value

Code Example

CODE
FindWindow(title:"*Untitled*", timeout: 5);

Control Actions

When the engine finds the window or object, it can perform multiple actions on the window/object. Using the above example, the following window control actions are available:

Name

Description

openDialogue.Click();

 

openDialogue.Close();

 

openDialogue.DoubleClick();

 

openDialogue.FindControl();

 

openDialogue.FindControlWithXPath();

 

openDialogue.Focus();

 

openDialogue.GetAllChildControls();

Gets all direct child controls for the window (can also be used on a control)

openDialogue.GetBounds();

Retrieves the window or control boundary coordinates in relation to the screen resolution, returning a WindowsCoordinates structure that includes X and Y coordinates along with additional properties.

Returns a WindowsCoordinates structure containing properties and methods for manipulating and interacting with the retrieved coordinates.

GetBounds() contains the following properties:

  • Bottom

  • Center

  • East

  • Height

  • Left

  • LeftBottom

  • LeftTop

  • North

  • Right

  • RightBottom

  • RightTop

  • South

  • West

  • Width

  • X

  • Y

Available methods on coordinate pair properties (Center, LeftBottom, LeftTop, RightBottom, RightTop):

  • Click(): Click the left mouse button once.

  • DoubleClick(): Double-click the left mouse button.

  • MouseMove(): Move the mouse pointer to the specified location.

  • Move(dx: int, dy: int): Move the mouse to a location relative to the selected point, specified by pixels.

  • MoveDown(dy: int): Move the mouse down by the specified number of pixels.

  • MoveLeft(dx: int): Move the mouse left by a specified number of pixels.

  • MoveRight(dx: int): Move the mouse right by a specified number of pixels.

  • MoveUp(dy: int): Move the mouse up by a specified number of pixels.

  • RightClick(): Press and release the right mouse button.

  • X: Integer X coordinate of the location.

  • Y: Integer Y coordinate of the location.

Chaining example: The methods can be chained together for more complex actions. For instance, the following code snippet retrieves the center of control, moves slightly down and to the left, and then performs a right-click:

CODE
javascriptCopy codevar myThing = MainWindow.FindControl(…);
myThing.GetBounds().Center.Move(dx:-10, dy:10).RightClick();

Additional notes: The GetBounds() method not only retrieves the boundary coordinates but also allows for dynamic interaction through the WindowsCoordinates structure.

openDialogue.GetClass();

Gets the class name for the window or control

openDialogue.GetProcess();

Gets the process name for the window or control

openDialogue.GetTitle();

Gets the title for the window or control

openDialogue.Maximize();

 

openDialogue.Minimize();

 

openDialogue.MoveMouseToCenter();

Moves the mouse to the center of the window

openDialogue.Restore();

 

openDialogue.RightClick();

 

openDialogue.Type("");

Types directly to the window and keeps the focus

openDialogue.GetText();

Retrieves the value from the object

openDialogue.SwitchTopMostWindow();

Allows a window to stay on top rather than behind a newly opened window. It provides a better defense against pop-ups overlapping your active window while running a workload.

NativeWindowHandle

For details, see the NativeWindowHandle

NativeAutomationElement

For details, see the NativeAutomationElement


FindControl

Each window has a set of controls (buttons, input fields, text fields, etc). Using FindControl allows you to find and subsequently interact with these controls.

Syntax

CODE
FindControl(string className = null, string title = null, int timeout = 5, bool searchRecursively = true, bool continueOnError = false);

Parameter

Type

Default Value

Description

className

string

 

Defines the class name of the control to find

title

string

 

Defines the title of the control to find

timeout

int

5

Timeout period 

searchRecursively

bool

true

Defines if only the direct children or all indirect children should be searched

continueOnError

bool

false

Continue with the script if control is not found

Code Example

CODE
MainWindow.FindControl(className : "Button:Button", title : "&Open").Click();

FindControlWithXPath

Each window has a set of controls (buttons, input fields, text fields, etc). Using FindControlWithXPath allows you to find and subsequently interact with these controls.

Syntax

CODE
FindControlWithXPath(string xPath, int timeout = 5, bool continueOnError = false);

Parameter

Type

Default Value

Description

xPath

string

 

(x)Path to the control

timeout

int

5

Timeout period 

continueOnError

bool

false

Continue with the script if control is not found

Code Example

CODE
MainWindow.FindControlWithXPath(xPath : "Button:Button").Click();

DumpHierarchy

Every window has a control tree with all classes and names. For troubleshooting purposes, we have a DumpHierarchy method. DumpHierarchy dumps the control tree into a text file.

Syntax

CODE
DumpHierarchy(string filePath, bool refreshBeforeDump = false);

Parameter

Type

Default Value

Description

filePath

string

 

Defines where to store the dump

refreshBeforeDump

bool

false

Defines if we should refresh the control tree before the dump

Code Example

CODE
var Open = FindWindow(title:"Open");
Open.DumpHierarchy(filePath:"C:\\dump.txt");

Mouse and Keyboard Functions

Mouse and keyboard functions automate interactions with Windows applications by simulating user input through typing and mouse actions. The Type command lets you enter text or press keys at a specified speed, supporting key combinations and encrypted application credentials. Mouse functions like Click, RightClick, and DoubleClick provide precise control over application elements based on X-Y coordinates. You can also use MouseMove and MouseMoveBy to reposition the cursor, while KeyDown and KeyUp simulate holding or releasing keys. These functions enable you to script user actions, test application workflows, and ensure that inputs and interactions behave as expected in real-world conditions.

Type

The Type command is used to type text or press keys.

Syntax

CODE
Type(string text, int cpm = 300, hideInLogging:true)

Parameter

Type

Default Value

Description

text

string

 

Text to type or keys to press

cpm

int

300

Characters per minute

hideInLogging

Boolean

true

Hides entry from being logged

Variable options: 

  • ApplicationPassword - Using this variable, you can enter an encrypted password for a specific application. 

  • ApplicationUser - Using this variable, you can enter an encrypted user for a specific application. 

For information on scripting application credentials, see Scripting Secure Application Credentials.

To learn about the encryption types and certificates, see Encryption Technology.

Code Example

CODE
// use type to type text
Type("Insert Text Here");
// use type to press the enter key
Type("{ENTER}");
// use type to press the enter key twice
Type("{ENTER}".Repeat(2));
// use type to press ctrl + O
Type("{CTRL+O}");
// use type to enter a path. backslash is an escape character.
Type("C:\\Folder\\Folder1\\something.txt");
// use @ sign to type path
Type(@"C:\Folder\Folder1\something.txt");
// type quotes
// use backslash to escape quote e.g. \"
Type("\"test\""); // this will type "test"
// type quotes
// use @ in front of string and use double quotes
Type(@"""test"""); // this will type "test"
// typing to a window variable will keep the focus on that window
MainWindow.Type("Insert text here");
KeyDown(KeyCode.SHIFT); // Holds the SHIFT key
Type("insert non-capital text here"); // This text will be typed in uppercase
KeyUp(KeyCode.SHIFT); // Releases the SHIFT key
Type("insert non-capital text here"); // This text will be typed in lowercase

Click

The Click command is used to mouse-click on an X-Y coordinate.

Syntax

CODE
Click(double x, double y, bool continueOnError = false);

Parameter

Type

Default Value

Description

x

double

 

Horizontal coordinate

y

double

 

Vertical coordinate

continueOnError

bool

false

Continue with the script on the error

Code Example

CODE
Click(x:10, y:10);

RightClick

The RightClick command is used by right-clicking on an X Y coordinate.

Syntax

CODE
RightClick(double x, double y, bool continueOnError = false);

Parameter

Type

Default Value

Description

x

double

 

Horizontal coordinate

y

double

 

Vertical coordinate

continueOnError

bool

false

Continue with the script on the error

Code Example

CODE
RightClick(x:10, y:10);

DoubleClick

The DoubleClick command is used to double-click on an X-Y coordinate.

Syntax

CODE
DoubleClick(double x, double y, bool continueOnError = false);

Parameter

Type

Default Value

Description

x

double

 

Horizontal coordinate

y

double

 

Vertical coordinate

continueOnError

bool

false

Continue with the script on the error

Code Example

CODE
DoubleClick(x:10, y:10);

MouseMove

The MouseMove command is used to move the mouse/cursor to a set of X-Y coordinates.

Syntax

CODE
MouseMove(double x, double y, bool continueOnError = false);

Parameter

Type

Default Value

Description

x

double

 

Horizontal coordinate

y

double

 

Vertical coordinate

continueOnError

bool

false

Continue with the script on the error

Code Example

CODE
MouseMove(x:10, y:10);

MouseMoveBy

The MouseMoveBy command is used to move the mouse/cursor by a set of pixels relative to the current position.

Syntax

CODE
MouseMoveBy(double dx, double dy, bool continueOnError = false);

Parameter

Type

Default Value

Description

dx

double

 

Horizontal coordinate

dy

double

 

Vertical coordinate

continueOnError

bool

false

Continue with the script on the error

Code Example

CODE
MouseMoveBy(dx:10, dy:10);

MouseDown

The MouseDown command presses the left mouse button without letting go

Code Example

CODE
MouseDown();

MouseUp

The MouseUp command lets go of the left mouse button

Code Example

CODE
MouseUp();

KeyDown

The KeyDown command holds down a key

Parameter

Description

KeyCode

See the KeyCode list

Code Example

CODE
KeyDown(KeyCode.SHIFT);
KeyUp(KeyCode.SHIFT);

KeyUp

The KeyUp command lets go of a key

Parameter

Description

KeyCode

See the KeyCode list

Code Example

CODE
KeyDown(KeyCode.CTRL);
KeyUp(KeyCode.CTRL);

KeyCodes

Available KeyCodes

CODE
/// Control-break processing
CANCEL = 0x03,
BREAK = CANCEL,
/// BACKSPACE key
BACK = 0x08,
BACKSPACE = BACK,
/// TAB key
TAB = 0x09,
/// CLEAR key
CLEAR = 0x0C,
/// ENTER key
RETURN = 0x0D,
ENTER = RETURN,
/// SHIFT key
SHIFT = 0x10,
/// CTRL key
CONTROL = 0x11,
CTRL = CONTROL,
/// ALT key
ALT = 0x12,
/// PAUSE key
PAUSE = 0x13,
/// CAPS LOCK key
CAPITAL = 0x14,
CAPSLOCK = CAPITAL,
/// ESC key
ESCAPE = 0x1B,
ESC = ESCAPE,
/// SPACEBAR
SPACE = 0x20,
/// PAGE UP key
PRIOR = 0x21,
PAGEUP = PRIOR,
/// PAGE DOWN key
NEXT = 0x22,
PAGEDOWN = NEXT,
/// END key
END = 0x23,
/// HOME key
HOME = 0x24,
/// LEFT ARROW key
LEFT = 0x25,
/// UP ARROW key
UP = 0x26,
/// RIGHT ARROW key
RIGHT = 0x27,
/// DOWN ARROW key
DOWN = 0x28,
/// PRINT SCREEN key
SNAPSHOT = 0x2C,
PRINTSCREEN = SNAPSHOT,
/// INS key
INSERT = 0x2D,
INS = INSERT,
/// DEL key
DELETE = 0x2E,
DEL = DELETE,
/// 0 key
KEY_0 = 0x30,
/// 1 key
KEY_1 = 0x31,
/// 2 key
KEY_2 = 0x32,
/// 3 key
KEY_3 = 0x33,
/// 4 key
KEY_4 = 0x34,
/// 5 key
KEY_5 = 0x35,
/// 6 key
KEY_6 = 0x36,
/// 7 key
KEY_7 = 0x37,
/// 8 key
KEY_8 = 0x38,
/// 9 key
KEY_9 = 0x39,
/// A key
KEY_A = 0x41,
/// B key
KEY_B = 0x42,
/// C key
KEY_C = 0x43,
/// D key
KEY_D = 0x44,
/// E key
KEY_E = 0x45,
/// F key
KEY_F = 0x46,
/// G key
KEY_G = 0x47,
/// H key
KEY_H = 0x48,
/// I key
KEY_I = 0x49,
/// J key
KEY_J = 0x4A,
/// K key
KEY_K = 0x4B,
/// L key
KEY_L = 0x4C,
/// M key
KEY_M = 0x4D,
/// N key
KEY_N = 0x4E,
/// O key
KEY_O = 0x4F,
/// P key
KEY_P = 0x50,
/// Q key
KEY_Q = 0x51,
/// R key
KEY_R = 0x52,
/// S key
KEY_S = 0x53,
/// T key
KEY_T = 0x54,
/// U key
KEY_U = 0x55,
/// V key
KEY_V = 0x56,
/// W key
KEY_W = 0x57,
/// X key
KEY_X = 0x58,
/// Y key
KEY_Y = 0x59,
/// Z key
KEY_Z = 0x5A,
/// Left Windows key (Microsoft Natural keyboard)
LWIN = 0x5B,
/// Right Windows key (Natural keyboard)
RWIN = 0x5C,
/// Applications key (Natural keyboard)
APPS = 0x5D,
MENU = APPS,
/// Numeric keypad 0 key
NUMPAD0 = 0x60,
/// Numeric keypad 1 key
NUMPAD1 = 0x61,
/// Numeric keypad 2 key
NUMPAD2 = 0x62,
/// Numeric keypad 3 key
NUMPAD3 = 0x63,
/// Numeric keypad 4 key
NUMPAD4 = 0x64,
/// Numeric keypad 5 key
NUMPAD5 = 0x65,
/// Numeric keypad 6 key
NUMPAD6 = 0x66,
/// Numeric keypad 7 key
NUMPAD7 = 0x67,
/// Numeric keypad 8 key
NUMPAD8 = 0x68,
/// Numeric keypad 9 key
NUMPAD9 = 0x69,
/// Multiply key
MULTIPLY = 0x6A,
NUMPAD_MULTIPLY = MULTIPLY,
/// Add key
ADD = 0x6B,
PLUS = ADD,
NUMPAD_ADD = ADD,
/// Subtract key
SUBTRACT = 0x6D,
MINUS = SUBTRACT,
NUMPAD_SUBTRACT = SUBTRACT,
/// Decimal key
DECIMAL = 0x6E,
NUMPAD_DECIMAL = DECIMAL,
/// Divide key
DIVIDE = 0x6F,
NUMPAD_DIVIDE = DIVIDE,
/// F1 key
F1 = 0x70,
/// F2 key
F2 = 0x71,
/// F3 key
F3 = 0x72,
/// F4 key
F4 = 0x73,
/// F5 key
F5 = 0x74,
/// F6 key
F6 = 0x75,
/// F7 key
F7 = 0x76,
/// F8 key
F8 = 0x77,
/// F9 key
F9 = 0x78,
/// F10 key
F10 = 0x79,
/// F11 key
F11 = 0x7A,
/// F12 key
F12 = 0x7B,
/// NUM LOCK key
NUMLOCK = 0x90,
/// SCROLL LOCK key
SCROLL = 0x91,
SCROLL_LOCK = SCROLL,
/// Left SHIFT key
LSHIFT = 0xA0,
/// Right SHIFT key
RSHIFT = 0xA1,
/// Left CONTROL key
LCONTROL = 0xA2,
LCTRL = LCONTROL,
/// Right CONTROL key
RCONTROL = 0xA3,
RCTRL = RCONTROL,
/// Left MENU key
LMENU = 0xA4,
LALT = LMENU,
/// Right MENU key
RMENU = 0xA5,
RALT = RMENU,
/// Windows 2000/XP: Volume Mute key
VOLUME_MUTE = 0xAD,
/// Windows 2000/XP: Volume Down key
VOLUME_DOWN = 0xAE,
/// Windows 2000/XP: Volume Up key
VOLUME_UP = 0xAF,

File and Registry Functions

File and registry functions provide the capability to manage file operations and interact with the Windows registry in your automation scripts. Use CopyFile and CopyFolder to move files or directories, while FileExists and DirectoryExists verify whether the items were successfully copied. Commands such as RemoveFile and RemoveFolder facilitate the cleanup of files and folders as needed. For handling compressed data, UnzipFile extracts contents from ZIP archives. Registry interactions are managed through RegImport, which imports registry settings from a specified file. These functions ensure efficient file management and registry operations.

CopyFile

The CopyFile command will copy a file from the source to the destination, overwriting the destination path.

Syntax

CODE
CopyFile(string sourcepath, string destinationPath, bool continueOnError, bool overwrite);

Parameter

Type

Default Value

Description

sourcepath

string

 

Copy the file source path

destinationPath

string

 

Copy the file destination path

continueOnError

boolean

false

Continue if an error occurs 

overwrite

boolean

true

Overwrite the target file if it exists

Code Example

CODE
CopyFile(sourcePath:"C:\\somefile.txt",destinationPath:"D:\\somefile.txt",continueOnError:false,overwrite:true)

CopyFile - Download Existing Example Files

You can download known files from the appliance. This is part of the existing CopyFile command. These files can be found on the appliance under "/loginVSI/content/scriptcontent/" when using WINSCP to connect to the appliance.

Syntax

CODE
CopyFile(KnownFiles.FileType, string destinationPath, bool continueOnError, bool overwrite);

Parameter

Type

Default Value

Description

KnownFiles.

filetype

 

KnownFiles.PdfFile

  1. PdfFile. Downloads a LoginVSI PDF file

  2. Excel sheet. Downloads a LoginVSI xlsx file

  3. OutlookConfiguration. Downloads a LoginVSI PRF file

  4. OutlookData. Downloads a LoginVSI PST file

  5. PowerPoint Presentation. Downloads a LoginVSI PPTX file

  6. RichTextFile. Downloads a LoginVSI RTF file

  7. WordDocument. Downloads a LoginVSI. txt file

destinationPath

string

 

Copy the file destination path

continueOnError

boolean

false

Continue if an error occurs 

overwrite

boolean

true

Overwrite the target file if it exists

Code Example

CODE
CopyFile(KnownFiles.PdfFile, "C:\\Temp\\loginvsi.pdf",continueOnError:false,overwrite:true);

CopyFolder

The CopyFolder command will copy a folder from the source to the destination, overwriting the destination path.

Syntax

CODE
CopyFolder(string sourcepath, string destinationPath);

Parameter

Type

Default Value

Description

sourcepath

string

 

Copy the folder source path

destinathPath

string

 

Copy the folder destination path

Code Example

CODE
CopyFolder(@"c:\testfolder", @"c:\temp\testfolder");
CopyFolder(string sourcepath, string destinationPath);

FileExists

Check if a file exists, which can be used as a verification to check if the file was successfully copied

Syntax

CODE
FileExists(string path);

Parameter

Type

Default Value

Description

path

string

 

Path of the file to verify

Code Example

CODE
FileExists("C:\\Temp\\loginvsi.pdf");

RemoveFile

The RemoveFile command will remove/delete the specified file. 

Syntax

CODE
RemoveFile(string path);

Parameter

Type

Default Value

Description

path

string

 

Path of the file to delete

Code Example

CODE
# literal string path
RemoveFile(path: "c:\\testfolder\\some file.txt");
# verbatim string path
RemoveFile(@"c:\testfolder\some file.txt");

RemoveFolder

The RemoveFolder command will remove/delete the specified folder.

Syntax

CODE
RemoveFolder(string path);

Parameter

Type

Default Value

Description

path

string

 

Path of the folder to remove

Code Example

CODE
# literal string path
RemoveFolder(path: "c:\\temp\\testfolder");
# verbatim string path
RemoveFolder(@"c:\temp\testfolder");

DirectoryExists

The DirectoryExists function checks if a specified folder exists. Can be used after you create a folder, or if you wish to verify if the folder exists before executing an action

Syntax

CODE
DirectoryExists(string path);

Parameter

Type

Default Value

Description

pathOfDirectory

string

 

Path of the directory to verify

Code Example

CODE
DirectoryExists("C:\\Temp");

UnzipFile 

The DirectoryExists function checks if a specified folder exists. Can be used after you create a folder, or if you wish to verify if the folder exists before executing an action

Syntax

CODE
UnzipFile(string SourcePath, destinationFolder, continueOnError, overWrite);

Parameter

Type

Default Value

Description

sourcePath

string

 

Path of the .zip file

destinationFolder

string

 

Path of the folder to unzip the contents into

continueOnError

boolean

false

Continue if an error occurs

overWrite

boolean

true

Overwrite if the file(s) exist

Code Example

CODE
UnzipFile(sourcePath:"C:\\Temp\\loginvsi.zip", destinationFolder:"C:\\temp\\loginvsiwebsite",continueOnError:false,overWrite:false); 

RegImport

The RegImport command will import a registry file into the system registry.

Syntax

CODE
RegImport(string registryFile);

Parameter

Type

Default Value

Description

registryFile

string

 

Path of the registry file to import

Code Example

CODE
# literal string path
RegImport(registryFile: "C:\\temp\\regfile.reg");
# verbatim string path
RegImport(@"C:\temp\regfile.reg");

Browser Functions

Browser functions provide the capability to control web browsers in your application scripts. Use StopBrowser to close a previously opened browser. The Navigate function directs the browser to a specified URL and tracks the time it takes to load the page, which is useful for performance monitoring. FindWebComponentBySelector and FindAllWebComponentsBySelector allow you to locate and interact with web elements using CSS selectors, enabling actions such as clicking or typing directly into the identified components. These functions streamline browser automation, allowing you to script web interactions and measure performance within your application workflows.

StartBrowser

The StartBrowser command allows you to start a browser within an application script. Right now, we only support Chrome 80 and Edge 42/44.

Syntax

CODE
StartBrowser(useInPrivateBrowsing, expectedURL, timeout, continueOnError);

Parameter

Type

Default Value

Description

useInPrivateBrowsing

boolean

false

Define if the browser starts in private mode

expectedURL

string

 

Defines the URL that you want to wait for

timeout

int

60

Waits for # seconds before timing out if not found

continueOnError

boolean

false

Continues the process if an error occurs

Code Example

CODE
StartBrowser(useInPrivateBrowsing:false,expectedUrl:"https://www.loginvsi.com",timeout:30,continueOnError:true);

StopBrowser

The StopBrowser command allows you to stop a browser within an application script. 

Syntax / Code Example

CODE
StopBrowser();

Navigate

The navigate command will tell the open browser to browse to a specific URL. It automatically measures the time it takes to browse to the page.

Syntax

CODE
Navigate(string url, string timerName);

Parameter

Type

Default Value

Description

Url

string

 

URL to browse too

timerName

string

 

Name of the timer

Code Example

CODE
Navigate(url: "https://loginvsi.com", timerName: "Website_LoginVSI");

FindWebComponentBySelector

The findWebComponentBySelector finds a web element based on the given CSS selector. You can attach existing control actions. For more details, see the Control Actions. You can also move your mouse to the component or search for your component by text.

Make the search field as small as possible to eliminate long searches.

Syntax

CODE
FindWebComponentBySelector(string selector, int timeout, bool continueOnError);

Parameter

Type

Default Value

Description

selector

string

 

CSS Selector on the page

timeout

int

30

Timeout in seconds

continueOnError

boolean

false

Continue if an error occurs

Code Example

CODE
FindWebComponentBySelector(selector:"",timeout:30,continueOnError:false);
// It's also possible to type to the web element via
FindWebComponentBySelector(selector:"",timeout:30,continueOnError:false).Type("Example text");
// You can also send a Click to the found web element
FindWebComponentBySelector(selector:"",timeout:30,continueOnError:false).Click();
Browser.FindWebComponentBySelector("button[id='logonbutton']",timeout:30,continueOnError:false).Click();

FindAllWebComponentsBySelector

Sometimes the CSS selector appears multiple times within the webpage, which makes it hard to find the one you are looking for. To list the selectors, you can use this command. The result can be used by findWebComponentBySelector. 

You can also move your mouse to the component. For more information, see the Control Actions.

Syntax

CODE
FindAllWebComponentsBySelector(string selector, int timeout);

Parameter

Type

Default Value

Description

selector

string

 

Selector object name

timeOut

string

30

Timeout value

Code Example

CODE
var components = FindAllWebComponentsBySelector(selector:"A", timeout:30);

Native Automation Scripting

Native automation scripting enhances the capabilities of scripting within the Virtual Appliance by providing deeper control over Windows applications through native OS elements. The NativeWindowHandle and FromNativeWindowHandle functions enable you to identify and work directly with windows using their native OS handles, allowing for precise targeting. SwitchTopMostWindow ensures that the desired window remains on top, preventing pop-ups from interrupting automated tasks. NativeAutomationElement offers direct access to UIAutomation features, providing robust control over UI elements when default methods, such as typing, are insufficient. These functions significantly enhance your ability to script and automate complex interactions with Windows applications.

Using these functions requires you to include the following line at the top of your script:

CODE
using Interop.UIAutomationClient;

NativeWindowHandle

Returns the unique identifier of the window as it is known to the Windows OS. This solves the issue where we cannot uniquely identify any given window.

Syntax

CODE
IntPtr NativeWindowHandle;

Code Example

CODE
FindWindow(title:"*Untitled*", timeout: 5).NativeWindowHandle;

FromNativeWindowHandle

Constructs a scripting window object from a native window handle. This allows us to work with a window that was found by its handle using native technologies like Win32 calls.

Syntax

CODE
IWindow FromNativeWindowHandle(IntPtr handle);

Code Example

CODE
var myNativeWindow = Process.GetProcessesByName("notepad")[0].MainWindowHandle;
var myLEWindow = FromNativeWindowHandle(myNativeWindow);

NativeAutomationElement

This provides access to the underlying automation (UIAutomation) library that the Login Enterprise Engine uses. It allows us to use low-level automation actions like manipulating checkboxes directly or setting the value of a text edit control in a more resilient way if typing doesn't work properly.

In-depth information about the UIAutomationClient functions is beyond the scope of this section.

You can download a code example from here.

Syntax

CODE
IUIAutomationElement NativeAutomationElement;

Code Example

CODE
MainWindow.FindControl(classname:"*Document*").NativeAutomationElement;

Control Flow Functions

Control flow functions provide options for implementing conditional logic and iteration in your scripts. The If Else statement allows you to execute code based on whether a condition is true or false. The Try Catch construct enables error handling, ensuring scripts continue running smoothly even if an element is not found. Loops like While and ForEach let you repeat actions until a condition is met or iterate over a collection of values. These control flow functions are essential for building dynamic and resilient scripts, helping you automate workflows that adapt to changing conditions and handle errors gracefully.

These functions represent standard programming concepts that are common across many languages, including C#. While they may be familiar to experienced programmers, we recognize that many of our users may not have a programming background. This section aims to clarify these concepts for those who may be new to scripting, particularly as our workload scripting in C# supports these features, facilitating more advanced and conditional scenarios.

If Else versus Try Catch

Function name: If Else statement

Description: The If...Else statement allows you to create conditional logic in your scripts. If the condition is true, the code within the If block executes. If the condition is false, the code within the Else block executes. Note that the Else statement is not mandatory.

Example:

CODE
var Condition = MainWindow.FindControl(title:"Condition");
if (Condition != null)
{
Type("Condition is true");
}
else
{
Type("Condition is not true");
}

Challenges:

Finding a control may throw an exception if the control is not found. If "Continue on Error" is not enabled, this will terminate the workflow.

Solution

Reword the script using a Try...Catch statement. This approach can eliminate inconsistent pop-ups and allow the script to continue running even if a control is not found.

Example:

CODE
Try{
var Condition = MainWindow.FindControl(title:"Condition");
Condition.Click();
}
catch{
Log("Was unable to find conditional window");
};

While

Function name: While

Description: The While statement executes a block of code in a loop as long as the specified condition evaluates to true. The condition is evaluated before each iteration of the loop.

Example:

In the following example, we specify an integer variable that equals zero. While the number is less than 10, we log the number to the console and add +1 to it until it evaluates to false.

CODE
int number = 0;
while(number < 10)
{
Log(number);
number++;
}

ForEach

Function name: foreach

Description: The ForEach statement iterates through each item in an array of values.

Example:

In the following example, we iterate through 3 sample values.

CODE
string[] example = {"example 1","example 2","example 3"};
foreach (string value in example)
{
Log(value);
}

Additional Uses

When working with a browser application, collecting all web selectors can be beneficial. You can then use a ForEach loop to find a specific condition or to identify a particular selector from an array of many.

Try it on your own environment for free.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.