5 min read time

One Script to Rule them all – Testing Android and iOS Hybrid Apps with Micro Focus UFT

by in DevOps Cloud (ADM)

 

(This post was written by Chomchalida Chalothorn from the UFT R&D Team)

 

Integrating Micro Focus Mobile Center and Unified Functional Testing (UFT) enables UFT to control and test mobile devices with automated testing software. One frequent question we receive from users is how to use a single script to test both Android and iOS hybrid apps—and have an efficient mobile testing experience.

Unified Functional Testing identifies and recognizes objects by building object properties and a hierarchy. It then uses the properties that make the object unique from others to identify it. 

Hybrid applications normally contain multiple web elements that are generalized for both Android and iOS.  They also include native elements developed for a specific platform. If we can identify the properties that are unique to a specific object, (but identical in different platforms) we can use those properties to create a single script that will replay in both Android and iOS.

This post illustrates how to adjust a script designed for an Android SAP FioriClient application to run in iOS.

 

You can try UFT for yourself to experience these capabilities.

 

Record a script and identify test objects

First, we connected two devices to Mobile Center:

  • Android 5.0.1 Huawei
  • iOS 9.0.2 IPhone 6S Plus

We’ll start by creating a simple script for the Huawei by recording in UFT. This script will:

  • Select Demo Mode
  • Select See it in Action
  • Add a Wait step
  • Add a Standard Checkpoint for the Welcome page

uft_mobile_script.png

In the image above, notice that there are two MobileWebView objects in the object repository.

These are the application’s native objects, and will have different properties in different platforms.

We can verify this using UFT’s Spy function.

The first of the following images shows the MobileWebView’s properties for the Android device. The second shows the MobileWebView’s properties for the iOS device.

Figure 1 MobileWebView properties - Android

uft_mobilewebview_android.png

Figure 2 MobileWebView properties - iOS

uft_mobilewebview_ios.png

 

Modify object properties

UFT uses the MobileWebView object to distinguish between mobile native and web objects in the hybrid application. MobileWebView objects are used as containers for HTML documents. All elements inside MobileWebView objects are recognized as Web objects in UFT.

For UFT to recognize web objects from different platforms, we must remove properties from the MobileWebView object, keeping only properties that are common and can be used by UFT for both platforms.

In the examples above, you can see that the native class and accessibility id properties are present for the Android object, but not for iOS. We’ll remove these properties here.

Note: When removing object properties, you must ensure that the object is still unique and can be identified by UFT. This may not always be possible, and therefore using a single script for both Android and iOS may not be possible all of the time.

Once the native class and accessibility id properties have been removed from all relevant test objects, our object properties should look like this:

uft_mobilewebview_or.png

 

Remove the extra test object

UFT can identify only one MobileWebView object at a time. We can remove the duplicate MobileWebView object, and move its child objects to the remaining one. It’s important to adjust the name of the MobileWebView object in your test steps so that they all match the name in the repository.

Now our object repository looks like this:

uft_mobilewebview_or_updated.png

 

Data drive your test

Configure your script to run on both platforms by using the UFT Global DataTable to run multiple iterations of your script, one on each platform.

Parameterize the id property

1. Select the Device On the right, click Add description properties ( ).

2. Add the id property as shown below:
uft_test_object.png

3. Configure the property value using a Parameter from the Global DataTable, as shown in the following images:

uft_global_prop.png

uft_global_data.png

Add the App identifier property to the DataTable

1. In the object repository, select the click the App object and add the identifier

2. Configure the value using a Parameter from the Global DataTable, as shown in the following images:

uft_test_object2.png

uft_global_data2.png

Remove the name property

The sample FioriClient application that we used in this post has different names in Android and iOS. Therefore, we’ll remove the App’s name property, leaving only the identifier property.

uft_test_object3.png

Run your script

Our script is ready to be run in both Android and iOS. We can add one iteration for Android and another for iOS.

Our object properties and Global DataTable now look like below:

Figure 1 Device properties after adding parameterize

uft_device_id.png

Figure 2 Application properties after adding parameterize

uft_test_object4.png

 

Analyze run results

After the script is run, the Run Result Report Viewer displays results from running in both devices.

The first of the following images shows the result of running the steps on the Android Huawei device. The second shows the result of running the steps on the iPhone 6S Plus device.

Figure 3 Run results - Android

uft_run_results_android.png

 

Figure 4 Run results - iOS

uft_run_results_ios.png

 

Summary

In this post, we’ve shown how to modify a single-script execution across platforms.

Although hybrid apps contain a web application that is similar in both Android and iOS, the container is to different platforms.

We used the UFT test object model and object identification properties to maintain a single object repository and single script for multiple platforms—making your mobile functional testing easier than ever.   

For more information about delivering exceptional user experience across all digital touchpoints – please visit Applandia!

Thanks to Chomchalida for providing this article!

 

Try Unified Functional Testing for yourself!

Feel free to leave a comment in the box below.

 

Labels:

UFT
Functional Testing