Over the past years, the mobile applications market has expanded tremendously. Mobile applications are simply everywhere. Consequently, the importance of testing mobile applications, has become crucial. This is a vital step in making sure consumers of these applications have a positive experience while using them.
UFT Pro (LeanFT), through its integration with Mobile Center, provides an easy-to-use, end-to-end, mobile testing solution. Using LeanFT together with Mobile Center, you can test your native, hybrid and mobile-web applications that run on iOS, Android and Windows Phone devices, while using all of LeanFT’s powerful capabilities, such as its Object Identification Center and Application Models.
This blog post provides step-by-step instructions for easily testing your mobile applications with LeanFT and Mobile Center. The blog provides an example for using LeanFT on a Windows machine. However, LeanFT’s mobile testing solution is also supported on Mac and Linux machines, and its usage principles on these platforms is similar.
Designing your mobile tests with LeanFT
In this section we’ll go over the process of creating tests for your mobile apps using LeanFT.
First you need to configure LeanFT for mobile testing, using the following steps. The configuration should be done only once per machine:
1. Launch the LeanFT runtime engine. Launching the engine can be done by selecting it in the Windows start menu, under your LeanFT (or UFT) Start menu folders:
Once the engine is launched, you will see the runtime engine’s tray icon in your taskbar:
2. Right-click the tray icon, and select “Settings” in the menu. As a result, the LeanFT Settings dialog box opens:
(The screenshot above was taken for LeanFT 14.01. In previous versions, the interface is slightly different)
3. In the “Engine” tab, under the “Add-ins” list, make sure to select the “Mobile” check box.
4. Select the “Labs” tab (in versions prior to LeanFT 14.01, there is no “Labs” tab, and the steps below can be done in a section presented when clicking the “Show more” link near the “Mobile” add-in):
In the Mobile Center Settings section, configure your Mobile Center settings, namely: the server address (including its port), your Mobile Center user name, and your Mobile Center password. You can also configure your proxy server if needed, by checking the “Use proxy” check box, and providing the proxy server details in a dedicated section presented at the bottom of the same tab. Once you are done, click the “Verify” button to verify your connection settings.
5. Save your changes using the “Save” button. The changes will be applied and the engine will be restarted. You can now exit the engine, by right-clicking its tray icon and selecting “Exit”.
Your machine is now ready for mobile testing with LeanFT and Mobile Center.
2. Creating your tests in the IDE
The flow below is based on the usage of Eclipse, with the LeanFT Java SDK and Junit as the testing framework. However, the flow for other supported IDEs, LeanFT SDKs, and testing frameworks, is similar:
1. Create a LeanFT project (or a new test in an exisiting project)::
2. Once you project or test case is created, a new class is presented in your IDE:
The last required step before actually implementing your test, is importing the LeanFT SDK’s mobile package, to your class:
Importing the mobile package makes all the services and APIs required for automating your mobile app available for you in your test. The mobile package is very comprehensive and provides everything you need for effective mobile test automation.
3. Implement your test
Now let’s talk about the interesting stuff: actually implementing your mobile test, using LeanFT’s SDK and tools (e.g.: the Object Identification Center). For this we’ll use a sample mobile native app. However, as we’ll see later, automating hybrid apps is very similar:
1. Launch your mobile application directly from the IDE:
The LeanFT IDE plugin enables you to open a VNC window which presents a device from your Mobile Center server, to be used when implementing your test. The application you are automating can be launched on that device and viewed in the VNC window, which enables you to spy on it (using the Object Identification Center) and create your identification code, whether you are using descriptive programming or by modeling the application objects to application models.
To open your device in the VNC window, click the “ Mobile Center” button in the LeanFT IDE menu or toolbar:
The “ Mobile Center” dialog opens, and you can select your device and application under test:
First, select the application you would like to automate, using the button to the right of the “Application” field. A Mobile Center window opens, presenting all the applications which are currently available in your Mobile Center server (If the application you would like to test is not displayed (or you would like to test another build of an existing application), you can upload it to Mobile Center using the “Upload application” option in the Mobile Center interface):
Now, select in the opened window the application you would like to automate. You can filter the list of presented applications based on the required device’s operating system, using the filter in the left pane. When selecting the application, note that you can configure whether to use a packaged (instrumented) version of the application, or use a non-packaged version of the application (read more about packaged and non-packaged applications in the Mobile Center help center):
Click the green confirmation button on the right to confirm your selection.
The “Mobile Center” dialog is presented again, enabling you this time to select the desired device. Click the button to the right of the “Device” field in the dialog. The Mobile Center window opens again, in which you can select the device to use while automating your application. Note that only devices that are compatible with the selected application (e.g.: Android devices for Android apps) are presented:
Select the desired device and click the confirmation button.
The “Mobile Center” dialog box displays again. In the dialog box, you can select the check box next to ”Install application” if you want your application to be installed on the device (or override an existing installation). In case the application is already installed on the device, you can select the checkbox near “Restart application”, if you would like the application to be restarted on the device in case it is opened there already. Now, just click the “Launch” button. A VNC window opens, providing you an active view of the selected device, in which the selected application will be launched automatically. If you selected to install the application, it will first be installed and then presented in the VNC window:
Once the device and application are open in the VNC window, automating it is basically the same as automating applications of other technologies, e.g.: web applications. You can simply spy on the application (directly on the VNC window) using LeanFT’s Object Identification Center and use other LeanFT tools to automate it.
2. Create code for launching the device and application from your script:
Mobile testing scripts usually start with code for locking (fetching) a device from Mobile Center. Locking a device is done by using the “MobileLab” class, which is part of the LeanFT SDK. The MobileLab class enables you to lock a specific device (e.g.: by its ID or name), or to dynamically lock an available device, based on given device capabilities (e.g.: operating system and / or manufacture). You are encouraged to read about all the options for locking devices in the documentation of the MobileLab class in the relevant LeanFT API reference (available from the LeanFT online Help Center). For simplicity, we’ll see below how to lock a specific device based on its ID:
You can copy the device ID from the VNC window above (the ID is presented at bottom-left corner of the window). Simply select it, right-click and select “Copy” in the open menu.
Then in your script, you should add a code like:
Device device = MobileLab.lockDeviceById("LGH961N1b5d4280");
Where the ID provided as an argument to “lockDeviceById” is the one you have copied.
When executing the script, LeanFT will lock the device with the given ID in Mobile Center. The call to “lockDeviceById” returns a LeanFT object of type “Device” which provides you with all the APIs needed to manipulate that device.
The next step is creating code in your script to launch (and if needed: install) the application under test, on your device. The easiest way to create this code is as following:
In your IDE, open the LeanFT Object Identification Center (by selecting it from the “LeanFT” IDE menu or toolbar). Then start spying on the mobile application presented in the VNC window, and click (doesn’t matter where, as long as it is done within the scope of the application). The Object Identification Center presents information about the object you clicked on. Scroll up to the root of the tree presented in the Object Identification Center, and select the “Application” node:
Now, all you have to do, is click the “Generate Code to Clipboard” button, in the Object Identification Center (the 2nd button from the left, in the bottom toolbar). Paste the generated code in your script:
device.describe(Application.class, new ApplicationDescription.Builder() .identifier("com.Advantage.aShopping") .packaged(true).build());
The generated code provides you with a LeanFT object of type “Application”, which will be used in your script from this point on, to manipulate the application itself. Assign the returned value to a variable of type “Application”:
Application app = device.describe(Application.class, new ApplicationDescription.Builder() .identifier("com.Advantage.aShopping") .packaged(true).build());
Now, use the Application class API to launch the application, restart it, or install it on the device, e.g.:
At this point, you can complete your script (as we’ll shortly see), by including code which manipulate objects in the application, verify its behavior, etc.
At the end of your script, you can use the Application class API to close and / or uninstall the application, using the Application class kill() and uninstall() APIs (respectively).Note that these 2 APIs are available only from LeanFT version 14.01.
3. Implement the required application scenario, using the Object Identification Center:
After creating the code for locking the device and launching the application, you can start to automate the application scenario to be tested. As with any application technology supported by LeanFT, this is done with the help of the Object Identification Center. Simply spy in the VNC window on objects you would like to automate. LeanFT will present the object’s information and a recommendation for a unique identification of the object. Then, you will be able to generate the identification code easily, using the “Generate code to clipboard” capability. For instance:
Creating code for tapping the “Laptops” objects in the demo application opened in the VNC window that is presented in the screenshot above, can be done by first spying it. Once done, you will see the following in the Object Identification Center:
As you can see, LeanFT identified the object as a “Label”, and the object properties are presented in the Object Identification Center as long as a recommendation for a unique identification. To create an identification code for the object, click the “generate code to clipboard” button, and paste it in your script. The code also includes the identification code for the application itself (which we created already). Refactor it to reuse the app variable created above, and add a call to the “tap()” operation. Your code will look like this:
app.describe(Label.class, new LabelDescription.Builder() .text("LAPTOPS") .className("Label") .resourceId("textViewCategory") .mobileCenterIndex(2).build()).tap();
4. Using Application Models in mobile testing scripts:
You can also use the LeanFT Application Models when automating your mobile applications and enjoy all its benefits. The flow for modeling mobile objects in Application Models is the regular flow:
Start with creating your Application Model, by selecting the relevant template in the IDE wizard. Then, open the Object Identification Center from the Application Model interface. Spy an object you would like to model, directly on the mobile application presented in the VNC window. Finally, click the “Add object to Application Model” in the Object Identification Center. The object is added to the Application Model. Repeat the same process of other objects you would like to model. Example:
Let’s model the user name, password and Login button in the following application, into an Application Model named “MobileAppModel”:
Once done, the Application Model interface will look like this:
Note that the root of the Application Model is not the “Device” object, but rather the “Application” object. This allows us to model our application once, and reuse it for testing the application with different mobile devices.
To use the Application Model in our script, we first create an instance of the automatically generated Application Model class (“MobileAppModel” in our case). When creating this instance, we provide it with the “Device” object as an argument, which will serve as the context for our Application Model. This makes the Application Model reusable with different devices, as we can simply create its instance each time with a different device object.
The below is a code sample for using the Application Model we created, in our script:
MobileAppModel appModel = new MobileAppModel(device); appModel.AdvantageShoppingApplication().userNameField().setText("demo_user"); appModel.AdvantageShoppingApplication().passwordField().setSecure("597eeefe1aabcc5812089a773b8a947b8098"); appModel.AdvantageShoppingApplication().LOGINButton().tap();
Below you can find a full code sample based on the example we have used:
Device device = MobileLab.lockDeviceById("LGH961N1b5d4280");
Application app = device.describe(Application.class, new ApplicationDescription.Builder() .identifier("com.Advantage.aShopping") .packaged(true).build());
app.install(); app.launch(); app.describe(Label.class, new LabelDescription.Builder() .text("LAPTOPS") .className("Label") .resourceId("textViewCategory") .mobileCenterIndex(2).build()).tap(); app.describe(UiObject.class, new UiObjectDescription.Builder() .className("ImageView") .container("Table") .resourceId("imageViewProduct") .mobileCenterIndex(0).build()).tap(); app.describe(Button.class, new ButtonDescription.Builder() .text("ADD TO CART") .className("Button") .resourceId("buttonProductAddToCart") .mobileCenterIndex(0).build()).tap(); MobileAppModel appModel = new MobileAppModel(device); appModel.AdvantageShoppingApplication().userNameField().setText("demo_user"); appModel.AdvantageShoppingApplication().passwordField().setSecure("597eeefe1aabcc5812089a773b8a947b8098"); appModel.AdvantageShoppingApplication().LOGINButton().tap(); app.kill(); app.uninstall();
Automating mobile hybrid apps
In the section above we have gone through the process of automating a mobile application with LeanFT and Mobile Center. Our example in that section was based on a sample mobile native app. However, as mentioned in the intro of this blog, you can also use LeanFT to automate mobile hybrid applications.
The good news is that the flow for automating hybrid apps with LeanFT is basically exactly the same as the one for automating native apps. The only difference I would like to highlight is regarding the hierarchy of the objects in hybrid apps, and the corresponding test objects hierarchy in LeanFT, used for automation:
Hybrid apps object hierarchy is composed of native mobile objects, which contain browser (web) views, which in turn contain web objects. Corresponding to this, the test object hierarchy (in LeanFT) is composed of mobile test objects, which contain test objects of type WebView, which in turn contain web test objects.
Spying web objects in hybrid apps with the Object Identification Center, results in a mixed hierarchy having the structure of test objects as described above. For instance:
The application presented on the right side of the screenshot below is a hybrid application. If we spy the Submit button in the application, the Object Identification Center presents the spied object as following:
As we can see, the Submit button is identified as a web test object. The WebView test object highlighted in the screenshot, corresponds to a browser (Web) view in the application which contains this button. The WebView test object itself is contained in mobile test objects, representing the native objects in the application which contain the web view.
“Translating” this hierarchy to code (using the “Generate code to clipboard” button), to be used in the script for accessing this button, will result in code similar to the following:
device.describe(Application.class, new ApplicationDescription.Builder() .identifier("com.sample.UICatalog") .packaged(true).build()) .describe(WebView.class, new WebViewDescription.Builder() .className("WebView") .resourceId("webview1") .mobileCenterIndex(0).build()) .describe(Page.class, new PageDescription()) .describe(Button.class, new ButtonDescription.Builder() .buttonType("button") .tagName("INPUT") .name("Submit").build());
The Application and WebView test objects, are part of LeanFT SDK mobile package, while the “Button” test object, belongs to the LeanFT SDK web package.
Of course, you can also model hybrid apps objects into Application Models, and use them as explained above.
Testing web applications, across desktop and mobile browsers
LeanFT enables you to automate web applications and execute them against both desktop and mobile browsers. Moreover, as LeanFT is a cross browser solution that supports automating application that have a responsive design, you can automate flows of your web applications once, and execute the same scripts against different browsers, whether they are desktop or mobile browsers. You can even run a number of instances of the same web test in parallel against different desktop and mobile browsers and get a unified LeanFT run report in which you will see the results of the execution for each browser separately (read more about parallel test execution in the LeanFT Help Center).
LeanFT supports the native device browser. In iOS devices, you can automate you web apps in the device’s Safari browser, while in Android devices, you can automate them in the device’s Chrome browser.
The beauty of automating web applications with LeanFT on mobile devices, is that LeanFT treats this applications as a pure web application. This means that if you will spy you web application in the device’s VNC window, the Object Identification Center will show the application objects hierarchy, as a web hierarchy. It also means that in your script, you can use the same LeanFT web API that you use to automate web applications in desktop browsers, also when running them against device browsers. In other words, you can script once, and execute against all browsers.
To spy your web applications on a device browser you should first open the VNC window of the device using the “Mobile Center” dialog as described above, while selecting in the “Application” drop-down “Device Home” as the application:
When you click the “Launch” button, the device is presented in the VNC window in its home screen. Now you should simply tap the icon of the device browser (in the VNC window) to open it, and spy it as usual.
The only point left for us in order to complete the picture here, is explaining how you can launch device browsers in your script:
As a reminder, LeanFT SDK enables launching desktop browsers using the BrowserFactory class. For instance, to launch Chrome in your desktop machine, you should write:
Browser browser = BrowserFactory.launch(BrowserType.CHROME);
Then you can use the browser variable, to manipulate your browser and application objects.
To launch device browsers, you should do the same, with a slight difference:
First, lock the desired device as explained above, e.g.:
Device iOsDevice = MobileLab.lockDeviceById("a1a0efea0d534d744db83af64e4938574180cba7");
Then, use the BrowserFactory’s launch method to launch your browser by specifying the browser type (as above) and provide it with a second argument which is the Device object of your device. For instance, if you would like to launch the Safari browser (on an iOS device), you should use the following code:
Browser browser = BrowserFactory.launch(BrowserType.Safari, iOsDevice);
At this point, you can continue using the browser variable in your script, exactly as you do when automating desktop browsers.
Execute your mobile tests and analyze the results
Up until now we have focused mainly on designing mobile tests with LeanFT. Now let’s talk about running them.
Running LeanFT mobile tests is exactly the same as running any other LeanFT test. You can run them from your IDE, or from your lab machines (during your continuous integration and testing cycle).
When running LeanFT mobile tests, LeanFT automatically generates an html run report (as for any LeanFT test). The run report provides a detailed view for the execution, including all the steps, results, images and more. For instance, if we’ll run the full code sample provided earlier in this blog, the report generated by LeanFT (can be opened by clicking the report file in the file system, or directly from the “LeanFT” menu in the IDE), will look like this:
As you can see, all the steps executed by LeanFT are reported, including the performed operation, operation data, a snapshot (if LeanFT was configured to take snapshots) and more. In case of execution failures, the report presents the failure’s root cause (e.g.: trying to run a test on a device which was locked to another user). In addition, selecting the “Device.Lock” step in the report tree, displays the exact details of the device used during the run. For instance:
As you can see, the report presents the parameters defined when requesting the device (e.g.: its ID) and the actual device parameters, which are being fetched from the device dynamically during execution (e.g.: model, manufacturer, etc.).
As the report is a pure html report, you can easily integrate it with your systems, e.g.: with your CI tool.
So, we have reviewed the basic process of designing and executing mobile tests with LeanFT through its integration with Mobile Center.
An important note is that there is much more in this integration than could be described in this blog. Now that you understand the basics of mobile testing with LeanFT, feel free to read more about it, in LeanFT’s and Mobile Center’s Help Centers.
About UFT Pro (LeanFT)
UFT Pro (LeanFT) is a powerful test automation solution that was built specifically for continuous testing and continuous integration. It enables advanced automation engineers and dev-testers in agile teams to leverage the standard development IDEs for test automation.
You can find more information about LeanFT, in the LeanFT Help Center.