+1 404-214-5804
Enterprise Mobility Blog, Mobile App Testing

Tailoring Your Test Script for iOS- and Android-Specific Objects

In a previous post entitled, Testing on iOS and Android Platforms with One Script, I discussed how a single set of objects from the Mobile Labs’ “Mobi” common object model can be used to write a single Unified Functional Testing (UFT) automated script that runs unchanged on multiple supported mobile platforms (for example, Android™ and Apple® iOS).  The example we discussed performed a login and a search using one of our demo apps in Android and iOS incarnations. Mobile Labs’ private mobile device cloud, deviceConnect™, was used to select an iPad Mini to run the script and then to select a Nexus 7 tablet to run the same, unchanged script a second time.

iPad Mini

iPad Mini

Nexus 7

Nexus 7

The “Mobi” common object model maps UI elements from all supported platforms into a common set of objects.  It is easy to imagine, for example, how a MobiEdit (edit box) or MobiButton (button) can be supported identically on all platforms. But what do you do when an object exists in one platform but not another?  We support such objects because manufacturers often implement their most creative ideas in order to attract more users and to stand out from the crowd. Users of a platform may expect apps to use the UI elements that set it apart.

One example of an object that exists in iOS but not in Android is the iOS picker. A picker presents the user with a dial that can be adjusted to select an item from a list.  The Android platform has no identical object.  The same function (selecting items from a list) is managed by the Android drop down.  If the objective remains to use one script on both platforms, and if the designer of the app used a drop-down in Android and a picker in iOS, how can one script still support both apps?

The simple answer is to define, when needed, objects that are unique to a platform and then to tailor the script to perform equivalent functions.  We are going to look at an example of such a customization. For iOS, we will script the picker; for Android, we will script the drop-down.  The object MobiDevice has a method, GetROProperty that may be used learn what platform is current.  MobiDevice is the root object for the Mobile Labs’ common object model, and its methods and attributes apply to the device and the display as a whole.

To see how this all works in practice, I wrote a script that logs into the app and performs a search of the inventory for all in-stock Apple mobile devices.  Most of the script runs without needing to know which platform is current.  When it comes time to set the name of the manufacturer as one of the search parameters, we face a drop-down menu on Android and a picker on iOS.  That small section of the script is tailored for each platform.

The first task is to establish an enumeration that tells us which platform is current.

'#
'# Set up platform discrimination
'#
Dim Platform
P_IOS = 1  ' Constant for iOS platform
P_AND = 2  ' Constant for Android platform

If MobiDevice("PhoneLookup").GetROProperty("platform") = "AndroidOS" Then
    Platform = P_AND
ElseIf MobiDevice("PhoneLookup").GetROProperty("platform") = "iPhone OS" Then
    Platform = P_IOS
Else
    Reporter.ReportEvent micFail, "Platform", "Unknown platform detected."
    ExitTest
End If

After running through this section, the script can examine the ‘Platform’ variable to know which platform is current.

The next section of the script logs into the app, and because the UI uses Mobi objects that are supported on both platforms, no tailoring is needed.  The MobiEdits used for username and password and the MobiButton used to sign in can be identified and manipulated by the same code for both platforms:

'#
'# Log in to app and record transaction time
'#
MobiDevice("PhoneLookup").MobiEdit("ME.Username").Set "mobilelabs"
MobiDevice("PhoneLookup").MobiEdit("ME.Password").Set "demo"
MobiDevice("PhoneLookup").MobiButton("SignIn").Click

The script checks to make sure the login was successful and then sets about the task of priming and executing the search. This section of the code is tailored by platform. For the iOS platform I set the manufacturer to “Apple” using the picker object:

MobiDevice("PhoneLookup").MobiList("ios.Search.List").MobiEdit("MEI.Apple").Click

If MobiDevice("PhoneLookup").MobiPicker("MPI.Picker.Mfgr").exist(1) Then
    MobiDevice("PhoneLookup").MobiPicker("MPI.Picker.Mfgr").Select "Apple"
    MobiDevice("PhoneLookup").MobiButton("MBI.Close").Click

    If MobiDevice("PhoneLookup").MobiButton("Search").Exist(2) Then
        MobiDevice("PhoneLookup").MobiButton("Search").Click
    End If
Else
    ExitTest
End If

Breaking down this code, the first method call brings the picker onto the display.  This line:

MobiDevice("PhoneLookup").MobiList("ios.Search.List").MobiEdit("MEI.Apple").Click

results in the following display (the screen capture is from the QTP run results):

Pic3_tailoring post

The next lines of code scroll the picker to “Apple,” return that result to the MobiEdit, and then start the search:

If MobiDevice("PhoneLookup").MobiPicker("MPI.Picker.Mfgr").exist(1) Then
    MobiDevice("PhoneLookup").MobiPicker("MPI.Picker.Mfgr").Select "Apple"
    MobiDevice("PhoneLookup").MobiButton("MBI.Close").Click
End If

MobiDevice("PhoneLookup").MobiButton("Search").Click

This is how the screen looks when the last line of the script above clicks the ‘Search’ button:

pic4_tailoring post

iPad Mini

pic5_tailoring post

Nexus 7

Note that the ‘Manufacturer’ enumeration in the black-background list is the same presented by the iOS picker.  The method called on MobiDropdown to select “Apple” is very similar to the method call for the MobiPicker:

MobiDevice("Phone Lookup").MobiElement("Element").MobiDropdown("HTC").Select "Apple"

Because the programmer of the app set different default values for the operating system, the Android version of this same sequence contains a couple of extra lines to bring the set of check boxes into sync with the iOS search. We uncheck the Android selection and check the iOS selection:

MobiDevice("Phone Lookup").MobiElement("Element").MobiCheckbox("Android").Set eUNCHECKED
MobiDevice("Phone Lookup").MobiElement("Element").MobiCheckbox("iOS").Set eCHECKED

With the ‘Operating System’ set to ‘iOS’ and the ‘Manufacturer’ set to ‘Apple,’ the screen appears like this when the script clicks the search button:

pic6_tailoring post

Finally, we can examine the identical results of the search on the two platforms:

iPad Mini Search Result

iPad Mini Search Result

Nexus7 Search Result

Nexus7 Search Result

To bring the entire tailoring process into focus, this is the entire platform-specific section of the script shown all at once (we have looked at the individual sections before):

'#
'# Schedule the default search for the platform
'#
If Platform = P_IOS Then
    '#
    '# Perform search on iOS platform
    '#
    MobiDevice("PhoneLookup").MobiList("ios.Search.List").MobiEdit("MEI.Apple").Click

    If MobiDevice("PhoneLookup").MobiPicker("MPI.Picker.Mfgr").exist(1) Then
        MobiDevice("PhoneLookup").MobiPicker("MPI.Picker.Mfgr").Select "Apple"
        MobiDevice("PhoneLookup").MobiButton("MBI.Close").Click
    Else
        ExitTest
    End If
ElseIf Platform = P_AND Then
    '#
    ‘#  Perform search on Android platform
    ‘#
    MobiDevice("Phone Lookup").MobiElement("Element").MobiCheckbox("Android").Set eUNCHECKED
    MobiDevice("Phone Lookup").MobiElement("Element").MobiCheckbox("iOS").Set eCHECKED
    MobiDevice("Phone Lookup").MobiElement("Element").MobiDropdown("HTC").Select "Apple"
End If

MobiDevice("PhoneLookup").MobiButton("Search").Click

Note that the iOS section contains a check to see that the picker has come onto the screen; the script can be faster than the device in some cases, so we check for the picker before attempting to manipulate it.

This post and the one I referred to earlier show the power and potential of the Mobile Labs’ common object model.  We have attempted to give test professionals the best of both worlds.  By using the common “Mobi” object model exclusively, apps can be tested on both platforms without script or object changes. When developers have chosen to exploit UI elements on one or more platforms that do not exist on their counterparts, the QTP script can be tailored based on the current platform to provide identical test results.

Don’t forget to download our eBook on Amazon, to stay ahead of the curve in 2017!

Michael Ryan

Michael Ryan serves as Mobile Labs’ chief technology officer. In this role, Ryan provides the technological vision and drives Mobile Labs Trust’s product road map. Ryan has more than 35 years of experience in leading software development teams that design and build robust and market-leading solutions for large-scale enterprise customers among Fortune 1000 companies. Most recently, Ryan was with Fundamental Software where he worked on large-scale systems CPU emulation architecture, design, and implementation. Prior to Fundamental Software, Ryan was director of development, Sr. VP of R&D, and finally, Chief Technical Officer for CASE tool vendor KnowledgeWare, Inc. Ryan served as senior staff systems engineer, field manager, and regional technical support manager for mainframe manufacturer Amdahl Corporation.

More Posts - Website

Leave a Reply

You must be logged in to post a comment.

Why Mobile Labs?

Mobile Labs provides enterprise-grade, next generation mobile application testing tools. With a focus on security, agility and affordability, Mobile Labs delivers solutions to help you deliver quality mobile apps for Android, iOS and Windows platforms while also helping manage mobile devices in a private, secure cloud.

Contact Mobile Labs

3423 Piedmont Road NE
Suite 465
Atlanta, GA 30305
+1 404-214-5804
twitter  facebook linkedin google-plus SlideShare