The document discusses automated testing of mobile applications across multiple platforms. It describes how traditional manual testing can take hundreds of hours for each release but UI automation can test full apps in minutes and be easily repeated. It also explains that test programs need to be written separately for each mobile platform which is wasteful effort. The document then introduces a programming language translator that allows writing tests once that can run on any platform by translating the code into the native language of each platform. This avoids wasted effort of writing tests multiple times.
Automated testing of mobile applications on multiple platforms
1. Copyright (c) 2014 Job and Esther Technologies, Inc. All Rights reserved.
1
Automated testing of mobile
applications on multiple
platforms
Markku Kero / Job and Esther Technologies
June 2014 / Softech.ph
2. Copyright (c) 2014 Job and Esther Technologies, Inc. All Rights reserved.
2
What is the
meaning of “Mobile
UI Automation”?
3. Copyright (c) 2014 Job and Esther Technologies, Inc. All Rights reserved.
3
Traditional QA procedure
… #100 … #1000 … hours and hours of testing … for each release …
4. Copyright (c) 2014 Job and Esther Technologies, Inc. All Rights reserved.
4
UI Automation
5. Copyright (c) 2014 Job and Esther Technologies, Inc. All Rights reserved.
5
import com.android.uiautomator.core.*;
import com.android.uiautomator.testrunner.*;
public class MyTestCase extends UiAutomatorTestCase
{
public void testnumberone() throws UiObjectNotFoundException,
android.os.RemoteException
{
getUiDevice().wakeUp();
getUiDevice().pressEnter();
UiObject textfield = new UiObject(new UiSelector().className("android.widget.EditText"));
textfield.clearTextField();
textfield.setText("This is really cool");
UiObject button = new UiObject(new UiSelector().className("android.widget.Button"));
button.click();
UiObject textview = new UiObject(new UiSelector().className("android.widget.TextView").index(1));
assertEquals("Text is incorrect", "This is really cool", textview.getText());
}
}
$ <apache-ant-dir>/bin/ant build
$ <adt-dir>/sdk/platform-tools adb push bin/MyTestProgram.jar /data/local/tmp
$ <adt-dir>/sdk/platform-tools/adb shell uiautomator runtest MyTestProgram.jar
-c MyTestCase
1. Write the test program
2. Run the tests
3. Read the report
6. Copyright (c) 2014 Job and Esther Technologies, Inc. All Rights reserved.
6
With automation, full test of an
app will no longer take hours
but minutes
The tests are easily repeated
for every release
7. Copyright (c) 2014 Job and Esther Technologies, Inc. All Rights reserved.
7
Perfect, right?
8. Copyright (c) 2014 Job and Esther Technologies, Inc. All Rights reserved.
.. FOR EACH PLATFORM
BUT TEST PROGRAMS NEED TO BE WRITTEN ..
9. Copyright (c) 2014 Job and Esther Technologies, Inc. All Rights reserved.
MANY MOBILE PLATFORMS HAVE BUILT-IN CAPABILITIES
FOR USER INTERFACE AUTOMATION
UI Automation
JavaScript
UIAutomator
Java
10. Copyright (c) 2014 Job and Esther Technologies, Inc. All Rights reserved.
11. Copyright (c) 2014 Job and Esther Technologies, Inc. All Rights reserved.
12. Copyright (c) 2014 Job and Esther Technologies, Inc. All Rights reserved.
public class Main : LayerWidget, EventReceiver
{
TextInputWidget input;
LabelWidget label;
public void initialize() {
base.initialize();
var box = BoxWidget.vertical().set_spacing(px("1mm"))
.set_margin(px("1mm"));
box.add(input = TextInputWidget.instance());
input.set_widget_id("input");
box.add(label = LabelWidget.for_string("(enter text)")
.set_font(Font.instance("7mm")));
box.add(ButtonWidget.for_string("Click me").set_event("clickme")
.set_widget_id("clickme"));
add(CanvasWidget.for_color(Color.instance("#AAAAAA")));
add(box);
set_draw_color(Color.instance("black"));
}
public void cleanup() {
base.cleanup();
input = null;
label = null;
}
public void on_event(Object o) {
label.set_text(input.get_text());
}
}
13. Copyright (c) 2014 Job and Esther Technologies, Inc. All Rights reserved.
// standard iOS UI Automation framework initialization
var target = UIATarget.localTarget();
var app = target.frontMostApp();
var window = app.mainWindow();
// Set the contents of the text input field
// to string "Something"
window.textFields()["input"].setValue("Something");
// Click the "Click me" button
window.buttons()["clickme"].tap();
UI Automation test script for iOS
14. Copyright (c) 2014 Job and Esther Technologies, Inc. All Rights reserved.
15. Copyright (c) 2014 Job and Esther Technologies, Inc. All Rights reserved.
16. Copyright (c) 2014 Job and Esther Technologies, Inc. All Rights reserved.
import com.android.uiautomator.core.*;
import com.android.uiautomator.testrunner.*;
public class MyTestCase extends UiAutomatorTestCase
{
public void testSample() throws
UiObjectNotFoundException,
android.os.RemoteException
{
UiObject textfield = new UiObject(new UiSelector()
.description("input"));
textfield.clearTextField();
textfield.setText("Something");
UiObject button = new UiObject(new UiSelector()
.description("clickme"));
button.click();
}
}
UIAutomator test script for Android
17. Copyright (c) 2014 Job and Esther Technologies, Inc. All Rights reserved.
public class MyTestCase extends UiAutomatorTestCase
{
public void testSample() throws
UiObjectNotFoundException,
android.os.RemoteException
{
UiObject textfield = new UiObject(new UiSelector()
.description("input"));
textfield.clearTextField();
textfield.setText("Something");
UiObject button = new UiObject(new UiSelector()
.description("clickme"));
button.click();
}
}
var target = UIATarget.localTarget();
var app = target.frontMostApp();
var window = app.mainWindow();
window.textFields()["input"].setValue("Something");
window.buttons()["clickme"].tap();
SAME PROGRAM WRITTEN TWICE ..
.. SEEMS LIKE A WASTE OF EFFORT
18. Copyright (c) 2014 Job and Esther Technologies, Inc. All Rights reserved.
BUT TWICE WOULD
NOT BE ENOUGH
19. Copyright (c) 2014 Job and Esther Technologies, Inc. All Rights reserved.
19
Programming Language
Translator
20. Copyright (c) 2014 Job and Esther Technologies, Inc. All Rights reserved.
class MyTestCase : UIAutomatorTestCase
{
public void execute() {
get_text_field("input").set_text("Something");
get_button("clickme").click();
}
}
package sample;
public class MyTestCase extends com.eqela.libuiautomator.UIAutomatorTestCase
{
@Override public void execute() {
((com.eqela.libuiautomator.UIAutomatorTestCase)this).get_text_field(eq.api.St
ringStatic.eq_api_StringStatic_for_strptr("input")).set_text(eq.api.StringSta
tic.eq_api_StringStatic_for_strptr("Something"));
((com.eqela.libuiautomator.UIAutomatorTestCase)this).get_button(eq.api.String
Static.eq_api_StringStatic_for_strptr("clickme")).click();
}
}
sample.MyTestCase=function(){
com.eqela.libuiautomator.UIAutomatorTestCase.call(this);
};
// ...
P.execute=function(){
com.eqela.libuiautomator.UIAutomatorTestCase.prototype.get_text_field.call(t
his,eq.api.StringStatic.for_strptr("input")).set_text(eq.api.StringStatic.fo
r_strptr("Something"));
com.eqela.libuiautomator.UIAutomatorTestCase.prototype.get_button.call(this,
eq.api.StringStatic.for_strptr("clickme")).click();
}
21. Copyright (c) 2014 Job and Esther Technologies, Inc. All Rights reserved.
public class UIAutomatorTextFieldAndroid : UIAutomatorTextField
{
public static UIAutomatorTextFieldAndroid for_id(String id) {
return(new UIAutomatorTextFieldAndroid().initialize(id));
}
ptr field;
public UIAutomatorTextFieldAndroid initialize(String id) {
ptr ff;
var ip = id.to_strptr();
embed {{{
ff = new UiObject(new UiSelector().description(ip));
}}}
if(ff == null) {
return(null);
}
field = ff;
return(this);
}
public void set_text(String text) {
var ff = field;
var tp = text.to_strptr();
embed {{{
ff.clearTextField();
ff.setText(tp);
}}}
}
}
22. Copyright (c) 2014 Job and Esther Technologies, Inc. All Rights reserved.
public class UIAutomatorTextFieldIOS : UIAutomatorTextField
{
public static UIAutomatorTextFieldIOS for_id(String id) {
return(new UIAutomatorTextFieldIOS().initialize(id));
}
ptr field;
public UIAutomatorTextFieldIOS initialize(String id) {
ptr ff;
var ip = id.to_strptr();
embed {{{
ff = window.textfields()[ip];
}}}
if(ff == null) {
return(null);
}
field = ff;
return(this);
}
public void set_text(String text) {
var ff = field;
var tp = text.to_strptr();
embed {{{
ff.setValue(tp);
}}}
}
}
23. Copyright (c) 2014 Job and Esther Technologies, Inc. All Rights reserved.
public class MyTestCase extends UiAutomatorTestCase
{
public void testSample() throws
UiObjectNotFoundException,
android.os.RemoteException
{
UiObject textfield = new UiObject(new UiSelector()
.description("input"));
textfield.clearTextField();
textfield.setText("Something");
UiObject button = new UiObject(new UiSelector()
.description("clickme"));
button.click();
}
}
var target = UIATarget.localTarget();
var app = target.frontMostApp();
var window = app.mainWindow();
window.textFields()["input"].setValue("Something");
window.buttons()["clickme"].tap();
NO WASTED EFFORT. WRITE THE SCRIPT ONLY ONCE
class MyTestCase : UIAutomatorTestCase
{
public void execute() {
get_text_field("input").set_text("Something");
get_button("clickme").click();
}
}
24. Copyright (c) 2014 Job and Esther Technologies, Inc. All Rights reserved.
24
Ask for more information
markku.kero@jobandesther.com
www.jobandesther.com
www.eqela.com