Part 1: Advanced script enhancements in TruClient – Native Mobile protocol

Micro Focus Frequent Contributor
Micro Focus Frequent Contributor
0 0 324
0 Likes

mobile_480x240.jpgThe TruClient – Native Mobile protocol provides a novel way to record and replay native mobile applications on both Android and iOS devices. The protocol enables the developers or DevOps engineers to record user interactions on the mobile applications and create TruClient scripts.

After recording the business process you want to test, you usually want to enhance the script to represent multiple Virtual Users (Vusers) or supply different inputs during the load test’s execution.

Using parameters and changing the Object Identification method

This is done in TruClient by supplying parameters to the step arguments using the TCA.getParam function. For example, when you want to parameterize the searched item in a search step, you can parameterize the Value parameter of a Type step, just as you always did in TruClient:

1.png

 However, when you want to parameterize objects, the story is a little different. In TruClient - Web you can change the object identification method to XPath or JavaScript and supply a different XPath or JavaScript arguments, while in TruClient – Native Mobile it is less flexible. 

When a step is created, the object identification method options contain only JavaScript. In the JavaScript, you will see a string that represents the object.

2.png

In the example above, you can see that selecting an airport creates a step for the Tap action, and the object is identified according to its string visualization (among other internal properties).

What if you need to select some other airport on the list? All you need to do is to change the string in the JavaScript field. You can enter any valid JavaScript that produces a string with the value you want. For example, you could use ArgsContext.TCA.getParam(“Airport”) which uses a corresponding parameter in VuGen:

3.png

This approach works for objects that follow the same layout structure, like lists and labels, and more. It doesn’t work for objects that are in completely different structures on the screen, but in any case, you don’t usually need to parameterize these kinds of objects.

Notice that in some Roles and actions the object parameterization is bundled in the arguments. For example, selecting a radio button inside a radio group can be parameterized using the arguments:

4.png

Analog mode

In rare cases, you might find yourself failing to record a certain object on the screen. Tapping on the screen will not generate a step. This might be caused by a customized control that UFT Mobile fails to recognize. As a workaround, you can use Analog mode. Switching to Analog mode generates steps of the type Touch on Device with arguments of X and Y coordinates:

5.png

Guess what this step does? It simulates a tap on the given point. This way you can overcome problems in recording. Switch to Analog mode for the specific control and then switch back. 

The drawback in Analog Mode is the resolution differences between the devices. In regular mode, a step recorded on a mobile phone also works in a tablet, while in Analog mode it might not work. You can add an If step to run a different Touch on Device step for each device to overcome it. 

As part of the business process you are recording, you may need operations from the device itself. These may include pressing the ‘Back’ button to go to the previous screen or simulating a phone call that arrives and the application should handle. You can do this by using a Generic Device Action step (available from the Functions tab in the Steps box).

6.png

The available actions on the device vary according to the currently selected device operating system – Android or iOS. For details, see TruClient Steps box for native mobile.

Understanding the Scroll action

TruClient – Native Mobile usually adds a Scroll action on an object that needs to be scrolled in order to perform some operations on it. For example, tap on it. In Android devices, every object that has a role of Scroller will contain a scroll action as part of the step’s available actions. In iOS devices, certain roles will have a Scroll action (like CollectionView, Table, etc.). This means that you don’t normally need to add a scroll action as a generic device action. But what happens if you fail to record a certain action on the application? How will you reach the object in order to perform a ‘Touch on Device’ step? Use the Scroll on Device step to simulate the scroll operation on an abstract object. Let’s take a look at the arguments:

7.png

The Direction can be either forward or backward. The Object index represents the object that you want to scroll on. TruClient looks for all the scrollable objects in the screen from the top left to the bottom right and performs a scroll on the object with the specified index. This lets you perform scrolls to bring your object to the screen.

In this blog, I covered some more advanced features in TruClient – Native Mobile that enable you to enhance the script. In the next post, I’ll talk about the extended log and how to run one script on multiple devices. Hope you are enjoying reading this series!

The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.