Automating Windows Desktop Application with Robocorp

26 Jan, 2021 | 5 minutes read

Introduction

While we are living in an era where digital transformation is the main characteristic of top businesses, many of them still rely on legacy systems and robust applications to perform crucial business processes. These practices have a major impact on productivity, response time, and application performance.

In every organization, there are operational areas with a daily job of executing countless, time-consuming business processes that demand accuracy and speed. Most of these processes require retrieving information from the web, databases, documents, scanned documents, photos, etc.

In order to overcome this potential obstacle, a business process automation tool can be used for greater convenience and speed. One of the emerging technologies nowadays is the RPA (Robotic Process Automation), which is a form of business process automation and allows anyone to configure computer software, or a “robot” to emulate and integrate the actions of a human interacting within digital systems. One of them is Robocorp, which is a Python-based automation tool.

Creating the Process

The process described is a combination of getting data from an Excel file, opening the windows forms application inserting the username and role in the designated fields, and ticking one of the listed checkboxes. After this, click on the Save button, and close the Windows Forms application.

After the installation and the setup of Robocorp are done (https://robocorp.com/docs/courses/beginners-course/set-up-robocorp-lab), open the Robocorp Lab App. Click Create a new robot and name it. After it is loaded, from the left side menu from the listed files, double-click on the tasks.robot file to open it in Notebook mode. The robot for now has two cells: Settings and Tasks sections which can be edited by clicking on them (Figure 1).

The Settings section typically contains documentation, for example, libraries and references to other files. The Tasks section defines the tasks for the robot.

To start creating the robot, first, we will modify the Tasks cell by adding a description of the process that the robot will do. After that, we add the name of the first task that the robot will process, but even giving the name of the first task, still, the robot still does not know what that means, so in order to explain that to the robot, we create a Keywords cell.

We add a new cell by clicking on the plus icon in the toolbar and placing it between the Settings and the Tasks cells. When the new cell is added, we write *** Keywords ***, the name of the task right below it (Figure 2) and we proceed with adding the necessary code.

First of all, we need to open the particular Windows Forms application (Figure 3), and to do so, we have to add the first library in the Settings cell. The particular library containing keywords for Windows desktop applications is RPA.Desktop.Windows (the names of the libraries are case-sensitive, so be careful when writing).

After adding this library, we can now use a keyword in order to open the Windows Forms app, which is “Open from search”, but for this keyword to work, instead of providing the whole path where the application is saved, the best way is to copy-paste the application into the robot folder. After copying it, next to the “Open from search” keyword there are required two parameters, the name of the executable file and the window title name. Therefore, after the parameters are inserted, the robot looks like this (Figure 4).

The next step that the robot has to do is to enter the username, and role, and tick a checkbox. In order to get the locators for the particular fields of the Windows app, there is a recommended app from Microsoft, Accessibility Insights (https://accessibilityinsights.io). After installing and launching the application, inspecting the elements in the Windows application is very easy, because we just hover on the elements, and the properties for the particular elements are listed, from which we should choose which we want to use. One tip regarding Accessibility Insights App is that we have to click on the properties settings button and select “Include all properties that have values”, which will include the AutomationId property as well. (Figure 5)

Now that we have the element locators, we can continue with the actions for them. We will start from the input fields, Username, and Role. We will use the keyword Type which requires two parameters – element locator and keys, i.e. the text we want the field to be filled with. Next, we will tick the first checkbox. Hence, we click on the Save button, and when the confirmation box appears, to click on OK and then close the application. Because we want to ensure that the application will be closed even if some part of our process fails, we will use the “Teardown” keyword. So, until now, the robot looks like this (Figure 6).

As previously mentioned, we are going to use usernames and roles listed in an excel file. In order to proceed with the excel file, first of all, we need to add one more library to the Settings cell and that will be RPA.Excel.Files (the names of the libraries are case-sensitive, so be careful when writing). Now that we have the excel library added, we add the Excel file to the robot folder as well, and then the robot will be able to open the Excel file with the “Open Workbook” keyword.

Next, we add a new task name in the Tasks section – Open Excel, get the data, and iterate through it – for which we create a new Keywords cell, and there we will add the “Open Workbook” keyword which as a parameter requires the file name. We pass the file name (together with its extension) next to the keyword. Since the Excel table has the first row of headers and then the data, the robot needs to read this data in a format that it understands, so a “Read Worksheet As Table” keyword will be used. For that purpose, we will add the Excel data in a variable that will be called ${datas}. Also, because the first row of the Excel file are header, we will pass the header parameter as true. After the data is read, and saved in a variable, we will close the Excel file with the “Close Workbook” keyword (Figure 7).

The next step is to fill the username input field for each of the data rows in the Excel file. In the “Open application and add the data” keyword we will add an expected argument ${data}, which will be a list of items, which means that if we want to access the Username property of our variable, we would write ${data}[Username], and if we want to access the Role property – ${data}[Role]. So, with this, the hardcoded values (John Doe and Writer) will be replaced (Figure 8).

Now that we are assured that the “Open application and add the data” keyword cell is ready to accept arguments, we are going back to the “Open Excel get the data and iterate through it” keyword cell, where we will iterate through the table rows with for loop, so that each of the usernames and the roles will be passed into the input fields. The robot should look like this (Figure 9).

Looks like the process is done here, so we will run the robot, and wait for the results (Figure 10).

Conclusion

Since RPA is one of the leading technologies nowadays, and by using Robocorp as an RPA tool, everyone is able to make smart solutions. The aim of RPA is to create processes, replacing human interaction for continual tasks of the same nature, to ease and accelerate the daily activities of the end-users.