Actions in UFT One with Examples

Every GUI Test in UFT consists of at least one action. Actions in UFT are units within the test that divide the flow of one test into logical sections. A GUI Test can be divided into multiple actions, to make it more modular, understandable, and efficient tests. Whenever a new test is created in UFT, the flow of the action looks like the below in the Solution Explorer.

Actions In UFT

You can write the actual steps in the Action editor. Select the required Action tab or double-click the required action in the solution explorer to open the script editor for the required action.

Action1-Example-UFT

In this article you will learn the following things:


Types of Actions in UFT

On a broader level, there are three types of actions in UFT

Internal and External Actions

  1. An internal action is an action that is stored in the local test.
  2. An external action is a referenced call to another action that is stored in a different test.

Reusable actions

As the name suggests, only a reusable action can be called multiple times within the same or different tests. By default all actions are reusable. We can make it unreusable if required.

Copied actions

You can also insert a copy of Action in a test if you want to modify the action steps of the calling action. When you copy the action, it becomes an internal action of the test into which it is copied. These copies are not linked to the source test, so any changes in the original action are not updated in the copy.

Action Properties

The Action Properties section is displayed in the properties pane of UFT on the right-hand side.

UFT-Action-Properties

You can see the Reusable checkbox is checked by default. This makes the action reusable and this action can be called in some other Action of a test. For ease of understanding, I have created a login action for doing login in the HP sample flight application. You can also provide a description of the action in the description field of the properties section.

UFT-Action-Description

You can also rename an Action by doing a right-click on the required action in the Solution Explorer and select the Rename menu to give a meaningful name and press the Enter key.

UFT-Rename-Action

I am renaming Action1 to “Login” Action.

Renaming-Action-UFT

Whenever an action is renamed UFT throws a warning message. Click the Yes button if the action has not been called in any other Action.

Adding a new action to a test

You can add actions to a test in the following ways:
  • Calls to new actions. This inserts a new, empty action in your test. The action is an internal action of the test containing it.
  • Calls to a copy of an action. This inserts a copy of an existing action in your test.
  • Calls to an existing action. This inserts a call to an existing action (an action external to the current test).

Call to a New Action

To add a new action to your current test, do a right-click on the current action, select the “Action” menu, and then “Call to New Action“.
 

Call-to-new-action-uft

You will get a new popup window with a default action name and default action location as “At the end of the test”.The Reusable Action checkbox will also be checked by default. I want to make find flight reusable hence I will not uncheck it.

New-Action-UFT

You can give a logical name to an action and its valid description. The description is an optional field. I am adding a new action to find a flight.
 
Call-To-New-Action-UFT-2
Now I have written the steps in the FindFlight action to find a flight for the MyFlight sample application.
 
FindFlight-UFT-Action
 
We can call the above two reusable actions in another GUI Test. For doing this you will have to first create a new test and then call both actions. The first “Login” Action will do the login into the MyFlight application and the second one “FindFlight” will find a flight on the specified dates.
 

Call to Existing Action

In order to call an existing action from another test into action in the current test, you will have to do a right-click inside the current action. I have created a new empty test “PlaceOrder” and going to call the “Login” action.
 
Call-To-Existing-Action-UFT
Clicking on the “Call to Existing Action” menu will display a popup window to browse and select the required action. The “From test” drop-down displays a list of all recently created tests.
 
Select-Action-UFT
Browse the test having desired reusable actions. A message might be displayed asking for confirmation before converting the absolute path to a relative path. This is done to ensure that the test does not fail if the files are moved as long as the same hierarchy is followed. Click Yes on this dialog box.
 
Relative-Action-Path-UFT

A list of all reusable actions inside the selected Test will be displayed in the Action drop-down.
 
Action-List-UFT
Select the required action and click on the OK button. Here I am selecting the “Login” Action. You will observe that in the Solution Explorer a new directory with the name “ExternalActions” has been created and Login action is displaying inside it. Also in the tabs pane, you will see a lock icon in front of it indicating it’s a read-only action and can’t be modified.
 
External-Action-UFT

Now select the Action1 of the current test. You will see that one line of code has been automatically added. At runtime, this RunAction method will call the Login action.
 
Run-Current-Action-UFT
 
In the same way, I am calling FindFlight action below the Login action.
 

Run-Action-UFT

 
Now adding steps to place the order to book a flight.
 
UFT-Action-Example

Now if you run the current test, first it will call the Login action to let you in the MyFlight application. Next, the FindFlight action will be called to search for the required flight. After that local action piece of codes will be executed. The flow of execution is also depicted in the test result.
 
UFT-Result

Call to Copy of Action

you can do “Call to copy of action” in the same fashion as we did “Call to Existing Action“. The only difference here will be that calling action would become an internal action of the test into which it is copied. You can do changes as per requirement in the copied action without affecting the original source action. You will not see any lock sign in front of the copy of the action.
 
Copy-of-a-Action-uft

Recommended Posts

Leave a Reply