W15
Test Automation
5/1/2013 3:00:00 PM

Test Automation for Packaged
Systems: Yes, You Can!
Presented by:
Chris Bushell
ThoughtWorks

Brought to you by:

340 Corporate Way, Suite 300, Orange Park, FL 32073
888-268-8770 ∙ 904-278-0524 ∙ sqeinfo@sqe.com ∙ www.sqe.com
Chris Bushell
A lead consultant at ThoughtWorks, Chris Bushell has a wide variety of roles including software
developer, architect, test automation specialist, agile coach, and trainer. Chris has more than ten years of
industry experience working in finance, retail, telecoms, and mobile in the U.K., Australia, and the U.S.
Passionate about software development process and technology, he is an advocate of using open source
software for building simple solutions to complex problems. Chris is an active member of the local
software development community wherever he's based. Contact Chris on Twitter @chrisbushelloz, by
email at chris.bushell@thoughtworks.com, or converse with him face-to-face.
Test	
  Automa+on	
  
For	
  Packaged	
  
Systems:
Yes	
  You	
  Can!
Chris	
  Bushell
Lead	
  Consultant,	
  ThoughtWorks
What	
  I	
  do
• Developer/Tech	
  Lead/Architect/
Agile	
  coach
• Custom	
  so8ware	
  development
• Focus	
  on	
  building	
  the	
  right	
  thing
• Focus	
  on	
  high	
  quality
• Test	
  driven
How	
  I	
  do	
  it	
  –	
  TDD/BDD
How	
  I	
  do	
  it	
  –	
  Revision	
  Control
How	
  I	
  do	
  it	
  –	
  Con+nuous	
  
Integra+on
How	
  I	
  do	
  it	
  –	
  Open	
  Source
• Light-­‐weight,	
  powerful
• Extensible
• Excellent	
  community
• Examples:	
  xUnit,	
  Selenium/
WebDriver,	
  RSpec,	
  Concordion,	
  
Cucumber	
  etc.

JUnit
November	
  2011
In	
  the	
  beginning....
The	
  COTS	
  Con!
Highly extensible software
“configured” in powerful
development environments,
comparable in complexity, and
susceptibility to defects as
anything in the custom software
development world
The	
  land	
  that	
  +me	
  forgot
Complete	
  lack	
  of	
  test	
  
automa+on
“Computers	
  are	
  designed	
  to	
  do	
  simple	
  repeKKve	
  
tasks.	
  The	
  second	
  you	
  have	
  humans	
  doing	
  
repeKKve	
  tasks,	
  all	
  the	
  computers	
  get	
  together	
  
late	
  at	
  night	
  and	
  laugh	
  at	
  you”
“Every	
  Kme	
  you	
  do	
  something	
  for	
  the	
  third	
  Kme,	
  
automate	
  it.	
  You’ll	
  be	
  doing	
  it	
  a	
  million	
  Kmes”
-­‐	
  Neal	
  Ford
Surely	
  someone	
  must	
  be	
  doing	
  
this	
  already?
• Commercial	
  tools	
  exist,	
  but	
  tend	
  to	
  be	
  a	
  poor	
  fit	
  for	
  
Agile	
  environments
-­‐ TesKng	
  viewed	
  as	
  a	
  luxury	
  (an	
  add-­‐on)
-­‐ Available	
  to	
  few	
  ($$$$	
  licensing)
-­‐ Discourages	
  collecKve	
  ownership
-­‐ Difficult	
  to	
  use	
  good	
  engineering	
  pracKces
-­‐ Difficult	
  to	
  integrate	
  with	
  ConKnuous	
  IntegraKon	
  
process	
  (lack	
  of	
  scriptability/headless	
  mode)
Lessons	
  learned	
  -­‐	
  what	
  worked	
  
and	
  what	
  didn’t
Oracle	
  Siebel	
  CRM
But	
  first,	
  browser	
  automa+on	
  
basics
• HTML	
  +	
  DOM
• Selectors
-­‐	
  Id,	
  class,	
  xpath
• AutomaKon	
  API
-­‐ e.g.	
  Selenium,	
  WebDriver,	
  Sahi,	
  WaKr	
  etc.
Our	
  biggest	
  problem
• AcKveX
• <object>
• Impervious	
  to	
  
tradiKonal	
  
automaKon	
  
toolset
All	
  is	
  not	
  lost
• Not	
  all	
  parts	
  of	
  the	
  applicaKon	
  used	
  AcKveX
• Some	
  controls	
  were	
  regular	
  HTML	
  (albeit	
  machine	
  
generated)
-­‐ WebDriver
• Perhaps	
  we	
  could	
  use	
  some	
  kind	
  of	
  hybrid	
  approach	
  
to	
  test	
  automaKon?
-­‐ WebDriver	
  +	
  X,	
  Y	
  or	
  Z?
Introducing	
  Sikuli	
  -­‐	
  automa+on	
  
using	
  images
An	
  example	
  using	
  Google
package com.tw.xconf;
import org.sikuli.script.FindFailed;
import org.sikuli.script.Screen;
import org.sikuli.script.Settings;
public class Demo {
	
	
	
	
	
	
	
	
	
	
	
}

public static void main(String[] args) {
	 Screen screen = new Screen();
	
	 try {
	 	 screen.click("images/criteria.png");
	 	 screen.type("ThoughtWorks");
	 	 screen.click("images/search.png");
	 } catch (FindFailed e) {
	 	 e.printStackTrace();
	 }	
}
Drawbacks	
  of	
  Sikuli
• Difficult	
  to	
  manage	
  large	
  numbers	
  of	
  images
• Can	
  be	
  confused	
  when	
  different	
  regions	
  of	
  the	
  screen	
  
look	
  the	
  same
• Tests	
  easily	
  broken	
  by	
  small	
  changes	
  in	
  the	
  UI
• ComparaKvely	
  slow	
  to	
  execute
	
  
The	
  story	
  so	
  far....
• Ability	
  to	
  automate	
  the	
  UI
-­‐ WebDriver	
  for	
  the	
  regular	
  HTML
-­‐ Sikuli	
  for	
  the	
  AcKveX	
  controls
The	
  last	
  hurdle
• How	
  do	
  we	
  extract	
  values	
  from	
  the	
  page	
  so	
  we	
  can	
  
perform	
  asserKons	
  on	
  them?
Tried	
  but	
  failed
• OpKcal	
  Character	
  RecogniKon	
  (OCR)
-­‐ Tesseract
• White
• AutoIt
• Win32-­‐Autogui
Plan	
  B
• 	
  Oracle	
  ApplicaKon	
  TesKng	
  Suite	
  (OATS)

-­‐ Record	
  +	
  playback
-­‐ Proprietary	
  test	
  automaKon	
  API
Test	
  automa+on	
  is	
  soYware	
  
development
• Code	
  duplicaKon	
  is	
  bad,	
  resulKng	
  in	
  fragile	
  test	
  suites
-­‐ Small	
  changes	
  can	
  break	
  many	
  tests	
  which	
  requires	
  
significant	
  maintenance
-­‐ Frequently	
  see	
  test	
  automaKon	
  abandoned	
  as	
  a	
  
result	
  of	
  this
• Record	
  +	
  playback	
  tools	
  make	
  it	
  difficult	
  to	
  introduce	
  
abstracKons	
  to	
  remove	
  duplicaKon
Oracle	
  Applica+on	
  Tes+ng	
  Suite
• A	
  process	
  of	
  learning	
  through	
  experimentaKon
• Generates	
  Java	
  code	
  under	
  the	
  covers	
  (for	
  both	
  Seibel	
  
and	
  HTML	
  automaKon)
-­‐ Liberate	
  the	
  API	
  from	
  tooling
• Creates	
  executable	
  JWG	
  files	
  as	
  test	
  arKfacts
-­‐ Understand	
  the	
  format	
  of	
  these	
  files	
  so	
  we	
  can	
  
create	
  them	
  programmaKcally
Gains
• 	
  Ability	
  to	
  more	
  easily	
  use	
  good	
  programming	
  
pracKces	
  (abstracKons,	
  code	
  refactoring	
  etc)
• Ability	
  to	
  integrate	
  test	
  arKfacts	
  with	
  ConKnuous	
  
IntegraKon	
  process
• A	
  maintainable	
  test	
  suite	
  for	
  an	
  Agile	
  team
Remedy	
  +cket	
  
management	
  
system
Great	
  news!
• A	
  more	
  tradiKonal	
  webapp	
  (albeit	
  with	
  many	
  quirks)
• AutomaKon	
  possible	
  with	
  familiar	
  toolset	
  
(WebDriver,	
  in	
  our	
  case)	
  
Example	
  quirk	
  #1:	
  windows
Solu+on:	
  model	
  the	
  windows	
  a	
  
stack
• WindowManagingWebDriver
• Allowed	
  us	
  to	
  keep	
  tests	
  focused
• Also	
  responsible	
  for	
  maximizing	
  browser	
  windows	
  
(quirk	
  1.1)
Example	
  quirk	
  #2:	
  mouse	
  
ac+ons	
  alone	
  not	
  enough

	
  	
  	
  	
  
	
  	
  	
  	
  public	
  void	
  navigateToRelationshipsTab()	
  {
	
   	
  	
  	
  	
  findElement(RELATIONSHIPS).sendKeys(Keys.ENTER);
	
   	
  	
  	
  	
  findElement(RELATIONSHIPS).click();
	
  	
  	
  	
  }
The	
  importance	
  of	
  abstrac+ons
• Page	
  model
• Domain	
  objects	
  e.g.	
  Incident
• Builders	
  for	
  domain	
  objects
• Page	
  level	
  gekers/sekers	
  e.g.	
  IncidentSeker,	
  
IncidentGeker
• Workflows	
  to	
  model	
  sequences	
  of	
  interacKons
Data	
  management
Data	
  management
Solu+on:	
  APIs	
  (again)
• AcKon	
  Request	
  System	
  (ARS)	
  API	
  allows	
  creaKon	
  of	
  
state	
  e.g.	
  Incidents	
  programmaKcally
• Simple	
  key/value	
  interface
• Gave	
  us	
  the	
  ability	
  to	
  replace	
  the	
  use	
  of	
  some	
  of	
  our	
  
Workflows	
  with	
  faster	
  running	
  API	
  based	
  Workflows
• Objects	
  created	
  by	
  API	
  based	
  workflows	
  could	
  be	
  
looked	
  up	
  in	
  the	
  browser
The	
  story	
  so	
  far....
• Ability	
  to	
  automate	
  the	
  UI	
  using	
  WebDriver
• AbstracKons	
  in	
  place	
  for	
  robust	
  tesKng
• Ability	
  to	
  setup	
  state	
  using	
  fast	
  API
• Growing	
  regression	
  test	
  suite
Reverse	
  Con+nuous	
  Integra+on
Summary
• COTS	
  test	
  automaKon	
  is	
  possible!
-­‐ Be	
  prepared	
  to	
  find	
  challenges/quirks	
  along	
  the	
  way
• ConKnuous	
  IntegraKon	
  is	
  possible
• APIs	
  are	
  your	
  friends	
  -­‐	
  seek	
  them	
  out
• AbstracKons	
  are	
  crucial,	
  especially	
  with	
  machine	
  
generated	
  code	
  and	
  environmental	
  differences
Ques+ons
ancisco, California 94104
6 F: +1 415 986 2964

ancisco, California 94104
6 F: +1 415 986 2964

Chris Bushell

Chris Bushell

315 Montgomery Street, 16th Floor San Francisco, California 94104
T: +1 415 273 1389 C: +1 415 568 8186 F: +1 415 986 2964
E: chris.bushell@thoughtworks.com

315 Montgomery Street, 16th Floo
T: +1 415 273 1389 C: +1 415
E: chris.bushell@thoughtworks.com

Chris Bushell

Chris Bushell

315 Montgomery Street, 16th Floor San Francisco, California 94104
T: +1 415 273 1389 C: +1 415 568 8186 F: +1 415 986 2964
E: chris.bushell@thoughtworks.com

315 Montgomery Street, 16th Floo
T: +1 415 273 1389 C: +1 415
E: chris.bushell@thoughtworks.com

Chris Bushell

Chris Bushell

Lead Consultant
Email:	
  chris.bushell@thoughtworks.com Lead Consultant
Twi`er:	
  @chrisbushelloz
Github:	
  www.github.com/cbushell
My	
  talks:	
  www.speakerdeck.com/cbushell
LinkedIn:	
  www.linkedin.com/in/chrisbushell

Lead Consultant

Lead Consultant
Credits
• Ross	
  Macbeth,	
  J3474	
  :	
  Old	
  night	
  safe,	
  Belfast,	
  licensed	
  
under	
  CreaKve	
  Commons,	
  hkp://www.geograph.ie/
photo/2261863
• Alan	
  Chia,	
  A pile of Lego blocks, of assorted
colours and sizes, licensed	
  under	
  CreaKve	
  
Commons,	
  hkp://en.wikipedia.org/wiki/
File:Lego_Color_Bricks.jpg
Test Automation for Packaged Systems: Yes, You Can!
Test Automation for Packaged Systems: Yes, You Can!

Test Automation for Packaged Systems: Yes, You Can!

  • 1.
    W15 Test Automation 5/1/2013 3:00:00PM Test Automation for Packaged Systems: Yes, You Can! Presented by: Chris Bushell ThoughtWorks Brought to you by: 340 Corporate Way, Suite 300, Orange Park, FL 32073 888-268-8770 ∙ 904-278-0524 ∙ sqeinfo@sqe.com ∙ www.sqe.com
  • 2.
    Chris Bushell A leadconsultant at ThoughtWorks, Chris Bushell has a wide variety of roles including software developer, architect, test automation specialist, agile coach, and trainer. Chris has more than ten years of industry experience working in finance, retail, telecoms, and mobile in the U.K., Australia, and the U.S. Passionate about software development process and technology, he is an advocate of using open source software for building simple solutions to complex problems. Chris is an active member of the local software development community wherever he's based. Contact Chris on Twitter @chrisbushelloz, by email at chris.bushell@thoughtworks.com, or converse with him face-to-face.
  • 3.
    Test  Automa+on   For  Packaged   Systems: Yes  You  Can! Chris  Bushell Lead  Consultant,  ThoughtWorks
  • 6.
    What  I  do •Developer/Tech  Lead/Architect/ Agile  coach • Custom  so8ware  development • Focus  on  building  the  right  thing • Focus  on  high  quality • Test  driven
  • 7.
    How  I  do  it  –  TDD/BDD
  • 8.
    How  I  do  it  –  Revision  Control
  • 9.
    How  I  do  it  –  Con+nuous   Integra+on
  • 10.
    How  I  do  it  –  Open  Source • Light-­‐weight,  powerful • Extensible • Excellent  community • Examples:  xUnit,  Selenium/ WebDriver,  RSpec,  Concordion,   Cucumber  etc. JUnit
  • 11.
  • 12.
  • 13.
    The  COTS  Con! Highlyextensible software “configured” in powerful development environments, comparable in complexity, and susceptibility to defects as anything in the custom software development world
  • 14.
    The  land  that  +me  forgot
  • 15.
    Complete  lack  of  test   automa+on “Computers  are  designed  to  do  simple  repeKKve   tasks.  The  second  you  have  humans  doing   repeKKve  tasks,  all  the  computers  get  together   late  at  night  and  laugh  at  you” “Every  Kme  you  do  something  for  the  third  Kme,   automate  it.  You’ll  be  doing  it  a  million  Kmes” -­‐  Neal  Ford
  • 16.
    Surely  someone  must  be  doing   this  already? • Commercial  tools  exist,  but  tend  to  be  a  poor  fit  for   Agile  environments -­‐ TesKng  viewed  as  a  luxury  (an  add-­‐on) -­‐ Available  to  few  ($$$$  licensing) -­‐ Discourages  collecKve  ownership -­‐ Difficult  to  use  good  engineering  pracKces -­‐ Difficult  to  integrate  with  ConKnuous  IntegraKon   process  (lack  of  scriptability/headless  mode)
  • 17.
    Lessons  learned  -­‐  what  worked   and  what  didn’t
  • 18.
  • 19.
    But  first,  browser  automa+on   basics • HTML  +  DOM • Selectors -­‐  Id,  class,  xpath • AutomaKon  API -­‐ e.g.  Selenium,  WebDriver,  Sahi,  WaKr  etc.
  • 20.
    Our  biggest  problem •AcKveX • <object> • Impervious  to   tradiKonal   automaKon   toolset
  • 21.
    All  is  not  lost • Not  all  parts  of  the  applicaKon  used  AcKveX • Some  controls  were  regular  HTML  (albeit  machine   generated) -­‐ WebDriver • Perhaps  we  could  use  some  kind  of  hybrid  approach   to  test  automaKon? -­‐ WebDriver  +  X,  Y  or  Z?
  • 22.
    Introducing  Sikuli  -­‐  automa+on   using  images
  • 23.
  • 24.
    package com.tw.xconf; import org.sikuli.script.FindFailed; importorg.sikuli.script.Screen; import org.sikuli.script.Settings; public class Demo { } public static void main(String[] args) { Screen screen = new Screen(); try { screen.click("images/criteria.png"); screen.type("ThoughtWorks"); screen.click("images/search.png"); } catch (FindFailed e) { e.printStackTrace(); } }
  • 25.
    Drawbacks  of  Sikuli •Difficult  to  manage  large  numbers  of  images • Can  be  confused  when  different  regions  of  the  screen   look  the  same • Tests  easily  broken  by  small  changes  in  the  UI • ComparaKvely  slow  to  execute  
  • 26.
    The  story  so  far.... • Ability  to  automate  the  UI -­‐ WebDriver  for  the  regular  HTML -­‐ Sikuli  for  the  AcKveX  controls
  • 27.
    The  last  hurdle •How  do  we  extract  values  from  the  page  so  we  can   perform  asserKons  on  them?
  • 28.
    Tried  but  failed •OpKcal  Character  RecogniKon  (OCR) -­‐ Tesseract • White • AutoIt • Win32-­‐Autogui
  • 29.
    Plan  B •  Oracle  ApplicaKon  TesKng  Suite  (OATS) -­‐ Record  +  playback -­‐ Proprietary  test  automaKon  API
  • 30.
    Test  automa+on  is  soYware   development • Code  duplicaKon  is  bad,  resulKng  in  fragile  test  suites -­‐ Small  changes  can  break  many  tests  which  requires   significant  maintenance -­‐ Frequently  see  test  automaKon  abandoned  as  a   result  of  this • Record  +  playback  tools  make  it  difficult  to  introduce   abstracKons  to  remove  duplicaKon
  • 31.
    Oracle  Applica+on  Tes+ng  Suite • A  process  of  learning  through  experimentaKon • Generates  Java  code  under  the  covers  (for  both  Seibel   and  HTML  automaKon) -­‐ Liberate  the  API  from  tooling • Creates  executable  JWG  files  as  test  arKfacts -­‐ Understand  the  format  of  these  files  so  we  can   create  them  programmaKcally
  • 32.
    Gains •  Ability  to  more  easily  use  good  programming   pracKces  (abstracKons,  code  refactoring  etc) • Ability  to  integrate  test  arKfacts  with  ConKnuous   IntegraKon  process • A  maintainable  test  suite  for  an  Agile  team
  • 34.
  • 35.
    Great  news! • A  more  tradiKonal  webapp  (albeit  with  many  quirks) • AutomaKon  possible  with  familiar  toolset   (WebDriver,  in  our  case)  
  • 36.
  • 37.
    Solu+on:  model  the  windows  a   stack • WindowManagingWebDriver • Allowed  us  to  keep  tests  focused • Also  responsible  for  maximizing  browser  windows   (quirk  1.1)
  • 38.
    Example  quirk  #2:  mouse   ac+ons  alone  not  enough                public  void  navigateToRelationshipsTab()  {          findElement(RELATIONSHIPS).sendKeys(Keys.ENTER);          findElement(RELATIONSHIPS).click();        }
  • 39.
    The  importance  of  abstrac+ons • Page  model • Domain  objects  e.g.  Incident • Builders  for  domain  objects • Page  level  gekers/sekers  e.g.  IncidentSeker,   IncidentGeker • Workflows  to  model  sequences  of  interacKons
  • 40.
  • 41.
  • 42.
    Solu+on:  APIs  (again) •AcKon  Request  System  (ARS)  API  allows  creaKon  of   state  e.g.  Incidents  programmaKcally • Simple  key/value  interface • Gave  us  the  ability  to  replace  the  use  of  some  of  our   Workflows  with  faster  running  API  based  Workflows • Objects  created  by  API  based  workflows  could  be   looked  up  in  the  browser
  • 43.
    The  story  so  far.... • Ability  to  automate  the  UI  using  WebDriver • AbstracKons  in  place  for  robust  tesKng • Ability  to  setup  state  using  fast  API • Growing  regression  test  suite
  • 44.
  • 45.
    Summary • COTS  test  automaKon  is  possible! -­‐ Be  prepared  to  find  challenges/quirks  along  the  way • ConKnuous  IntegraKon  is  possible • APIs  are  your  friends  -­‐  seek  them  out • AbstracKons  are  crucial,  especially  with  machine   generated  code  and  environmental  differences
  • 46.
  • 47.
    ancisco, California 94104 6F: +1 415 986 2964 ancisco, California 94104 6 F: +1 415 986 2964 Chris Bushell Chris Bushell 315 Montgomery Street, 16th Floor San Francisco, California 94104 T: +1 415 273 1389 C: +1 415 568 8186 F: +1 415 986 2964 E: chris.bushell@thoughtworks.com 315 Montgomery Street, 16th Floo T: +1 415 273 1389 C: +1 415 E: chris.bushell@thoughtworks.com Chris Bushell Chris Bushell 315 Montgomery Street, 16th Floor San Francisco, California 94104 T: +1 415 273 1389 C: +1 415 568 8186 F: +1 415 986 2964 E: chris.bushell@thoughtworks.com 315 Montgomery Street, 16th Floo T: +1 415 273 1389 C: +1 415 E: chris.bushell@thoughtworks.com Chris Bushell Chris Bushell Lead Consultant Email:  chris.bushell@thoughtworks.com Lead Consultant Twi`er:  @chrisbushelloz Github:  www.github.com/cbushell My  talks:  www.speakerdeck.com/cbushell LinkedIn:  www.linkedin.com/in/chrisbushell Lead Consultant Lead Consultant
  • 48.
    Credits • Ross  Macbeth,  J3474  :  Old  night  safe,  Belfast,  licensed   under  CreaKve  Commons,  hkp://www.geograph.ie/ photo/2261863 • Alan  Chia,  A pile of Lego blocks, of assorted colours and sizes, licensed  under  CreaKve   Commons,  hkp://en.wikipedia.org/wiki/ File:Lego_Color_Bricks.jpg