DESKTOP UI AUTOMATION - Lesson 3: Sub-flows and reusability

  • How to create a custom, re-usable sub-flows
  • How to add parameters to a sub-flow
  • How to use the data-driven features in LEAPWORK.
  • How to iterate lists of data

Go to next video

You will learn:

  • How to create a custom, re-usable sub-flows
  • How to add parameters to a sub-flow
  • 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.

TRANSCRIPT

Hi

And welcome to the third training video for desktop ui automation in LEAPWORK.

We will continue where we left of in lesson 2 and look more into the reusable subflows
and how you can drive the automation flows with data from external sources.

More specifically we will look at how we create a reusable subflow that will handle the process
of creating a new contact and how to pull the input data from an external excel sheet.

We have an example flow which opens the demo application and logs in using the Login subflow created in the previous lesson.

What I want to create first is a subflow, 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 subflow block we start by creating the flow, that we want to wrap up in the actual subflow.
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.

*** Run flow from here.

In this lesson we wil 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 have the full flow of creating 1 new contact, and we can turn this into a subflow.

We select all the blocks from pressing the "New" button until the "Save" button,
right-click and select "Create subflow".

All the selected blocks are now wrapped into one new subflow – you recognize them by their purple color on the canvas.
I'll re-arrange a bit and rename the subflow to "Create new contact".

Subflows has 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 – thereby saving time and ensuring consistency.

2. Second, the subflow 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 subflows within subflows and thereby build a hierarchy of blocks covering an entire application.
This way an automation flow will be an orchestration of functionality in the subflows which is much easier to manage.


If I double-click the subflow 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 subflow on the canvas,
and it's possible to add more connectors depending on the functionality in the subflow.

The next obvious question after creating a subflow that sets values in fields is:
"Can I add data to this" - or "can I parameterise it "?

Yes, you can, which leads directly to the next obvious question:
"Can I drive the flow with external data?". And yes you can.

LEAPWORK ships with a number of building blocks supporting getting external data to drive the flow.

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 features section.

The most used block for pulling data into the automation flows is the Excel block, which
we will use in this lesson.

I add a "Read Excel" block in front of the create new contact subflow and select a file on
my local drive. I have prepared a file in advance.

I then click "Define" to select the data range I want to use to drive the flow with,
check the "Use first row as header" and click Save.
By using the first row as header,
LEAPWORK 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 subflow and that way create a data connection.
And we can actually do that.

I go back into the subflow and focus on the blocks where we hardcoded the values.

Instead of hardcoding this we can add a Value Input block
which is used to define input fields for a subflow.

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 subflow.

When we go back to the flow we now see that the subflow has 3 new fields and connectors added,
and now it's easy:

We simply connect the right fields using the blue connectors.

This means that when the Create New Contact subflow 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 flow.

As we can see it ended up in Pass, and if I search for Bill in the 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 is the default value and it 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 flow...

*** Run the case

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 LEAPWORK regardless if you have a
list of rows in a grid, a series of web elements or a collection of found images.
The blocks in LEAPWORK will allow you to build a flow to handle the individual elements
and then continue your flow after the iteration is done.

In this video we looked at how to create parameterized subflows
and how to hook these up with an external data source - in this case an excel sheet.
We also saw how easy it is to setup an iteration of data.