Getting started with Worklight Mobile Testing
Tissandier 270002HRW9 Comment (1) Visits (11616)
Back in May, during the Impact conference, we discussed with Jim Zhang and Tom Young about the new Mobile Testing capabilities in Worklight 6.0 in this blog entry Mobile Testing Feature in Worklight 6 . Now that Worklight 6.0 is out, I wanted to come back on this and explain the basics of mobile testing in Worklight 6 and how to start using it.
You may wonder what is this new mobile testing capability in Worklight 6.0. This is not about doing unit test of your code or anything similar, this is the ability to do functional testing of a Worklight mobile application. As you run your Worklight application (native or hybrid) you can record a human readable test script that you will use later to play-back the test and ensure your application is running as expected. The script is recording events that are happening on the user interface elements of your application such as the fact that you pressed a button or that you entered text in an entry field. This makes the script easy to read and resilient to changes in the user interface. Inside this script you add verification points to validate that your application is behaving as expected.
How to get started
First thing is probably to install this mobile testing capability in Worklight Studio. If you have installed the Worklight developer edition in the past, you are familiar with installing Worklight Studio from the Eclipse Market place. This is also the place where you can find the IBM Mobile Test Workbench for Worklight (the official name of the mobile testing feature in Worklight)
You should install them both on a Juno version (4.2.2) of Eclipse and you are almost ready to create and test mobile applications with Worklight 6.0.
The Mobile testing components for Android requires that you run Eclipse with a Java JDK and not a JRE, You can check this in the Window > Preferences > Java > Installed JREs window of Eclipse.
In order to test an Android application, you will also need to install the Android tools or install Xcode if you are on a Mac and willing to test and iOS application. The mobile testing capabilities today support both Worklight iOs and Android applications.
Once all this is installed and you re-launched Eclipse you will see a new perspective in Eclipse for mobile testing called Test Workbench.
Notice also the additional icons in the toolbar of eclipse.The first one opens the Mobile Applications view. This view lists all the applications that are available for testing.
All this is of course empty at the beginning, but before testing anything we will create a simple Worklight application.
Creating a simple Worklight app for testing
Since this is not the purpose of this article to show you how to create a Worklight application, we will try to use a fast path for building a simple app and we will see some nice Worklight 6 features along the way.
We start with File > New > Worklight Project, notice that as you create a new Worklight project, you are also proposed to create a new IBM Mobile Test Workbench Project.
I am choosing to add JQuery Mobile 1.3.1 to my application as shown in the picture above and I will also create the corresponding test project.
We will not use the test project right now; instead, we will build the user interface of a very simple application. Opening the main HTML file of my hybrid application (the file located at apps
In the Mobile Navigation view, I click on the + icon to add a new page in my application. This opens a dialog box that is proposing me to create a new view based on a set of predefined patterns. This nice Worklight 6 new feature will prevent me from explaining all the steps required to create the HTML for the application.
At this point I choose the Registration pattern that is proposed. The development of my application is finished. The application is not doing anything interesting but this is enough for the purpose of this article.
I can now add a Worklight android environment or an iphone or ipad environment using File > New > Worklight Environment and use Run As / Build All and Deploy to create the final native project for my hybrid application.
On the Android side Worklight Studio creates for me the native Android project accessible from Eclipse and I can build and test the application from there. On iOS, Worklight Studio will create for me the Xcode project. My application is then ready and I can now start using the mobile testing capabilities.
Installing the mobile client for Android
Starting to test the application on Android is now very simple, but before testing you need to install the mobile client application on the device. This mobile application will allow to record tests, playback tests and view reports on the device. For Android we install the mobile application on a real device, for iOS as I write those lines the mobile client is only available for testing in the iphone/ipad simulator, so we will install the mobile client and do our testing in the simulator.
Let’s see how to do this on Android. Start by flashing the QR code that is available in the Mobile Devices view in the eclipse workbench, this will open a URL on your device with instructions on how to install the application on the device.
After you clicked the proposed link and followed the installation instructions, the app called IBM Rational Test Workbench is available on your device. You have noted that sometime the name Rational Test Workbench is used and sometime you see Mobile Test Workbench for Worklight. The mobile testing capabilities of Worklight are also part of the Rational Test Workbench (RTW) product. The testing capabilities are the same in both products but within Worklight you are only able to test hybrid and native applications created with Worklight and in RTW, you can test any mobile apps.
When you launch the mobile client, you first need to configure the URI of the server so that the application can talk to the test workbench within eclipse.
The URI is the same as the one you used to open the page above but without the /mobile extension. You do not need to change any other settings. You can check that the device is connected by verifying that the network icon at the bottom of the application has no red-cross next to it. If you are correctly connected you can also see the Disconnect menu that appears in the main view of the application.
Installing the mobile client for iOS
The procedure to install the mobile client on the iOS simulator is similar. You start by pointing Safari on your Mac to http
One the zip is downloaded, run the following command to install the mobile client in the iOS simulator using the script located in the buildscript directory of the archive:
This will also open the simulator with the mobile client ready to be used to start testing apps. In a similar way as for Android the first thing to do is the configuration of the server URI through the Configure Workbench button:
Registering a test
You can now start testing the application. First go to Worklight Studio, right-click the environment (the android, ipad or iphone folder in the Worklight project) and choose Run As-> Test with IBM Mobile Test Workbench… Doing so will add the application in the Mobile Applications view in the eclipse workbench, but the application will also appear in the list of available applications in the mobile client. If you click the Manage Applications menu on the phone, the application is now listed and available to start a test.
When you perform this step for iOS, the application is recompiled with a slightly modified version of the Xcode project and thus it may take some time to complete. For Android an instrumentation of the application is also done when the application APK is added in the list of application. In both cases, you cannot start testing the application before the application has the status ‘Available’ in the Mobile Applications view. There are several other ways to add an application in the test workbench but this is the most convenient one.
Registering a test is as simple as running the application. From the mobile client you select the application in the list of managed client and you choose the Record button. On Android, this will ask you to install the application on the device and then launches the app. Here is how it looks on Android:
And on iOS:
You can then run the application. There are not a lot of things we can do with our very simple application, but we can enter the user name and password and click the Register button.
As soon as you do this and leave the application, the test recording is sent to the eclipse workbench, you will notice the message indicating that a new recording is available as shown below.
From there you can follow the wizard that will guide you to the creation of the test from the recording. You will be asked to store the resulting test in a test project, if you remember we have created a test project at the beginning of the exercise. In this example you named the test SimpleTest.
The test in the workbench will be automatically opened in a Test editor that will allow you not only to see the various steps of the recording but also to edit the test to add some additional verification points.
Here is how the test editor looks like, note the various steps that I have recorded, for example entering text in the various text fields. The scripts is listing the various user interface elements I interacted with and identified them based on their location in the application, depending on the layout and configuration of the view, the identification can be done by a unique property of the element (for example there is a single OK button in the page) or for example by a relative position to another object in the page.
Among the various things you can do in the test editor, the most interesting one is probably the ability to add some verification points within the flow of the script, i.e an additional test that will verify the property of a user interface object. This is the main way you can control that the flow of the application is correct.
Now that a test is recorded, you will want to play it back. This is also done from the mobile client application. The available tests appear in the mobile client and you can run them back against the application. Here is the mobile client for iOS showing our SimpleTest.
As you run the test, the application runs automatically and the various steps are executed. All this ends up with a report that you can read on the mobile client or in the eclipse workbench. This report will tell you if the test passed or not and provide you again all the steps that have been executed and their status. The report looks like this on the iOS client:
We have been able to successfully register a test and play it back for our Worklight application, I hope you now understand the basics of using the mobile testing capabilities of Worklight 6. To learn more about the Mobile Test Workbench you want to read the Worklight information center about this feature at: http
You will for example learn how to share applications for testing using the Worklight Application Center.