2010 bb dev con

39
Automated Tes,ng for Mobile Applica,ons An experimental technique Eing Ong, Intuit Inc. Louis daRosa, Intuit Inc.

Upload: eing-ong

Post on 08-Jul-2015

273 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: 2010 bb dev con

Automated  Tes,ng  for  Mobile  Applica,ons  An  experimental  technique  

Eing  Ong,  Intuit  Inc.  

Louis  daRosa,  Intuit  Inc.  

Page 2: 2010 bb dev con

Session  outline  

2

•   Introduc,on  •   Simulator  basics  

•   Simulator  library    

•   Building  your  mobile  app  library  

•   Wri,ng  reusable  test  cases  

•   Mobile  test  automa,on  framework    

•   Advantages  and  limita,ons  

•   Q  &  A  

Page 3: 2010 bb dev con

Introduc,on  

3

What  are  we  solving  for  ?  

•   Various  BB  OS  and  devices  •   End-­‐to-­‐end  mobile  tests  

•   Low  cost  solu,on  •   Mul,ple  mobile  plaLorms  

Page 4: 2010 bb dev con

Simulator  Basics  

4

BlackBerry®  JDE  tool  kit  

• Mobile  data  service  (MDS)  

•  Simulators  suite  

•  App  installa,on  •  Image  capture  

Page 5: 2010 bb dev con

Simulator  Basics  

5

BlackBerry®  simulator  •  Star<ng  simulator              fledge.exe                      /app=jvm.dll                                  /session=<model>                    /app-­‐param=                            JvmAlxConfigFile:<model>.xml                      /handheld=<model>  

•  Communica<ng  with  simulator              fledgecontroller.exe                      /session=<model>  

Page 6: 2010 bb dev con

Simulator  Basics  

Ac<ons   Steps  

Start  9630  Tour  simulator  

fledge.exe  /app=jvm.dll            /session=9630  /handheld=9630          /app-­‐param=JvmAlxConfigFile:9630.xml    

Install  applica,on  

1.  Copy  app.jar,  app.jad,  app.cod  to  Javaloader  directory  

2.  JavaLoader.exe    –u  load  app.jad  

3.  Delete  app.jar,  app.jad,  app.cod  Save  screenshot  as  test.png  in  $TEST_OUTPUT  

1.  JavaLoader.exe    –u  screenshot  test.png  

2.  mv  test.png  $TEST_OUTPUT  

6

Page 7: 2010 bb dev con

Simulator  Basics  

Ac<ons   Steps   bblib.py  

Start  9630  Tour  simulator  

fledge.exe  /app=jvm.dll            /session=9630  /handheld=9630          /app-­‐param=JvmAlxConfigFile:9630.xml    

fledgeStart()  

Install  applica,on  

1.  Copy  app.jar,  app.jad,  app.cod  to  Javaloader  directory  

2.  JavaLoader.exe    –u  load  app.jad  

3.  Delete  app.jar,  app.jad,  app.cod  

install()  

Save  screenshot  as  test.png  in  $TEST_OUTPUT  

1.  JavaLoader.exe    –u  screenshot  test.png  

2.  mv  test.png  $TEST_OUTPUT  

getScreenShot(‘test’)  

7

Page 8: 2010 bb dev con

Simulator  commands  

8

Ac<on   Steps  

Enter  'Hello  World'  

StringInjec,on(Hello)  KeyPress(SPACE)  

KeyRelease(SPACE)  

StringInjec,on(World)  Backspace  2  ,mes  

KeyPress(BACKSPACE)  KeyRelease(BACKSPACE)  

KeyPress(BACKSPACE)  

KeyRelease(BACKSPACE)  Thumbwheel  up  twice  

ThumbWheelRoll(-­‐1)  ThumbWheelRoll(-­‐1)  

Page 9: 2010 bb dev con

Simulator  commands  

Ac<on   Steps   bblib.py  

Enter  'Hello  World'  

StringInjec,on(Hello)  KeyPress(SPACE)  

KeyRelease(SPACE)  

StringInjec,on(World)  

enter(‘Hello  World')  

Backspace  2  ,mes  

KeyPress(BACKSPACE)  KeyRelease(BACKSPACE)  

KeyPress(BACKSPACE)  

KeyRelease(BACKSPACE)  

backspaces(2)  

Thumbwheel  up  twice  

ThumbWheelRoll(-­‐1)  ThumbWheelRoll(-­‐1)  

thumbwheel  ('up',                                                                2)  

9

Page 10: 2010 bb dev con

Simulator  commands  

Ac<on   Steps   bblib.py  

Touch  screen  at  (10,  100)  

TouchScreenPress(10,  100,  0)  TouchScreenClick()  TouchScreenUnclick()  TouchScreenUnpress(0)  

touch(10,  100)  

10

Page 11: 2010 bb dev con

bblib.py  

11

Setup  •  fledgeStart()  •  javaloaderStart()  •  mdsStart()  

Basic  key  events  •  backspaces(count)  •  enter()  •  enter(string)  •  menu()    

•  escape()    •  pause(seconds)  

Page 12: 2010 bb dev con

bblib.py  

12

Naviga<on  •  thumbwheel('up',  count)  

•  thumbwheel(‘down',  count)  

•  trackball('up’,  count)  •  trackball(‘down’,  count)  •  trackball(‘lek’,  count)  •  trackball(‘right’,  count)  •  touch(x,y)  

Page 13: 2010 bb dev con

Case  study  –  Address  Book  Demo  

13

•  Devices  –  Pearl  –  Storm  

•  Simulator  library  

•  Address  book  –  Add  contact  –  Find  contact  –  Delete  contact  

•  Automated  tests  

Page 14: 2010 bb dev con

Test  Automa,on  Overview  

1.   Define  applica<on  interface  This  interface  is  device-­‐agnos,c.  

2.   Implement  the  interface  Implement  interface  in  BlackBerry®    

U,lize  Python™  mobile  libraries  e.g.  bblib.py.  

3.   Write  your  tests  Tests  are  device  independent  and  reusable.  

4.   Run  

14

Page 15: 2010 bb dev con

Step  1  :  Define  applica,on  interface  

class  AppInterface:  

       """Applica,on  Interface"""  

       def    launch(self):  

                 """Launch  app"""  

       def  add(self,  contact):  

               """Add  a  contact"""  

       def  find(self,  contact):  

               """Find  contact"""  

       def  delete(self):  

               """Delete  current  contact"""  

 15

Page 16: 2010 bb dev con

Test  Automa,on  Overview  

1.   Define  applica<on  interface  This  interface  is  device-­‐agnos,c.  

2.   Implement  the  interface  Implement  interface  in  BlackBerry®    

U,lize  Python™  mobile  libraries  e.g.  bblib.py.  

3.   Write  your  tests  Tests  are  device  independent  and  reusable.  

4.   Run  

16

Page 17: 2010 bb dev con

Step  2  (Storm):  Implement  the  interface  

17  

def  StormImpl(appbase.AppInterface):  

def  add(self,  contact):    

touch(100,  50)  

enter(contact.getFirstname()  

                               thumbwheel('down',  1)  

                               enter(contact.getLastname())  

                               #  save  

                               menu()  

touch(50,  300)  

Page 18: 2010 bb dev con

Step  2  (Storm):  Implement  the  interface  

18  

def  StormImpl(appbase.AppInterface):  

def  add(self,  contact):    

touch(100,  50)  

enter(contact.getFirstname()  

                               thumbwheel('down',  1)  

                               enter(contact.getLastname())  

                               #  save  

                               menu()  

touch(50,  300)  

Page 19: 2010 bb dev con

Step  2  (Storm):  Implement  the  interface  

19  

def  StormImpl(appbase.AppInterface):  

def  add(self,  contact):    

touch(100,  50)  

enter(contact.getFirstname()  

                               thumbwheel('down',  1)  

                               enter(contact.getLastname())  

                               #  save  

                               menu()  

touch(50,  300)  

Page 20: 2010 bb dev con

Step  2  (Pearl):  Implement  the  interface  

20  

def  PearlImpl(appbase.AppInterface):  

def  add(self,  contact):    

enter()  

enter(contact.getFirstname()  

                               thumbwheel('down',  1)  

                               enter(contact.getLastname())  

                               #  save  

                               menu()  

enter()

Page 21: 2010 bb dev con

Step  2  (Pearl):  Implement  the  interface  

21  

def  PearlImpl(appbase.AppInterface):  

def  add(self,  contact):    

enter()  

enter(contact.getFirstname()  

                               thumbwheel('down',  1)  

                               enter(contact.getLastname())  

                               #  save  

                               menu()  

enter()

Page 22: 2010 bb dev con

Step  2  (Pearl):  Implement  the  interface  

22  

def  PearlImpl(appbase.AppInterface):  

def  add(self,  contact):    

enter()  

enter(contact.getFirstname()  

                               thumbwheel('down',  1)  

                               enter(contact.getLastname())  

                               #  save  

                               menu()  

enter()

Page 23: 2010 bb dev con

Step  2  Recap:  Implement  the  interface  

23  

def  StormImpl(appbase.AppInterface):  

def  add(self,  contact):    

touch(100,  50)  

enter(contact.getFirstname()  

                               thumbwheel('down',  1)  

                               enter(contact.getLastname())  

                               #  save  

                               menu()  

touch(50,  300)  

     def  PearlImpl(appbase.AppInterface):  

def  add(self,  contact):    

enter()  

enter(contact.getFirstname()  

                               thumbwheel('down',  1)  

                               enter(contact.getLastname())  

                               #  save  

                               menu()  

enter()  

 

Page 24: 2010 bb dev con

Test  Automa,on  Overview  

1.   Define  applica<on  interface  This  interface  is  device-­‐agnos,c.  

2.   Implement  the  interface  Implement  interface  in  BlackBerry®    

U,lize  Python™  mobile  libraries  e.g.  bblib.py.  

3.   Write  your  tests  Tests  are  device  independent  and  reusable.  

4.   Run  

24

Page 25: 2010 bb dev con

Step  3  :  Wri,ng  tests  

class  AddContactTest(uniqest.TestCase):    device  =  testenv.getDeviceClass()    

def  addContactWithOnlyFirstnameTest(self):  

       self.contact.setFirstname(firstname)  

       self.device.add(self.contact)  

 

def  addContactWithOnlyLastnameTest(self):  

       self.contact.setLastname(firstname)  

       self.device.add(self.contact)  

       

25

Page 26: 2010 bb dev con

Step  3  :  Run,me  device  binding  

def getDeviceClass(self): """ Returns the device to test """ mobileDevice = self.getMobileDevice() if mobileDevice == 'pearl': import pearl deviceClass = pearl.PearlImpl() elif mobileDevice == 'storm': import storm deviceClass = storm.StormImpl() else: import bb deviceClass = bb.BlackBerry() return deviceClass

26

Page 27: 2010 bb dev con

More  device-­‐independent  tests  

Addi<onal  tests  are  easy  to  write    

def  addContactWithEmailTest(self):  

def  addContactWithAddressesTest(self):  

def  addContactWithAllDetailsTest(self):  

def  addContactWithLongDetailsTest(self):  

def  addContactAddressWithStateZip(self):  

def  addContactAddressWithCityStateZip(self):  

def  addContactAddressWithNoDataNega,veTest(self):  

 

 

27

Page 28: 2010 bb dev con

Step  4  :  Run  

•  Basic  run  command  –  python  <test.py>  

 

•  Python™  test  frameworks  –  uniqest  –  PyUnit    –  python-­‐nose  

 

 

28

Page 29: 2010 bb dev con

Test  Verifica,on  

•  Server  hosted  apps  –  API  asser,ons  –  Database  asser,ons  

•  Image  asser,ons    self.assertTrue(imagelib.compare(self.device,  testname,  '100%x90%‘))    

imagelib.py  :  

def  compare(device,  imageName,  crop=None,  tolerance=500)  

29

Page 30: 2010 bb dev con

Logging  

•  Ini,aliza,on  self.log  =  self.device.initLogger(self._testMethodName,                                                                                                                      self.__class__.__name__)  

•  Usage  self.log.info('Star,ng  test:  '  +  self._testMethodName)  self.log.debug(self.contact)  self.log.error(‘Missing  image  to  compare’)  

•  Logs  AddressTest.log  :    

2010-­‐06-­‐10  15:19:46,773  -­‐  testCreateAddressMethod  -­‐  INFO  -­‐  

 [Address1]  200  Villa  St  Mountain  View  CA  94040  BUSINESS  ADDRESS  

30

Page 31: 2010 bb dev con

Login  example  on  BlackBerry®  Pearl  

31

enter(username)  scroll(‘down’)  enter(password)  enter()  

def  enter(str)  def  scroll(ac<on)  def  enter()  

login(‘user100’,’helloworld’)  

pearlapp.py

def  login(username,  passwd)  

bblib.py

Interface

Test (logintest.py)

Page 32: 2010 bb dev con

Login  example  on  BlackBerry®  Storm      

32

touch(100,100)  enter(username)  touch(100,200)  enter(password)  touch(150,  300)  

def  enter()  def  touch(x,y)  

login(‘user100’,’helloworld’)  

stormapp.py

def  login(username,  passwd)  

bblib.py

Interface

Test (logintest.py)

Page 33: 2010 bb dev con

Mobile  Tes,ng  Framework  

33

BB    app  library  

BB  device  library  

Mobile  app  library  

Device  library  

Device  Independent  Tests  

Python™ Test Framework

Simulator libraries

Mobile  Applica<on  Interface  

Runtime device binding

Page 34: 2010 bb dev con

Advantages  

•  Zero  cost  to  use    •  No  device  sharing/scheduling  •  Bigger  device  pool  •  Reduce  manual  tes,ng  ,me  

•  Run  on  developers  machines  

•  Debugging  capabili,es  

34

Page 35: 2010 bb dev con

Limita,ons  

•  Requires  ethernet  or  internet  connec,vity  •  Does  not  simulate  network  performance  

•  Does  not  support  hardware  controls  tes,ng  •  Dependent  on  simulator  reliability  

•  Limited  peer-­‐to-­‐peer  applica,ons  tes,ng  

35

Page 36: 2010 bb dev con

Resources  

36

BlackBerry  ®  JDE  Downloads  hqp://na.blackberry.com/eng/developers/javaappdev/javadevenv.jsp  

Documenta<on  Fledge  controller  hqp://docs.blackberry.com/en/developers/deliverables/15476/Test_B  BSmrtphnSmltr_events_using_script_607587_11.jsp  

BlackBerry  ®  Simulator  Tes,ng  hqp://docs.blackberry.com/en/developers/deliverables/6338/Tes,ng_apps_using_the  _BBSmrtphnSmltr_607559_11.jsp  

Python  ™  hqp://docs.python.org/    BlackBerry  ® Developers  Forum  hqp://supporLorums.blackberry.com/  

Page 37: 2010 bb dev con

Acknowledgments  

37

•  Desiree  Gosby,  Mobile  Architect  

•  Paul  Hau,  QA  Manager  

•  Jaron  Jones,  QA  Manager  

•  Jason  Pugh,  Architect  (definitely  not  least)  

Page 38: 2010 bb dev con

Q  &  A  

38

Page 39: 2010 bb dev con

Thanks  and  enjoy  the  rest  of  DevCon  2010!  

For  more  details  on  the  presenta,on,  contact  [email protected]  

39