WEB AUTOMATION - Lesson 2: Sub-flows and re-usability

  • How to reuse parts of an automation flow elsewhere by creating sub-flows.
  • How to add parameters to a sub-flow to make them even more reusable.
  • How to use the blue connectors in LEAPWORK for transferring values between building blocks.
Go to next video.

You will learn:

  • How to reuse parts of an automation flow elsewhere by creating sub-flows.
  • How to add parameters to a sub-flow to make them even more reusable.
  • How to use the blue connectors in LEAPWORK for transferring values between building blocks.
Go to next video.

TRANSCRIPT

Welcome to the second lesson on Web automation using Leapwork!

In our previous lesson, we learned about the creation of basic flows for Sign In functionality. I hope you were able to successfully create the flow.

In this lesson, we will explain why reusability is so important and how you can achieve it with leapwork.

Reusability in automation refers to the ability to reuse building blocks, files, and assets in other flows.

Reusability is important in automation because it can improve the efficiency, consistency, and maintainability of your automation efforts.

Let’s take an example: 

An application that has entire functionality implemented behind login requires Sign in to be executed in every flow

If we repeat the same blocks for login again and again in multiple flows, then we end up in duplication of the same blocks in multiple flows, and if the developer makes a small change in the login feature, then we must manually change all those blocks we duplicated, thereby consuming our majority time in maintenance.

In Leapwork we can achieve the same functionality without having such maintainability by creating reusable building blocks called sub-flows. 

This lesson will learn how to create and use reusable sub-flows.

We will continue to use the flow we created in lesson 1.

Let's get started! 

Here is the flow we created in Lesson 1

Performing a login could be part of many web automation flows.
In some cases, many flows will include a login at the very start of the flow,
so, the login process is typically a good candidate for a reusable sub-flow.


To create a sub-flow, select the building blocks that you want to use to make a reusable component. 

For example, in our flow, we will select the blocks that perform the Sign-In function, from entering the Username to clicking the "No" button.

Once the blocks are selected, right-click on the canvas and select "Create sub-flow."


By default the name of the sub-flow is suggested as “New Sub-Flow”, please ensure to give it a meaningful name so that it is easy it find it later, let’s name it “Sign In” and click save.
Now we see that all the selected building blocks are wrapped up into one new building block named Sign In. 

The Sub-flow is created, Let’s see where and how we can reuse the created Sub-flow in our other flows.


Suppose we want to create a flow to add the Lease, for that, we need to Sign In first, there we can call the above created Sub-flow first and continue with our creation. 

Let’s create the new flow first, (Pause – creating a new flow)

Here we are, 
move to the Canvas and do the steps to add the new block after the ‘Start’ block, in the ‘Add new building Block’ menu go to the end and Click on the ‘Sub-flows’ Category and you get the Sub-flow ‘Sign In’ which we have created above, select the ’Sign In’ Sub-flow.

The Sub-flow is added to the New Flow.

We can continue the flow creation as we do in the previous lesson.

Now the next question comes to mind how we would edit the Sub flow?


To edit the Sub flow, you right-click on the Sub flow on the Canvas and Select the ‘Edit Sub-Flow’ option and you can see the Sub flow is opened in the editable mode.


The other way to open the Sub flow is by double clicking the Sub flow from the Explorer pane. (Action is missing in Video)
We have seen how we can reuse the Sub Flow and are open to editing.

Now we are going to look at another very useful feature with sub-flows called parameterization.

Instead of hard coding the values inside the sub-flow, we can define input parameters to the sub-flow that helps us in passing a different set of data to the same sub-flow. In this case, if we use parameters, we can also pass different credentials to log in to D365 to test user-based scenarios.


Adding a parameter is very easy, simply add a Value Input building block by right click on the Canvas and clicking ‘Add building block’.

Select the ‘Value Input’ block that lies under the category ‘Module Input and Output’.

Once the block is visible on the Canvas we can rename the block by double clicking on the header of the block and renaming it to ‘Email’ as we are using this for an email address, as a best practice it is always good to provide a logical name.


There are blue connectors available on the blocks, they are used for transferring values and properties between building blocks.

Drag the blue connector of the ‘Email’ Value Input block to the text field of the ‘Type Web text’ block where we entered the Email of the User.

Connecting the parameter block to the Type Web Text means that any values passed as parameters to the Email parameter will be further passed to Type Web Text as a Text.
Let’s repeat the same actions with the password field:

- Adding a Value input block and renaming it to ‘Password’. (pause)

- Then connecting the Value Input block, data connector to the text value property of the Type Web text block contains the Password.

Now we created the two Value input connectors for the Sub Flow. 
Let’s Save the Sub Flow and move back to the main flow.


Ahaa, we can see that the custom block now has 2 new input parameters defined: email and password.
Let’s learn how to pass data to the sub-flow:
There are two ways to pass the data to the sub-flow.
1)    By directly writing the values into the test box in the sub-flow or
2)    By using Set text or using a data provider like Excel to pass the value 
let’s see how we can pass data to the sub-flow using a set text building block.

To specify the e-mail address, we use a Set Text building block and connect to the Email property in the main flow. 

We get the ‘Set Text’ block under the ‘Set Value’ Category. 
After adding the block enter the email id in the text field.

After entering the value, connect the text value data connector of the ‘Set text’ block to the data connector of the ‘Email’ of the ‘Sign In’ block.


Similarly, we use the Set Text block for the Password field as well, (Pause)

To secure the password from others, the only change we do in the Set text block before providing the password is to Set the Type of text as
as a Password.

To achieve that, we expand the Set text block and change the Type to Password.

After changing the type to ‘Password’ we enter the value in the text field and you can see the value is masked.

We are ready to run the login flow - this time using a reusable, parameterized custom block.
Let’s Click on Run, to see the execution.
The flow Passed as expected.
Let’s see how to debug the flow with the sub-flow.

Click on the log message for a block that is placed inside the Sub Flow, and Leapwork will highlight the Sub Flow.

Double-click on the Same log message will open the preview screen of the Sub-flow with the highlighted relevant block. 

Using this technique, you can easily debug the sub-flows. 

Here are some benefits which sub-flows can bring to automation:

Efficiency: By reusing existing flow assets, you can save time and effort compared to creating new flows from scratch every time. This can be especially useful for regression testing, where the same tests need to be run repeatedly.

Consistency: Reusing flow assets can help ensure consistency across tests and test suites. This can help identify patterns and trends in test results more easily.

Maintenance: When you have many flows, maintaining them can become a challenge. Reusing flow assets can make maintenance easier by reducing the number of tests you need to update.

Scalability: Reusing flows assets can help you scale your testing efforts by enabling you to quickly create new tests or test suites by leveraging existing assets.




Overall, In this lesson, we learned, 

How to design flow in a modular way, with sub-flow, so that changes can be made in one place and applied across multiple tests.

How to parameterize a Sub flow by passing input values from outside to a Sub flow.

How to create an Efficient, Maintainable, Reliable, and scalable flow.

We suggest you try replicating this flow on your own by following the video.