Tutorial: Creating your first application script

For more information refer to this blog: Creating Workloads Using Login Enterprise Application XRay

Having your own custom application added to Login Enterprise is one of its most important features. This guide explains how you can create your own application from scratch. In this tutorial we are going to create an application script using the Wordpad application.

If you still need to install the pre-requisites of the Application Scripting. Please see this article.

Step 1. Setting up your scripting workspace

First, open up visual studio code and select the “MyScripts” tab. Next create a Folder with the title of your application for example "WordPad". The name of the folder is also the name we use for both .APP and .CS files. 

Within the folder you just created add an "myapplication.app" file i.e. "WordPad.app" and a application.cs i.e. "Wordpad.cs" file. 

As an example, we created the wordpad folder and files.

app4.png

Step 2. Application Configuration 

Select the "WordPad.app" file and enter the working directory of the application:

Once done close the "WordPad.app" file, we will not be using this anymore. 

Step 3. The basics

Now open the "Wordpad.cs" file. This is the file that contains all of the application commands that need to be executed by Login Enterprise. 

We start with the first few default lines that are required by Login Enterprise to be able to run. 

Make sure that every script has the following lines configured: 

 

Within the Private Void, in between the START(); and STOP(); commands we can start writing our script.

Step 4. Actions and the Application XRay tool

Now we are ready to add actions to our script. There are a number of commands we supply within Login Enterprise you can find them in our scripting functions page. There they are explained in more detail. For now we are going to:

  1. Open application
  2. Write some text
  3. Save the file
  4. Close the application

Xray Tool

To help you with writing the script, we have created a tool called the “ApplicationXRay”. This program is located in the tools directory of the extracted "LoginVSI Scripting Toolset". With the tool, you can select buttons, fields, and area's within an application you want to interact with. The tool automatically creates a string you can copy / paste directly in to the script you are creating.

As an example, open up the Xray tool and drag the scope on a field you want to have selected. I chose for the field where you can enter text. It will highlight the selected area with a red barrier.

app6.png

On the bottom of the Xray tool, we get a Code snippet function. This code snippet is readable code for the engine and can be copy and pasted in to the script.

Step 5. Run the script for the first time

We are first going to check if the application, as configured now, works and starts. To do this we need to add a wait command in the script so we can verify visually it works. So we add:

Wait(5);

Once this is done you can run the script using the "Start Debugging" command found in "Debug>Start Without Debugging". Or by pressing the "Ctrl-F5" command. 

When you have ran the script you should see something like this:

Step 6 Getting familiar with the Xray tool

Once the basic actions are done we can focus on the next step, typing in the application. What we want to do is add the type actions before the Wait() action. To do this we first need to make sure that where we type is going to be correct. Simply sending keys to the application can result in unwanted behavior. This video below explains the different steps to achieve this:

  • Drag the Xray tool to the specific section of the application
  • Change the action point to Focus Window
  • Copy the action to clipboard
  • Paste in to Visual Studio Code
  • Save the script
  • Run the script

Once the action is placed in the script you can try and run it again using ctrl-F5 to check if it works. It is hard to see the actual action happening since its executed in the background. 

Step 7 - Now the real work

Now that we have familiarized ourselves with the Xray tool and Visual Studio Code we are ready for some real work. Now that we have made sure that the location where we want to type exists and is ready we can add the typing actions. 

Again with the Xray tool you can drag over the location you want to type in and select the action in the "Action" dropdown menu. In this case we select "Type to Control". 

Once again you can click the "To Clipboard" button to copy the action and paste it in Visual Studio Code. The command should look something like this:

MainWindow.FindControl(className : "Document:RICHEDIT50W", title : "Rich Text Window").Type("Hello, World!");

As you can see we, by default, fill in the command that we are going to type "Hello, World!". This can be changed to whatever you want. 

Once you have done this it should look like this: 

  • Drag the Xray tool to the specific section of the application
  • Change the action point to Type to Control
  • Copy the action to clipboard
  • Paste in to Visual Studio Code
  • Save the script
  • Run the script

Step 8 - Saving the file

As you might have noticed the application tries to close the application but a prompt about "saving the file" blocks it. In the end Login Enterprise manages the close the application but that is because we kill the process. This is a last-resort response. If you want to do this the clean way we suggest handeling with the popups like a user would do. 

To do this we first want to send a "Ctrl-s" command to prompt the save dialog and again use the Xray tool to find the controls for the save. Once we have found the Save dialog we need to create a variable for it so we direct all actions to that specific window. Then we give the file a name and save it. 

In the Xray tool we are going to use: 

  • Type to Window
  • Focus Window
  • Type to Control
  • Click

The code, when done should look like this:

These are the steps described in the video: 

  • Copy the previous typing command and adding the CTRL-S command.
  • Drag the Xray tool to the main window of the Save File Dialog
  • Change the action point to Find Window
  • Copy the action to clipboard
  • Paste in to Visual Studio Code
  • Modify string to create a variable
  • Drag the Xray tool to the file name text box of the Save File Dialog
  • Change the action point to Type to Control
  • Copy the action to clipboard
  • Paste in to Visual Studio Code
  • Modify String to add variable
  • Change the default typing value to "your desired filename.rtf"
  • Drag the Xray tool to the File name in the Save Button in the Save File Dialog
  • Change the action point to Type to Click
  • Copy the action to clipboard
  • Paste in to Visual Studio Code
  • Modify String to add variable
  • Save the script
  • Run the script

Congratulations! You have now done the basics of Login Enterprise workload editing! We have added the example scripts to this article for you to download as example. 

We recommend adding more features and steps to your script to get more experience. Or continue to our more advanced guide.