Custom blocks and data-driven cases - Desktop UI automation

Learn how to create custom, re-usable components and drive cases with external data.

In this video

  • How to create a Custom, re-usable block
  • How to add parameters to a Custom block
  • How to use the data-driven features in LEAPWORK.
  • How to iterate lists of data

Go to next video.

Lesson Overview

Learn how to create custom, re-usable components and drive cases with external data.

In this video

  • How to create a Custom, re-usable block
  • How to add parameters to a Custom block
  • How to use the data-driven features in LEAPWORK.
  • How to iterate lists of data

Go to next video.

In lesson 3 you will learn how create a Custom building block that can be reused across multiple test cases. We look into how we can add parameters to the Customer building blocks to make them even more useful.

In the example of creating new contacts we show you how to use an external data source to drive the automation case. In this case an Excel sheet containing the data needed for creating contact person, and we show how easy it is to simply wire up the Excel sheet with the parameterized Custom building block.

Finally we show how you can turn a single building block into a looping structure making it very simply to e.g. iterate all the data in an Excel sheet.

Welcome to the third training video for desktop ui automation in Leaptest.

We will continue where we left of in lesson 2 and look more into the custom building blocks and how you can drive the automation cases with data from external sources. More specifically we will look at how we create a reusable, custom building block that will handle the process of creating a new contact and how to pull the input data from an external excel sheet.

We have a test case the opens the demo application and login using the Login block created in the previous lesson. hat I want to create first is a custom building block, that can create a new contact. This means click the New button, fill in – at least – all the mandatory fields, and then click the Save button.

To create a custom building block we start by creating the flow, that we want to wrap up in the custom block. The first action here is to click on the New button,
so we add a Click UI block, and capture the New button. If we run this block, we see an empty contact form opening.

(Automation case runs)

In this lesson we will focus on the Mandatory fields: “LastName”, “FirstName” and “Email” fields. For each of the fields we will add a Set Value block, capture the field and insert a value for the field. We then save the contact using a Click block and capture the Save button. Finally we add a Pass block.

At this stage we we have the full flow of creating 1 new contact, and we can turn this flow into a custom building block. We select all the blocks from pressing the “New” button until the “Save” button, right-click and select “Create custom building”.

All the selected blocks are now wrapped into one new custom building block. I’ll re-arrange a bit and rename the custom building block to “Create new contact”.

Custom building blocks have a lot of advantages:

1. First of all we can create and encapsulate the functionality we want, and make sure that we don’t recreate the same functionality over and over.

2. Second the custom block helps to maintain the overview on the canvas by grouping other building blocks, and thereby limiting the number of blocks on the canvas.

3. Third, you can have custom block inside custom blocks and this way build a hierarchy of blocks covering an entire application. This way an automation case will be an orchestration of functionality in the custom blocks which is much easier to administer.

If I double-click the new block it opens up in a new tab, and we can see that the entire flow is now surrounded by some special building blocks called execution input and output. These blocks define the green connectors on the building block, and it’s possible to add more connectors depending on the functionality in the custom block.

The next obvious question after creating a custom block that sets values in fields is: “Can I add data to this block” – or “can I parameterize the block”?

“Yes, you can.”,

which leads directly to the next obvious question:

“Can I drive the case with external data?”

and “Yes you can.”

Leaptest ships with a number of building blocks the gets external data that can be used to drive the case. There are blocks for getting data from databases, web services, from powershell scripts etc. You can find more information about this in the Learning Center in the Advanced section. The most used block for pulling data into the automation cases is the Excel block, which we will use in this lesson.

We add a “Read Excel” block in front of the create new contact and select a file on my local drive. I have prepared a file in advance. We then click “Define” to select the data range we want to use to drive the case with, check the “Use first row as header” and click Save. By using the first row as header, Leaptest now understands what fields are available for each data row in the selected range.

To use the data from the Excel sheet, it would be nice to be able to just pull the fields onto the Create New Contact block and that way create a data connection – and we can actually do that. I go back into the Custom block and focus on the blocks where we hard coded the values.

Instead of hard coding this we can add a Value Input block which is used to define input fields for a custom blocks. I will name this first one “LastName”, and then connect whatever value is added to this block to the Set Value block for the “LastName” field. I will do the same for FirstName and Email, and then save the custom block.

When we go back to the case we now see that the custom block has 3 new fields added, and now it’s easy: We simply just connect the right fields using the blue connectors. This means that when the Create New Contact block is executed, it will get the input data from the Excel sheet, and insert this into the contact form.

Let’s try to run the case.

(Automation case runs)

As we can see it ended up in Pass, and if I search for Bill in the demo application, We can see that the new contact person is there.

“So what if we want to add all 3 contact persons that we selected in the excel sheet?”. Well, if we expand the Excel block we can see a Method field with the value
“First Row”. This means it will only read the first row in the selected data range. If I select “Row index”, we can specify exactly what row to use. If I select “Iterate”, the top connector on the block will be executed for each data row in the selected data range, in this case it will create a new contact based on the individual rows, meaning we will have 3 new contacts created.

When all the rows in the Excel sheet have been iterated, the Completed connector is executed and we can continue the flow. A flow will stop whenever it encounters a Pass or Fail block, so in this case it makes more sense to move the Pass block to the Completed connector.

Let’s try to run the case…

(Automation case runs)

As we could see we had 3 new contacts created based on the data in the excel sheet.

Iterating data like this is a common feature in Leaptest whatever you have a list of rows in a grid, a series of web elements or a collection of found images. The blocks in Leaptest will allow you to build a flow to handle the individual elementsand then continue your flow after the iteration is done.

In this video we looked at how to create parameterized custom building blocks and how to hook this up with an external data source – in the case an excel sheet.
We also saw how easy it is to setup an iteration of data in a single building block.