SlideShare a Scribd company logo
WebTest Efficient Functional Web Testing with HtmlUnit and Beyond Marc Guillemot JUG Cologne 25.08.2008
Your speaker French developer exiled in Germany Independent consultant since 2002 Focus on Java, Groovy, Grails and ... web testing HtmlUnit & WebTest lead developer Committer to Groovy & NekoHTML Blog:  http://mguillem.wordpress.com Site (coming):  http://www.efficient-webtesting.com
Agenda Introduction to WebTest Test automation: a software engineering activity Extending WebTest Myths and best practices WebTest and AJAX WebTest's future(s) Conclusion Q & A
What I won't say Why you should automate your web application tests How to install WebTest How to integrate into your build Why Selenium sucks ;-)
What is WebTest Automated web functional testing tool Open Source (Apache 2 license) Founded in 2001 Currently 4 committers (Germany, Switzerland, USA, Australia) Built on top of Apache Ant http://webtest.canoo.com
Who uses WebTest? Open Source project => no idea! Let's look at the mailing list: 700 subscribers [email_address] *@apache.org *@*.gov Akamai, AMD, Axa, Bayer, Boeing, BT, Citigroup, Crédit-Suisse, CSC, DHL, EDS, IBM, Lexmark, Novartis, Oracle, Paypal, Sun, T-Mobile, Thalesgroup, Verisign, Zuehlke, ... => everybody from small to huge
demo (on a strange site)
Over 100 WebTest Steps General <invoke .../> <clickLink .../> ... Forms <setInputField .../> <setRadioButton .../> <clickButton .../> ... Verification <verifyTitle .../> <verifyXPath .../> <verifyInputField .../> ... PDF <pdfDecryptDocument .../> <pdfVerifyField .../> ... Excel documents <excelFindRow .../> <excelVerifyCellValue .../> ... Email, Applets, ... Comprehensive online documentation http://webtest.canoo.com
A software engineering activity
Apply rules of software engineering Remove duplications Extract modules Use source control Consider modifications and extensions Ant, Java, Groovy
XPath Learn XPath Learn XPath!!!  Apply it wisely /html/body/div[2]/center/table[3]/tr/td[@id='total'] //*[@id='total'] Write HTML code allowing simple XPath expressions!!!
Apply the right testing paradigm Capture / replay Model based testing Data driven testing Scripted automation
demo WebTestRecorder
Model based testing Specification: modelling expected behavior Be tolerant to accidental behavior Example: bad XPath: /html/body/div[2]/center/table[3] better: //*[@id='total'] Fault model: modelling unexpected behavior < not > < verifyText text= &quot;NullPointerException&quot;/> </ not >
demo data driven
Scripted automation Maximum flexibility and power Maximum responsibility
Extending WebTest
Why? Go beyond built-in features Customize for special needs Make your tests easier to write Make your tests results easier to read
Building blocks WebTest Groovy Apache ANT Apache POI ... HtmlUnit Jakarta commons-httpclient NekoHTML Mozilla Rhino ...
WebTest uses HtmlUnit A “browser for Java programms” 100% pure java, headless Able to simulate FF or IE Very fast and leightweight Used in WebTest but as well in JSFUnit, WebDriver, JWebUnit, Cactus, Celerity, Schnell, ... Very good JS support... but not yet perfect
Go beyond built-in features ... < webtest > < groovy description =&quot; configure NTLM proxy credentials &quot;> step.context.webClient.credentialsProvider.addNTLMProxyCredentials( &quot;michael&quot;, &quot;secret&quot;, &quot;testserver&quot;, 12345, &quot;BlueGene&quot;, &quot;my.windows.domain&quot;)  </ groovy > < invoke url =&quot; http://testserver/ &quot;/> ..... </ webtest > ...
Hack the web connection
Define custom steps Works but: too low level not reusable ... < verifyXPath xpath= &quot;//*[@id='navPath1']”  text= &quot;Home”/> < verifyXPath xpath= &quot;//*[@id='navPath2']”  text= &quot;Functional testing”/> < verifyXPath xpath= &quot;//*[@id='navPath3']”  text= &quot;WebTest”/> ...
Define custom steps < groovyScript   name= &quot;verifyNavPath”><![CDATA[ class  VerifyNavigationPath  extends  com.canoo.webtest.steps.Step  { String  level1, level2, level3, level4 void  doExecute()  { def  ant =  new  AntBuilder(project) def  levels = [0, level1, level2, level3, level4] for  (i  in  1..<levels.size())  { if  (levels[i]) ant.verifyXPath(xpath: &quot;//a[@id='navPath${i}']/text()&quot;, text: levels[i], description: &quot;Verify level ${i}&quot;) } } } project.addTaskDefinition('verifyNavPath', VerifyNavigationPath) ]]></ groovyScript > ... < verifyNavPath level1= &quot;Home”/> < verifyNavPath level1= &quot;Home”  level2= &quot;Functional testing”  level3= &quot;WebTest”/>
Myths & Best Practices
“ UI tests  are brittle by nature”
Determine what you want to test! How to test addition into the basket? clickLink ”Einkaufskorb”? clickLink “Ajax” ? clickLink xpath=”//*[text() = 'Top Angebot']//a” ? clickLink xpath=”//*[text() = '6.60']/following-sibling::a” ? => it depends! These 4 examples  don't test the same thing !
wrong! “ UI tests  are brittle by nature”
“ Tests ensure that the application works”
demo http://new.jugcologne.org
wrong! => tests allow to find errors, that's all “ Tests ensure that the application works”
“ UI tests must run in the browser  to act like real users”
wrong! => a test pilot is not a standard pilot “ UI tests must run in the browser  to act like real users”
“ UI tests are slow”
Speed matters! Execution speed WebTest very fast: no rendering, single process, HtmlUnit's API allows a better control HtmlUnit vs Watir Celerity benchmarks: 69%-99% time reduction Schnell benchmark: 97% time reduction Report analyse speed Very rich reports Debugging (mostly) useless
demo wt.parallel.nbWorkers
wrong! “ UI tests are slow”
WebTest & AJAX
AJAX testing AJAX supported XMLHttpRequest supported since 2005 But AJAX = complex JS libraries AJAX = testing challenge WebTest JS support not yet perfect Simulated browser offers testing facilities
AJAX = testing challenge Selenium & Co' solution: WebTest's solution: BUT not yet perfect - works well with XHR and setTimeout - doesn't work well with setInterval ;-( nothing here! clickButton  &quot;Update&quot; click  &quot;Update&quot; waitForElementPresent  &quot;some elt&quot; click
JS support not yet perfect HtmlUnit JS support continuously improved HtmlUnit/WebTest already used in numerous projects to test AJAX applications Currently supported libraries: GWT, Sarissa, ...
Testing Facility example: mashup unavailability other.server.com www.myserver.com ?
Testing Facility example: mashup unavailability
WebTest's future(s)
WebTest's future(s) Integration of WebDriver Integration with JMeter for load testing ...
Integration with WebDriver N o w WebTest HtmlUnit HtmlUnit WebDriver Firefox IE ... C o m i n g WebTest
demo wt.withFirefox=1
demo WebTest Sampler
Conclusion
Lessons learned Use recorder only to give you a jump start Write testable code write coherent html code add nodes, ids, ... to make testing easier Test early Modulize / Refactor / Reuse code  Customize your test tool Distinguish guaranted from accidental behavior: which changes in the application should make a step fail which changes in the application should NOT make it fail
WebTest key properties simple fast excellent reporting very low TCO runs everywhere no display needed easy to extend straightforward integration js support not as good as in “normal” browser doesn't accept (too) badly formatted html code doesn't accept (too) badly formatted html code
References WebTest http://webtest.canoo.com WebTestRecorder  http://webtestrecorder.canoo.com Mailing list  http://lists.canoo.com/mailman/listinfo/webtest WebTest screencasts Creating a first WebTest project  http://opensource.basehaus.com/webtest/screencasts/creating-a-first-webtest-project.htm Data driven WebTest  http://opensource.basehaus.com/webtest/screencasts/data-driven-webtest.htm HtmlUnit  http://htmlunit.sf.net WebDriver  http://code.google.com/p/webdriver/ JMeter  http://jakarta.apache.org/jmeter/ Why Selenium sucks (Mark Striebeck, Selenium User Meetup)  http://br.youtube.com/watch?v=EDb8yOM3Vpw Groovy  http://groovy.codehaus.org/ AntBuilder  http://groovy.codehaus.org/Using+Ant+from+Groovy Watir  http://wtr.rubyforge.org/ Schnell  http://code.google.com/p/schnell-jruby/ Celerity  http://celerity.rubyforge.org/ JSFUnit  http://www.jboss.org/jsfunit/
Happy testing!

More Related Content

What's hot (20)

Codeception introduction and use in Yii
Codeception introduction and use in Yii
IlPeach
 
Azure DevOps Realtime Work Item Sync: the good, the bad, the ugly!
Azure DevOps Realtime Work Item Sync: the good, the bad, the ugly!
Lorenzo Barbieri
 
Sync Workitems between multiple Team Projects #vssatpn
Sync Workitems between multiple Team Projects #vssatpn
Lorenzo Barbieri
 
Pragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScript
davejohnson
 
Codeception
Codeception
Jonathan Lau
 
Usability in the GeoWeb
Usability in the GeoWeb
Dave Bouwman
 
Acceptance & Functional Testing with Codeception - SunshinePHP 2016
Acceptance & Functional Testing with Codeception - SunshinePHP 2016
Joe Ferguson
 
Efficient JavaScript Unit Testing, May 2012
Efficient JavaScript Unit Testing, May 2012
Hazem Saleh
 
Web driver selenium simplified
Web driver selenium simplified
Vikas Singh
 
Five Easy Ways to QA Your Drupal Site
Five Easy Ways to QA Your Drupal Site
Mediacurrent
 
Beginning AngularJS
Beginning AngularJS
Troy Miles
 
PHP Unit Testing in Yii
PHP Unit Testing in Yii
IlPeach
 
Automated tests
Automated tests
Damian Sromek
 
Rewrite vs Refactor (AgileIndia 2021)
Rewrite vs Refactor (AgileIndia 2021)
Anand Bagmar
 
Gems Of Selenium
Gems Of Selenium
Skills Matter
 
Abstraction Layers Test Management Summit Faciliated Session 2014
Abstraction Layers Test Management Summit Faciliated Session 2014
Alan Richardson
 
From Good to Great: Functional and Acceptance Testing in WordPress.
From Good to Great: Functional and Acceptance Testing in WordPress.
David Aguilera
 
Php tests tips
Php tests tips
Damian Sromek
 
Unit testing hippo
Unit testing hippo
Ebrahim Aharpour
 
HTML5: what's new?
HTML5: what's new?
Chris Mills
 
Codeception introduction and use in Yii
Codeception introduction and use in Yii
IlPeach
 
Azure DevOps Realtime Work Item Sync: the good, the bad, the ugly!
Azure DevOps Realtime Work Item Sync: the good, the bad, the ugly!
Lorenzo Barbieri
 
Sync Workitems between multiple Team Projects #vssatpn
Sync Workitems between multiple Team Projects #vssatpn
Lorenzo Barbieri
 
Pragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScript
davejohnson
 
Usability in the GeoWeb
Usability in the GeoWeb
Dave Bouwman
 
Acceptance & Functional Testing with Codeception - SunshinePHP 2016
Acceptance & Functional Testing with Codeception - SunshinePHP 2016
Joe Ferguson
 
Efficient JavaScript Unit Testing, May 2012
Efficient JavaScript Unit Testing, May 2012
Hazem Saleh
 
Web driver selenium simplified
Web driver selenium simplified
Vikas Singh
 
Five Easy Ways to QA Your Drupal Site
Five Easy Ways to QA Your Drupal Site
Mediacurrent
 
Beginning AngularJS
Beginning AngularJS
Troy Miles
 
PHP Unit Testing in Yii
PHP Unit Testing in Yii
IlPeach
 
Rewrite vs Refactor (AgileIndia 2021)
Rewrite vs Refactor (AgileIndia 2021)
Anand Bagmar
 
Abstraction Layers Test Management Summit Faciliated Session 2014
Abstraction Layers Test Management Summit Faciliated Session 2014
Alan Richardson
 
From Good to Great: Functional and Acceptance Testing in WordPress.
From Good to Great: Functional and Acceptance Testing in WordPress.
David Aguilera
 
HTML5: what's new?
HTML5: what's new?
Chris Mills
 

Viewers also liked (10)

The Safety Net of Functional Web Testing
The Safety Net of Functional Web Testing
ogborstad
 
Darfur1
Darfur1
mjap23
 
Sitecore 7: A developers quest to mastering unit testing
Sitecore 7: A developers quest to mastering unit testing
nonlinear creations
 
Test-Driven Sitecore
Test-Driven Sitecore
Caitlin Portrie
 
What are the advantages of non functional testing
What are the advantages of non functional testing
Maveric Systems
 
Continuous Testing of eCommerce Apps
Continuous Testing of eCommerce Apps
Sauce Labs
 
The importance of non functional testing
The importance of non functional testing
Maveric Systems
 
Non-functional Testing (NFT) Overview
Non-functional Testing (NFT) Overview
Assaf Halperin
 
Non Functional Testing
Non Functional Testing
Nishant Worah
 
Testing web services
Testing web services
Taras Lytvyn
 
The Safety Net of Functional Web Testing
The Safety Net of Functional Web Testing
ogborstad
 
Darfur1
Darfur1
mjap23
 
Sitecore 7: A developers quest to mastering unit testing
Sitecore 7: A developers quest to mastering unit testing
nonlinear creations
 
What are the advantages of non functional testing
What are the advantages of non functional testing
Maveric Systems
 
Continuous Testing of eCommerce Apps
Continuous Testing of eCommerce Apps
Sauce Labs
 
The importance of non functional testing
The importance of non functional testing
Maveric Systems
 
Non-functional Testing (NFT) Overview
Non-functional Testing (NFT) Overview
Assaf Halperin
 
Non Functional Testing
Non Functional Testing
Nishant Worah
 
Testing web services
Testing web services
Taras Lytvyn
 
Ad

Similar to WebTest - Efficient Functional Web Testing with HtmlUnit and Beyond (20)

Selenium
Selenium
Adam Goucher
 
Internet Explorer 8 for Developers by Christian Thilmany
Internet Explorer 8 for Developers by Christian Thilmany
Christian Thilmany
 
Enterprise Build And Test In The Cloud
Enterprise Build And Test In The Cloud
Carlos Sanchez
 
Justmeans power point
Justmeans power point
justmeanscsr
 
Basic testing with selenium
Basic testing with selenium
Søren Lund
 
One code Web, iOS, Android
One code Web, iOS, Android
Artem Marchenko
 
Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven
Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven
Thorsten Kamann
 
An Introduction to Web Components
An Introduction to Web Components
Red Pill Now
 
Creating testing tools to support development
Creating testing tools to support development
Chema del Barco
 
Integration Testing in Python
Integration Testing in Python
Panoptic Development, Inc.
 
Good practices for debugging Selenium and Appium tests
Good practices for debugging Selenium and Appium tests
Abhijeet Vaikar
 
SoftTest Ireland: Model Based Testing - January 27th 2011
SoftTest Ireland: Model Based Testing - January 27th 2011
David O'Dowd
 
Rey Bango - HTML5: polyfills and shims
Rey Bango - HTML5: polyfills and shims
StarTech Conference
 
Using HttpWatch Plug-in with Selenium Automation in Java
Using HttpWatch Plug-in with Selenium Automation in Java
Sandeep Tol
 
Functional Testing Swing Applications with Frankenstein
Functional Testing Swing Applications with Frankenstein
vivek_prahlad
 
The Testing Planet Issue 2
The Testing Planet Issue 2
Rosie Sherry
 
First QTP Tutorial
First QTP Tutorial
tjdhans
 
QTP Tutorial Slides Presentation.
QTP Tutorial Slides Presentation.
Jaya Priya
 
Dhanasekaran 2008-2009 Quick Test Pro Presentation
Dhanasekaran 2008-2009 Quick Test Pro Presentation
Dhanasekaran Nagarajan
 
Browser Automated Testing Frameworks - Nightwatch.js
Browser Automated Testing Frameworks - Nightwatch.js
Luís Bastião Silva
 
Internet Explorer 8 for Developers by Christian Thilmany
Internet Explorer 8 for Developers by Christian Thilmany
Christian Thilmany
 
Enterprise Build And Test In The Cloud
Enterprise Build And Test In The Cloud
Carlos Sanchez
 
Justmeans power point
Justmeans power point
justmeanscsr
 
Basic testing with selenium
Basic testing with selenium
Søren Lund
 
One code Web, iOS, Android
One code Web, iOS, Android
Artem Marchenko
 
Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven
Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven
Thorsten Kamann
 
An Introduction to Web Components
An Introduction to Web Components
Red Pill Now
 
Creating testing tools to support development
Creating testing tools to support development
Chema del Barco
 
Good practices for debugging Selenium and Appium tests
Good practices for debugging Selenium and Appium tests
Abhijeet Vaikar
 
SoftTest Ireland: Model Based Testing - January 27th 2011
SoftTest Ireland: Model Based Testing - January 27th 2011
David O'Dowd
 
Rey Bango - HTML5: polyfills and shims
Rey Bango - HTML5: polyfills and shims
StarTech Conference
 
Using HttpWatch Plug-in with Selenium Automation in Java
Using HttpWatch Plug-in with Selenium Automation in Java
Sandeep Tol
 
Functional Testing Swing Applications with Frankenstein
Functional Testing Swing Applications with Frankenstein
vivek_prahlad
 
The Testing Planet Issue 2
The Testing Planet Issue 2
Rosie Sherry
 
First QTP Tutorial
First QTP Tutorial
tjdhans
 
QTP Tutorial Slides Presentation.
QTP Tutorial Slides Presentation.
Jaya Priya
 
Dhanasekaran 2008-2009 Quick Test Pro Presentation
Dhanasekaran 2008-2009 Quick Test Pro Presentation
Dhanasekaran Nagarajan
 
Browser Automated Testing Frameworks - Nightwatch.js
Browser Automated Testing Frameworks - Nightwatch.js
Luís Bastião Silva
 
Ad

Recently uploaded (20)

MuleSoft for AgentForce : Topic Center and API Catalog
MuleSoft for AgentForce : Topic Center and API Catalog
shyamraj55
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
High Availability On-Premises FME Flow.pdf
High Availability On-Premises FME Flow.pdf
Safe Software
 
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
Safe Software
 
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Safe Software
 
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
Edge AI and Vision Alliance
 
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
Muhammad Rizwan Akram
 
Down the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training Roadblocks
Rustici Software
 
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
AmirStern2
 
The State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry Report
Liveplex
 
Analysis of the changes in the attitude of the news comments caused by knowin...
Analysis of the changes in the attitude of the news comments caused by knowin...
Matsushita Laboratory
 
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
SOFTTECHHUB
 
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
Edge AI and Vision Alliance
 
June Patch Tuesday
June Patch Tuesday
Ivanti
 
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Alliance
 
Data Validation and System Interoperability
Data Validation and System Interoperability
Safe Software
 
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance
 
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Alliance
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 
Supporting the NextGen 911 Digital Transformation with FME
Supporting the NextGen 911 Digital Transformation with FME
Safe Software
 
MuleSoft for AgentForce : Topic Center and API Catalog
MuleSoft for AgentForce : Topic Center and API Catalog
shyamraj55
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
High Availability On-Premises FME Flow.pdf
High Availability On-Premises FME Flow.pdf
Safe Software
 
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
Safe Software
 
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Safe Software
 
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
Edge AI and Vision Alliance
 
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
Muhammad Rizwan Akram
 
Down the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training Roadblocks
Rustici Software
 
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
AmirStern2
 
The State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry Report
Liveplex
 
Analysis of the changes in the attitude of the news comments caused by knowin...
Analysis of the changes in the attitude of the news comments caused by knowin...
Matsushita Laboratory
 
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
SOFTTECHHUB
 
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
Edge AI and Vision Alliance
 
June Patch Tuesday
June Patch Tuesday
Ivanti
 
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Alliance
 
Data Validation and System Interoperability
Data Validation and System Interoperability
Safe Software
 
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance
 
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Alliance
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 
Supporting the NextGen 911 Digital Transformation with FME
Supporting the NextGen 911 Digital Transformation with FME
Safe Software
 

WebTest - Efficient Functional Web Testing with HtmlUnit and Beyond

  • 1. WebTest Efficient Functional Web Testing with HtmlUnit and Beyond Marc Guillemot JUG Cologne 25.08.2008
  • 2. Your speaker French developer exiled in Germany Independent consultant since 2002 Focus on Java, Groovy, Grails and ... web testing HtmlUnit & WebTest lead developer Committer to Groovy & NekoHTML Blog: http://mguillem.wordpress.com Site (coming): http://www.efficient-webtesting.com
  • 3. Agenda Introduction to WebTest Test automation: a software engineering activity Extending WebTest Myths and best practices WebTest and AJAX WebTest's future(s) Conclusion Q & A
  • 4. What I won't say Why you should automate your web application tests How to install WebTest How to integrate into your build Why Selenium sucks ;-)
  • 5. What is WebTest Automated web functional testing tool Open Source (Apache 2 license) Founded in 2001 Currently 4 committers (Germany, Switzerland, USA, Australia) Built on top of Apache Ant http://webtest.canoo.com
  • 6. Who uses WebTest? Open Source project => no idea! Let's look at the mailing list: 700 subscribers [email_address] *@apache.org *@*.gov Akamai, AMD, Axa, Bayer, Boeing, BT, Citigroup, Crédit-Suisse, CSC, DHL, EDS, IBM, Lexmark, Novartis, Oracle, Paypal, Sun, T-Mobile, Thalesgroup, Verisign, Zuehlke, ... => everybody from small to huge
  • 7. demo (on a strange site)
  • 8. Over 100 WebTest Steps General <invoke .../> <clickLink .../> ... Forms <setInputField .../> <setRadioButton .../> <clickButton .../> ... Verification <verifyTitle .../> <verifyXPath .../> <verifyInputField .../> ... PDF <pdfDecryptDocument .../> <pdfVerifyField .../> ... Excel documents <excelFindRow .../> <excelVerifyCellValue .../> ... Email, Applets, ... Comprehensive online documentation http://webtest.canoo.com
  • 10. Apply rules of software engineering Remove duplications Extract modules Use source control Consider modifications and extensions Ant, Java, Groovy
  • 11. XPath Learn XPath Learn XPath!!! Apply it wisely /html/body/div[2]/center/table[3]/tr/td[@id='total'] //*[@id='total'] Write HTML code allowing simple XPath expressions!!!
  • 12. Apply the right testing paradigm Capture / replay Model based testing Data driven testing Scripted automation
  • 14. Model based testing Specification: modelling expected behavior Be tolerant to accidental behavior Example: bad XPath: /html/body/div[2]/center/table[3] better: //*[@id='total'] Fault model: modelling unexpected behavior < not > < verifyText text= &quot;NullPointerException&quot;/> </ not >
  • 16. Scripted automation Maximum flexibility and power Maximum responsibility
  • 18. Why? Go beyond built-in features Customize for special needs Make your tests easier to write Make your tests results easier to read
  • 19. Building blocks WebTest Groovy Apache ANT Apache POI ... HtmlUnit Jakarta commons-httpclient NekoHTML Mozilla Rhino ...
  • 20. WebTest uses HtmlUnit A “browser for Java programms” 100% pure java, headless Able to simulate FF or IE Very fast and leightweight Used in WebTest but as well in JSFUnit, WebDriver, JWebUnit, Cactus, Celerity, Schnell, ... Very good JS support... but not yet perfect
  • 21. Go beyond built-in features ... < webtest > < groovy description =&quot; configure NTLM proxy credentials &quot;> step.context.webClient.credentialsProvider.addNTLMProxyCredentials( &quot;michael&quot;, &quot;secret&quot;, &quot;testserver&quot;, 12345, &quot;BlueGene&quot;, &quot;my.windows.domain&quot;) </ groovy > < invoke url =&quot; http://testserver/ &quot;/> ..... </ webtest > ...
  • 22. Hack the web connection
  • 23. Define custom steps Works but: too low level not reusable ... < verifyXPath xpath= &quot;//*[@id='navPath1']” text= &quot;Home”/> < verifyXPath xpath= &quot;//*[@id='navPath2']” text= &quot;Functional testing”/> < verifyXPath xpath= &quot;//*[@id='navPath3']” text= &quot;WebTest”/> ...
  • 24. Define custom steps < groovyScript name= &quot;verifyNavPath”><![CDATA[ class VerifyNavigationPath extends com.canoo.webtest.steps.Step { String level1, level2, level3, level4 void doExecute() { def ant = new AntBuilder(project) def levels = [0, level1, level2, level3, level4] for (i in 1..<levels.size()) { if (levels[i]) ant.verifyXPath(xpath: &quot;//a[@id='navPath${i}']/text()&quot;, text: levels[i], description: &quot;Verify level ${i}&quot;) } } } project.addTaskDefinition('verifyNavPath', VerifyNavigationPath) ]]></ groovyScript > ... < verifyNavPath level1= &quot;Home”/> < verifyNavPath level1= &quot;Home” level2= &quot;Functional testing” level3= &quot;WebTest”/>
  • 25. Myths & Best Practices
  • 26. “ UI tests are brittle by nature”
  • 27. Determine what you want to test! How to test addition into the basket? clickLink ”Einkaufskorb”? clickLink “Ajax” ? clickLink xpath=”//*[text() = 'Top Angebot']//a” ? clickLink xpath=”//*[text() = '6.60']/following-sibling::a” ? => it depends! These 4 examples don't test the same thing !
  • 28. wrong! “ UI tests are brittle by nature”
  • 29. “ Tests ensure that the application works”
  • 31. wrong! => tests allow to find errors, that's all “ Tests ensure that the application works”
  • 32. “ UI tests must run in the browser to act like real users”
  • 33. wrong! => a test pilot is not a standard pilot “ UI tests must run in the browser to act like real users”
  • 34. “ UI tests are slow”
  • 35. Speed matters! Execution speed WebTest very fast: no rendering, single process, HtmlUnit's API allows a better control HtmlUnit vs Watir Celerity benchmarks: 69%-99% time reduction Schnell benchmark: 97% time reduction Report analyse speed Very rich reports Debugging (mostly) useless
  • 37. wrong! “ UI tests are slow”
  • 39. AJAX testing AJAX supported XMLHttpRequest supported since 2005 But AJAX = complex JS libraries AJAX = testing challenge WebTest JS support not yet perfect Simulated browser offers testing facilities
  • 40. AJAX = testing challenge Selenium & Co' solution: WebTest's solution: BUT not yet perfect - works well with XHR and setTimeout - doesn't work well with setInterval ;-( nothing here! clickButton &quot;Update&quot; click &quot;Update&quot; waitForElementPresent &quot;some elt&quot; click
  • 41. JS support not yet perfect HtmlUnit JS support continuously improved HtmlUnit/WebTest already used in numerous projects to test AJAX applications Currently supported libraries: GWT, Sarissa, ...
  • 42. Testing Facility example: mashup unavailability other.server.com www.myserver.com ?
  • 43. Testing Facility example: mashup unavailability
  • 45. WebTest's future(s) Integration of WebDriver Integration with JMeter for load testing ...
  • 46. Integration with WebDriver N o w WebTest HtmlUnit HtmlUnit WebDriver Firefox IE ... C o m i n g WebTest
  • 50. Lessons learned Use recorder only to give you a jump start Write testable code write coherent html code add nodes, ids, ... to make testing easier Test early Modulize / Refactor / Reuse code Customize your test tool Distinguish guaranted from accidental behavior: which changes in the application should make a step fail which changes in the application should NOT make it fail
  • 51. WebTest key properties simple fast excellent reporting very low TCO runs everywhere no display needed easy to extend straightforward integration js support not as good as in “normal” browser doesn't accept (too) badly formatted html code doesn't accept (too) badly formatted html code
  • 52. References WebTest http://webtest.canoo.com WebTestRecorder http://webtestrecorder.canoo.com Mailing list http://lists.canoo.com/mailman/listinfo/webtest WebTest screencasts Creating a first WebTest project http://opensource.basehaus.com/webtest/screencasts/creating-a-first-webtest-project.htm Data driven WebTest http://opensource.basehaus.com/webtest/screencasts/data-driven-webtest.htm HtmlUnit http://htmlunit.sf.net WebDriver http://code.google.com/p/webdriver/ JMeter http://jakarta.apache.org/jmeter/ Why Selenium sucks (Mark Striebeck, Selenium User Meetup) http://br.youtube.com/watch?v=EDb8yOM3Vpw Groovy http://groovy.codehaus.org/ AntBuilder http://groovy.codehaus.org/Using+Ant+from+Groovy Watir http://wtr.rubyforge.org/ Schnell http://code.google.com/p/schnell-jruby/ Celerity http://celerity.rubyforge.org/ JSFUnit http://www.jboss.org/jsfunit/