24
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

Automated testing of mobile applications on multiple platforms

Embed Size (px)

DESCRIPTION

What is the meaning of "Mobile UI Automation"? How does it help in making quality assurance more effective? How is automation conducted in practice, and what are the challenges? The source code conversion approach of Eqela can also be used to address the challenges of mobile UI automation. (Presentation slides as presented in the Softech.ph conference)

Citation preview

Page 1: Automated testing of mobile applications on multiple platforms

Copyright (c) 2014 Job and Esther Technologies, Inc. All Rights reserved.

1

Automated testing of mobileapplications on multiple

platforms

Markku Kero / Job and Esther Technologies

June 2014 / Softech.ph

Page 2: Automated testing of mobile applications on multiple platforms

Copyright (c) 2014 Job and Esther Technologies, Inc. All Rights reserved.

2

What is the meaning of “Mobile

UI Automation”?

Page 3: Automated testing of mobile applications on multiple platforms

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 …

Page 4: Automated testing of mobile applications on multiple platforms

Copyright (c) 2014 Job and Esther Technologies, Inc. All Rights reserved.

4

UI Automation

Page 5: Automated testing of mobile applications on multiple platforms

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

Page 6: Automated testing of mobile applications on multiple platforms

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

Page 7: Automated testing of mobile applications on multiple platforms

Copyright (c) 2014 Job and Esther Technologies, Inc. All Rights reserved.

7

Perfect, right?

Page 8: Automated testing of mobile applications on multiple platforms

Copyright (c) 2014 Job and Esther Technologies, Inc. All Rights reserved.

.. FOR EACH PLATFORM

BUT TEST PROGRAMS NEED TO BE WRITTEN ..

Page 9: Automated testing of mobile applications on multiple platforms

Copyright (c) 2014 Job and Esther Technologies, Inc. All Rights reserved.

MANY MOBILE PLATFORMS HAVE BUILT-IN CAPABILITIESFOR USER INTERFACE AUTOMATION

UI Automation

JavaScript

UIAutomator

Java

Page 10: Automated testing of mobile applications on multiple platforms

Copyright (c) 2014 Job and Esther Technologies, Inc. All Rights reserved.

Page 11: Automated testing of mobile applications on multiple platforms

Copyright (c) 2014 Job and Esther Technologies, Inc. All Rights reserved.

Page 12: Automated testing of mobile applications on multiple platforms

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());

}}

Page 13: Automated testing of mobile applications on multiple platforms

Copyright (c) 2014 Job and Esther Technologies, Inc. All Rights reserved.

// standard iOS UI Automation framework initializationvar 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" buttonwindow.buttons()["clickme"].tap();

UI Automation test script for iOS

Page 14: Automated testing of mobile applications on multiple platforms

Copyright (c) 2014 Job and Esther Technologies, Inc. All Rights reserved.

Page 15: Automated testing of mobile applications on multiple platforms

Copyright (c) 2014 Job and Esther Technologies, Inc. All Rights reserved.

Page 16: Automated testing of mobile applications on multiple platforms

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() throwsUiObjectNotFoundException,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

Page 17: Automated testing of mobile applications on multiple platforms

Copyright (c) 2014 Job and Esther Technologies, Inc. All Rights reserved.

public class MyTestCase extends UiAutomatorTestCase{

public void testSample() throwsUiObjectNotFoundException,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

Page 18: Automated testing of mobile applications on multiple platforms

Copyright (c) 2014 Job and Esther Technologies, Inc. All Rights reserved.

BUT TWICE WOULDNOT BE ENOUGH

Page 19: Automated testing of mobile applications on multiple platforms

Copyright (c) 2014 Job and Esther Technologies, Inc. All Rights reserved.

19

Programming LanguageTranslator

Page 20: Automated testing of mobile applications on multiple platforms

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.StringStatic.eq_api_StringStatic_for_strptr("input")).set_text(eq.api.StringStatic.eq_api_StringStatic_for_strptr("Something"));((com.eqela.libuiautomator.UIAutomatorTestCase)this).get_button(eq.api.StringStatic.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(this,eq.api.StringStatic.for_strptr("input")).set_text(eq.api.StringStatic.for_strptr("Something"));com.eqela.libuiautomator.UIAutomatorTestCase.prototype.get_button.call(this,eq.api.StringStatic.for_strptr("clickme")).click();}

Page 21: Automated testing of mobile applications on multiple platforms

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);

}}}}

}

Page 22: Automated testing of mobile applications on multiple platforms

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);}}}

}}

Page 23: Automated testing of mobile applications on multiple platforms

Copyright (c) 2014 Job and Esther Technologies, Inc. All Rights reserved.

public class MyTestCase extends UiAutomatorTestCase{

public void testSample() throwsUiObjectNotFoundException,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();

}}

Page 24: Automated testing of mobile applications on multiple platforms

Copyright (c) 2014 Job and Esther Technologies, Inc. All Rights reserved.

24

Ask for more information

[email protected]

www.jobandesther.com

www.eqela.com