Testing Single Page Webapp
Upcoming SlideShare
Loading in...5
×
 

Testing Single Page Webapp

on

  • 2,546 views

 

Statistics

Views

Total Views
2,546
Views on SlideShare
1,781
Embed Views
765

Actions

Likes
1
Downloads
18
Comments
0

38 Embeds 765

http://facebook-programming.blogspot.in 367
http://facebook-programming.blogspot.com 173
http://facebook-programming.blogspot.de 29
http://facebook-programming.blogspot.fr 18
http://facebook-programming.blogspot.it 16
http://facebook-programming.blogspot.com.br 14
http://facebook-programming.blogspot.co.uk 14
http://facebook-programming.blogspot.ru 12
http://facebook-programming.blogspot.jp 12
http://facebook-programming.blogspot.com.ar 11
http://facebook-programming.blogspot.ca 11
http://facebook-programming.blogspot.co.il 10
http://facebook-programming.blogspot.nl 10
http://facebook-programming.blogspot.kr 6
http://facebook-programming.blogspot.ro 6
http://facebook-programming.blogspot.com.au 5
http://facebook-programming.blogspot.com.es 5
http://facebook-programming.blogspot.tw 4
http://facebook-programming.blogspot.sg 4
http://facebook-programming.blogspot.co.at 4
http://facebook-programming.blogspot.fi 3
http://facebook-programming.blogspot.hu 3
http://facebook-programming.blogspot.se 3
http://www.facebook-programming.blogspot.in 3
http://facebook-programming.blogspot.cz 2
http://facebook-programming.blogspot.be 2
http://facebook-programming.blogspot.ae 2
http://facebook-programming.blogspot.gr 2
http://facebook-programming.blogspot.dk 2
http://facebook-programming.blogspot.ch 2
http://facebook-programming.blogspot.sk 2
http://facebook-programming.blogspot.no 2
http://facebook-programming.blogspot.mx 1
http://webcache.googleusercontent.com 1
http://facebook-programming.blogspot.hk 1
http://facebook-programming.blogspot.pt 1
http://facebook-programming.blogspot.ie 1
http://translate.googleusercontent.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

CC Attribution License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Testing Single Page Webapp Testing Single Page Webapp Presentation Transcript

  • Testing Single-page Web App Akshay Mathur Siddharth Saha Nikita Mundhada
  • Ground Rules • Post on FB and Tweet now • Disturb Everyone during the session – Not by phone rings – Not by local talks – By more information and questions 2@akshaymathu @sid_chilling @nikitascorner
  • Let’s Know Each Other • Do you code? • Do you test? • OS? • Programing Language? • HTML DOM, CSS Selectors, JQuery ? • Why are you attending? 3@akshaymathu @sid_chilling @nikitascorner
  • Akshay Mathur • Managed development, testing and release teams in last 14+ years – Currently Principal Architect at ShopSocially • Founding Team Member of – ShopSocially (Enabling “social” for retailers) – AirTight Neworks (Global leader of WIPS) 4@akshaymathu @sid_chilling @nikitascorner
  • Siddharth Saha • CS graduate from NIT Rourkela • 3+ years in Software Product industry • Worked in Telecom (Drishti Soft) and Social Shopping (ShopSocially) Domains • Currently Junior Application Architect at ShopSocially 5@akshaymathu @sid_chilling @nikitascorner
  • Nikita Mundhada • CS graduate from PICT Pune • 2 years in Software Product industry • Worked – at Amdocs as a Java Developer – at ShopSocially as a Full Stack Developer • Going back to college – For MS at Georgia Institute of Technology 6@akshaymathu @sid_chilling @nikitascorner
  • Agenda • Problem Statement – What are single page apps and how are they different – Why other tools fail testing dynamic DoM in browser • Introduction to Server Side Javascript and Related Technologies – Headless Browser, NodeJS, PhantomJS, CasperJS, Splinter • Demonstrations and Code Walkthroughs – Invoking UI test suite, in the browser from Python console, using Splinter – Testing UI from command line, without opening the browser, using CasperJS 7@akshaymathu @sid_chilling @nikitascorner
  • Traditional Web Apps Dynamic on Server
  • The Evolution of Web 9 @akshaymathu @sid_chilling @nikitascorner
  • Traditional Apps • Action items are implemented as hyperlinks to URLs • Different web page is requested from server for next step of workflow • Browser’s address bar is the only progress indicator • Tooltips are available for in-context help 10@akshaymathu @sid_chilling @nikitascorner
  • Page Construction • On Server: – Dynamic portion of the page executes and brings the data – HTML gets constructed using PHP, ASP, JSP etc. • On Client: – Browser renders the HTML DOM – No major change happens in HTML DOM after rendering • Light use of Javascript 11@akshaymathu @sid_chilling @nikitascorner
  • Traditional Testing Tools Work Fine • Get a copy of HTML DOM just before it is being rendered by web browser • Do not execute Javascript • For recognizing DOM elements: – Old: Use window coordinates – New: Use Object’s xPath • Use UI elements/Events for interactions 12@akshaymathu @sid_chilling @nikitascorner
  • Modern Apps Dynamic on Client
  • Modern Apps • Javascript event handlers are attached to on- screen actions • Only required portion of page gets updated as needed • Loading indicator appears whenever user need to wait • Rich in-context interaction, in form of light- box popups 14@akshaymathu @sid_chilling @nikitascorner
  • Page Construction • On Server: – Minimal HTML rendering – Typically no (or minimum) data-driven components – Separate calls for data • On Client: – Data requested from Server using AJAX calls – HTML DOM changes dynamically – Workflow implemented in browser • Heavy use of Javascript – Jquery, BackboneJS etc. 15@akshaymathu @sid_chilling @nikitascorner
  • Traditional Testing Tools Fail • Changed HTML DOM is not available to the tool • xPaths of existing elements change 16@akshaymathu @sid_chilling @nikitascorner
  • Requirements for New Age Tools • Should have complete control over HTML DOM and the Javascript on the page – Should be able to fire DOM events as user does – Should be able run Javascript on the page as it happens in the browser on user’s action – Should be able to get changed DOM as needed • Should use selectors rather than xPaths • Should not depend too much on screen painting 17@akshaymathu @sid_chilling @nikitascorner
  • 18@akshaymathu @sid_chilling @nikitascorner
  • Javascript Runtime Environment Outside the Brower
  • NodeJS • Technology that allows to use Javascript on server side or in command line environment – A complete app-server and web-framework can be written using NodeJS • Even-driven and Asynchronous programming – High performance – Low response time 20@akshaymathu @sid_chilling @nikitascorner
  • Headless Browser • Browser without Graphical User Interface – Implements everything same as web browsers • HTTP Request and Response handling • Rendering Engine • HTTP DOM and Events • Javascript Runtime Environment • Used for website testing, screen capture and page automation from command line 21@akshaymathu @sid_chilling @nikitascorner
  • Headless Browsers • Phantom JS – Headless browser implementing Webkit • Similar to Chrome, Safari • Slimer JS – Upcoming headless browser implementing Gecko • Similar to Firefox 22@akshaymathu @sid_chilling @nikitascorner
  • Testing Tools
  • Casper JS • Tool built on top of Headless Browsers – Same code works for PhantomJS and SlimerJS • Eases the process of defining a full navigation scenario • Provides syntactic sugar for common tasks: – Filling Forms – Clicking and following links – Logging events – Finding DOM elements – … 24@akshaymathu @sid_chilling @nikitascorner
  • Splinter • Open source tool for testing web applications using Python • An abstraction layer on top of existing browser automation tools: – Selenium – PhantomJS – Zope 25@akshaymathu @sid_chilling @nikitascorner
  • 26@akshaymathu @sid_chilling @nikitascorner
  • Demonstrations • Important points to note – The UI under test is sensitive to screen size – The test includes interacting with the elements in an iFrame – The DOM in the iFrame changes dynamically without loading the complete page 27@akshaymathu @sid_chilling @nikitascorner
  • ShopSocially • Provides social apps to online retailers – Most of apps are embed-able on web pages • Execute in iFrame • Do not reload page for better user experience 28@akshaymathu @sid_chilling @nikitascorner
  • Testing with Browser UI Splinter Demonstration and Code Siddharth Saha
  • Splinter • Open source tool for testing web applications using Python • An abstraction layer on top of existing browser automation tools: – Selenium – PhantomJS – Zope 30@akshaymathu @sid_chilling @nikitascorner
  • Splinter • Simple Python APIs • Multiple webdrivers – Chrome, Firefox, PhatomJS, Zope – One code to rule them all • CSS and Xpath Selectors • Support for iframe and alerts • Executes JavaScript 31@akshaymathu @sid_chilling @nikitascorner
  • Do with Splinter • Browser Navigation • Finding elements • Mouse interactions • Interacting with elements and forms • Cookies manipulation • Execute JavaScript • Deal with HTTP status codes • Interact with iframes, alerts and prompts 32@akshaymathu @sid_chilling @nikitascorner
  • @akshaymathu @sid_chilling @nikitascorner 33
  • Choosing Browser from splinter import Browser browser = Browser(„chrome‟) B = Browser(user_agent = „Mozilla/5.0 (iPhone; U;)‟) 34@akshaymathu @sid_chilling @nikitascorner
  • Navigation browser.visit( „http://shopsocially.com‟ ) browser.back() browser.forward() @akshaymathu @sid_chilling @nikitascorner 35
  • Finding DOM Element browser.find_by_id(„my_id‟) browser.find_by_name(„my_name‟) browser.find_by_tag(„h1‟) 36@akshaymathu @sid_chilling @nikitascorner
  • Mouse Interactions browser.find_by_tag(„div‟).first. click() browser.find_by_id(„my_id‟). right_click() browser.find_by_name(„my_name‟). double_click() browser.find_by_tag(„h1‟). mouse_over() 37@akshaymathu @sid_chilling @nikitascorner
  • Interacting with Form Elements browser.fill(„query‟, „Siddharth‟) browser.choose(„some-radio‟, „radio-value‟) browser.select(„my-dropdown‟, „my-fav-value‟) 38@akshaymathu @sid_chilling @nikitascorner
  • Executing Javascript browser.execute_script( “$(„body‟).css(„bgcolor‟, „#ccc‟); $(„#some_el‟).hide();” ) 39@akshaymathu @sid_chilling @nikitascorner
  • Dealing with iFrames with browser.get_iframe(„iframe_id‟) as iframe: iframe.fill(„query‟, „sid‟) 40@akshaymathu @sid_chilling @nikitascorner • iFrame is another browser object – Supports all the functionality of a browser
  • 41@akshaymathu @sid_chilling @nikitascorner
  • Testing without Browser UI CasperJS Demonstration and Code Nikita Mudada
  • Casper JS • Tool built on top of Headless Browsers – Same code works for PhantomJS and SlimerJS • Eases the process of defining a full navigation scenario • Provides syntactic sugar for common tasks: – Filling Forms – Clicking and following links – Logging events – Finding DOM elements – … 43@akshaymathu @sid_chilling @nikitascorner
  • Casper JS • Code written in only JavaScript/CoffeeScript • Casper JS and the javascript in the page execute in their own sandboxes – Specific call is available to communicate • Tester module provides functions and assertions for testing • Utils module provide general utilities for I/O 44@akshaymathu @sid_chilling @nikitascorner
  • Skeleton of a CasperJS program @akshaymathu @sid_chilling @nikitascorner 45 then() run() evaluate() Passes Function Returns Value Page DOM SandboxCasperJS Sandbox Executes Function
  • Example @akshaymathu @sid_chilling @nikitascorner 46 var casper = require('casper').create(); casper.start('http://facebook.com/‟); casper.then(function() { this.echo(this.getTitle()); this.evaluate(function(){ alert("Cookies are:" + document.cookie); }); }); casper.run();
  • Demonstration @akshaymathu @sid_chilling @nikitascorner 47
  • Specifying Window Size var casper = require('casper').create({ verbose:true, logLevel:'info', waitTimeout:10000, viewportSize: {width: 900, height:700} }); 48@akshaymathu @sid_chilling @nikitascorner
  • Checking for DOM Element casper.then(function(){ this.test.assertExists( '#ssmi_getafan_sidebar_image', 'Sidebar image loaded.'); this.click('#ssmi_getafan_sidebar_ image a'); this.page.switchToChildFrame("ssmi _getafan_iframe"); @akshaymathu @sid_chilling @nikitascorner 49
  • Clicking a Hyperlink casper.then(function(){ this.test.assertExists('#ssmi_geta fan_sidebar_image', 'Sidebar image loaded.'); this.click( '#ssmi_getafan_sidebar_image a'); this.page.switchToChildFrame("ssmi _getafan_iframe"); @akshaymathu @sid_chilling @nikitascorner 50
  • Getting into iFrame casper.then(function(){ this.test.assertExists('#ssmi_geta fan_sidebar_image', 'Sidebar image loaded.'); this.click('#ssmi_getafan_sidebar_ image a'); this.page.switchToChildFrame( "ssmi_getafan_iframe"); @akshaymathu @sid_chilling @nikitascorner 51
  • Getting info from Web Page this.evaluate(function(){ alert("Cookies are:" + document.cookie); }); }); @akshaymathu @sid_chilling @nikitascorner 52
  • Waiting for Changing DOM casper.waitForSelector( '#coupon_area > span', function() { this.test.assertTextExists('Tha nk you!', 'Thank you message displayed correctly.'); }); @akshaymathu @sid_chilling @nikitascorner 53
  • Reporting Results casper.run(function(){ require('utils').dump( casper.test.getFailures()); require('utils').dump( casper.test.getPasses()); casper.test.renderResults( true, 0, 'test-results.xml'); }); @akshaymathu @sid_chilling @nikitascorner 54
  • Result Format <testsuite> <testcase classname="samples" name="Get-a-Fan App Sidebar loaded." time="39.647"> </testcase> <testcase classname="samples" name="Found “Special-20” within the selector coupon_area1 > span" time="0.013"> <failure type="assertSelectorHasText">Found "Special-20" within the selector "#coupon_area1 > span“> </failure> </testcase> </testsuite> 55@akshaymathu @sid_chilling @nikitascorner
  • Do with CasperJS • Test webpages – Report results in X-unit XML format – Integrate with Continuous Integration tool like Jenkins • Take screenshots • Fill forms • Insert scripts into webpages • Download links 56@akshaymathu @sid_chilling @nikitascorner
  • 57@akshaymathu @sid_chilling @nikitascorner
  • Summary • Nature of web apps is changing – Javascript is becoming more and more powerful – Dynamism has come to browser • Testing tools are also catching up – Dependency on UI layout is decreasing • Using newer tools and technologies, We can save a lot – Tests are faster as they need not wait for UI – Multiple CasperJS tests can run on same machine 58@akshaymathu @sid_chilling @nikitascorner
  • Thanks 59 @akshaymathu @sid_chilling @nikitascorner @akshaymathu @sid_chilling @nikitascorner