JavaScript Testing. Beginner's Guide. Liang Yuxian Eugene. Test and debug JavaScript the easy way PUBLISHING MUMBAI BIRMINGHAM. k I I.



Similar documents
Elgg 1.8 Social Networking

Debugging JavaScript and CSS Using Firebug. Harman Goei CSCI 571 1/27/13

AJAX Toolkit Framework

Browser tools that make web development easier. Alan Seiden Consulting alanseiden.com

Eclipse Web Tools Platform. Naci Dai (Eteration), WTP JST Lead

Citrix StoreFront. Customizing the Receiver for Web User Interface Citrix. All rights reserved.

An introduction to creating Web 2.0 applications in Rational Application Developer Version 8.0

Reading an sent with Voltage Secur . Using the Voltage Secur Zero Download Messenger (ZDM)

Simply type the id# in the search mechanism of ACS Skills Online to access the learning assets outlined below.

Modern Web Development:

This course provides students with the knowledge and skills to develop ASP.NET MVC 4 web applications.

HP LoadRunner. Software Version: Ajax TruClient Tips & Tricks

Web Application Development

Course Information Course Number: IWT 1229 Course Name: Web Development and Design Foundation

Finding XSS in Real World

Developing ASP.NET MVC 4 Web Applications MOC 20486

JavaScript By: A. Mousavi & P. Broomhead SERG, School of Engineering Design, Brunel University, UK

Automation using Selenium

Credits: Some of the slides are based on material adapted from

AUTOMATED CONFERENCE CD-ROM BUILDER AN OPEN SOURCE APPROACH Stefan Karastanev

Backbase Accessibility

Intro to Web Programming. using PHP, HTTP, CSS, and Javascript Layton Smith CSE 4000

slides at goo.gl/kifue

Ajax Development with ASP.NET 2.0

Tutorial: Building a Dojo Application using IBM Rational Application Developer Loan Payment Calculator

BROWSER-BASED DEVELOPMENT & NETWORK MONITORING UTILITIES

Front-End Performance Testing and Optimization

Getting Started Developing JavaScript Web Apps. this = that. VT Geospatial Forum 2015

HTML5 Data Visualization and Manipulation Tool Colorado School of Mines Field Session Summer 2013

Developing ASP.NET MVC 4 Web Applications

jquery Tutorial for Beginners: Nothing But the Goods

ABC Widget Company. Website Redesign Proposal. Prepared for: Jonathon Doe

Mobile Performance Management Tools Prasanna Gawade, Infosys April 2014

IMRG Peermap API Documentation V 5.0

Interactive Data Visualization for the Web Scott Murray

Developer Tutorial Version 1. 0 February 2015

1. User Guide API overview addon - xml Definition addon.background addon.background.script

Macromedia Dreamweaver 8 Developer Certification Examination Specification

PingFederate. Identity Menu Builder. User Guide. Version 1.0

Software Automated Testing

How we use cookies on our website

MSOW. MSO for the Web MSONet Workstation Configuration Guide

Web Application diploma using.net Technology

Apple Applications > Safari

Rails Cookbook. Rob Orsini. O'REILLY 8 Beijing Cambridge Farnham Koln Paris Sebastopol Taipei Tokyo

Developing ASP.NET MVC 4 Web Applications Course 20486A; 5 Days, Instructor-led

Example. Represent this as XML

IT3504: Web Development Techniques (Optional)

Business Application Services Testing

Portals and Hosted Files

Magento 1.4 Themes Design

HTML5. Turn this page to see Quick Guide of CTTC

HARD-EARNED PERFORMANCE LESSONS

CSE 403. Performance Profiling Marty Stepp

Web Development I & II*

Providing Different Types of Software Systems Development Services

Grails 1.1. Web Application. Development. Reclaiming Productivity for Faster. Java Web Development. Jon Dickinson PUBLISHING J MUMBAI BIRMINGHAM

Application Testing Suite: A fully Java-based software testing platform for testing Oracle E-Business Suite and other web applications

Java Application Development using Eclipse. Jezz Kelway Java Technology Centre, z/os Service IBM Hursley Park Labs, United Kingdom

HyperWorks Enterprise 11.0 Release Notes 2011

Treemap Visualisations

Information Technology Career Cluster Web Development Course Number: Course Standard 1

J j enterpririse. Oracle Application Express 3. Develop Native Oracle database-centric web applications quickly and easily with Oracle APEX

unisys ClearPath eportal Developer 6.1 Unisys Multi-Device App Developer s Guide March

Lucy Zhang UI Developer Contact:

Designing with Exceptions. CSE219, Computer Science III Stony Brook University

Introduction to web development and JavaScript

MSWL Development & Tool. Eclipse IDE

Drupal Performance Tuning

Dashcode User Guide. (Retired Document)

How to test and debug an ASP.NET application

Members of staff may also phone for assistance at any time during the college day (extension 3277).

Dreamweaver CS5. Module 2: Website Modification

Product description version

STATEMENT OF PURPOSE

For Introduction to Java Programming, 5E By Y. Daniel Liang

Migration and Developer Productivity Solutions Retargeting IT for Emerging Business Needs

Java Development for the Cloud, present and future. Scott Rich Distinguished Engineer, IBM Rational

WEB DEVELOPMENT IA & IB (893 & 894)

Programming Social Applications

SIMGallery. User Documentation

Dreamweaver Tutorial - Dreamweaver Interface

Progressive Enhancement With GQuery and GWT. Ray Cromwell

Beginner's Guide. LiveCode Mobile Development. LiveCode. Create fun-filled, rich apps for Android and ios with. Colin Holgate PUBLISHING

Blueball Design Dynamic Content 2 Stack Readme Manual v1.0

Mobile Web Applications. Gary Dubuque IT Research Architect Department of Revenue

Learning HTML5 Game Programming

HtmlUnit: An Efficient Approach to Testing Web Applications

Project 2: Web Security Pitfalls

With 30% 60% of website traffic coming from a mobile device, it s a given

Debugging Mobile Apps

Lakeland College ART/COM 280 SPECIAL TOPICS: FUNDAMENTALS OF WEB DESIGN Fall 2015 SYLLABUS

Load Testing RIA using WebLOAD. Amir Shoval, VP Product Management

Rich User Interfaces for Web-Based Corporate Applications

IBM Rational Web Developer for WebSphere Software Version 6.0

A Tale of the Weaknesses of Current Client-Side XSS Filtering

Advantage of Jquery: T his file is downloaded from

Adobe Dreamweaver CS5

Learning Web App Development

Transcription:

JavaScript Testing Beginner's Guide Test and debug JavaScript the easy way Liang Yuxian Eugene [ rwtmm k I I PUBLISHING I BIRMINGHAM MUMBAI

loading loading runtime Preface 1 Chapter 1: What is JavaScript Testing? 7 Where does JavaScript fit into the web page? 8 HTML Content 8 building a HTML document 9 Styling HTML elements using its attributes 11 Specifying id and class name for an HTML element 12 Cascading Style Sheets 12 styling your HTML document using CSS 14 Referring to an HTML element by its id or class name and styling it 18 Differences between a class selector and an id selector 19 Other uses for dass selectors and id selectors 20 Complete list of CSS attributes 20 JavaScript providing behavior to a web page 20 giving behavior to your HTML document 20 JavaScript Syntax 24 JavaScript events 26 Finding elements in a document 26 Putting it all together 28 The difference between JavaScript and serverside languages 29 Why pages need to work without JavaScript 30 What is testing? 31 Why do you need to test? 31 Types of errors 32 Loading errors 33 errors in action 33 Partially correct JavaScript 34 errors in action 35 Runtime errors 36 errors in action 36 Logic errors 37

checking accessing unobtrusively simplifying logic errors in action 38 Some advice for writing errorfree JavaScript 40 Always check for proper names of objects, variables, and functions 40 Check for proper syntax 40 Plan before you code 40 Check for correctness as you code 40 Preventing errors by choosing a suitable text editor 41 Summary 41 Chapter 2: Ad Hoc Testing and Debugging in JavaScript 43 The purpose of ad hoc testinggetting the script to run 44 What happens when the browser encounters an error in JavaScript 44 Browser differences and the need to test in multiple browsers 45 for features and sniffing browsers 46 Testing browser differences via capability testing 47 capability testing for different browsers 48 Are you getting the correct output and putting values in the correct places? 50 Accessing the values on a form 50 values from a form 51 Another technique for accessing form values 54 Accessing other parts of the web page 55 getting the correct values in the correct places 55 Does the script give the expected result 65 What to do if the script doesn't run? 65 Visually inspecting the code 66 Using alert() to see what code is running 66 Using alert() to see what values are being used 67 using alert to inspect your code 67 A less obtrusive way to check what code is running and the values used 71 checking what values are used 72 Commenting out parts of the script to simplify testing 75 the checking process 76 Timing differencesmaking sure that the HTML is there before interacting with it 77 Why ad hoc testing is never enough 78 Summary 79 Chapter 3: Syntax Validation 81 The difference between validating and testing 82 Code that is valid but wrongvalidation doesn't find all the errors 83 Code that is invalid but right 83 Code that is invalid and wrongvalidation finds some errors that might be difficult to spot any other way 83

using fixing fixing fixing changing Code quality 83 HTML and CSS needs to be valid before you start on JavaScript 84 What happens if you don't validate your code 85 Colorcoding editorshow your editor can help you to spot validation errors 87 Common errors in JavaScript that will be picked up by validation 89 JSLintan online validator 90 JSLint to spot validation errors 91 Valid code constructs that produce validation warnings 92 Should you fix valid code constructs that produce validation warnings? 92 What happens if you don't fix them 93 How to fix validation errors 93 Error missing "use strict" statement 94 "use strict" errors 94 Error unexpected use of ++ 94 fixing the error of "Unexpected use of ++" 95 Error functions not defined 96 the error of "Functions not defined" 96 Too many var statements 97 fixing the error of using too many var statements 98 Expecting <V instead of <\ 100 the expectation of '<V instead of '</' 101 Expected '===' but found '==' 102 == to === 102 Alert is not defined 102 fixing "Alert is not defined" 103 Avoiding HTML event handlers 103 avoiding HTML event handlers 104 Summary of the corrections we have done 106 JavaScript Linta tool you can download 112 Challenge yourselffix the remaining errors spotted by JSLint 113 Summary 113 Chapter 4: Planning to Test 115 A very brief introduction to the software lifecycle 116 The agile method 116 The agile method and the software cycle in action 117 Analysis and design 117 Implementation and testing 117 Deployment 117 Maintenance 117 Do you need a test plan to be able to test? 117

Test Test Test When to develop the test plan 118 How much testing is required? 118 What is the code intended to do? 119 Testing whether the code satisfies our needs 119 Testing for invalid actions by users 119 A short summary of the above issues 120 Major testing concepts and strategies 120 Functional requirement testing 120 Nonfunctional requirement testing 121 Acceptance testing 121 Black box testing 122 Usability tests 123 Boundary testing 123 Equivalence partitioning 123 Beta testing 124 White box testing 124 Branch testing 124 Pareto testing 125 Unit tests 125 Web page tests 126 Performance tests 127 Integration testing 127 Regression testingrepeating prior testing after making changes 128 Testing order 128 Documenting your test plan 129 The test plan 129 Versioning 130 Test strategy 130 Bug form 137 Summary of our test plan 137 Summary 137 Chapter 5: Putting the Test Plan Into Action 139 Applying the test plan: running your tests in order 140 Test Case 1: Testing expected and acceptable values 140 Case la: testing expected and acceptable values by using white box testing 141 Test Case lb: Testing expected but unacceptable values using black box testing 142 case lbi: testing expected but unacceptable values using boundary value testing 142 case lbii: testing expected but unacceptable values using illegal values 144

coding, Test Case 2: Testing the program logic 146 testing the program logic 146 Test Case 3: Integration testing and testing unexpected values 147 Test Case 3a: testing the entire program with expected values 147 Test Case 3b: testing robustness of the second form 150 What to do when a test returns an unexpected result 151 Regression testing in action 151 fixing the bugs and performing regression testing 151 Performance issues compressing your code to make it load faster 160 Does using Ajax make a difference? 161 Difference from serverside testing 162 What happens if you visitor turns off JavaScript 162 Summary 164 Chapter 6: Testing More Complex Code 165 Issues with combining scripts 166 Combining event handlers 166 Naming clashes 168 Using JavaScript libraries 169 Do you need to test a library that someone else has written? 170 What sort of tests to run against library code 170 Performance testing 170 Profiling testing 171 GUI and widget addons to libraries and considerations on how to test them 171 Deliberately throwing your own JavaScript errors 172 The throw statement 172 The try, catch, and finally statements 172 Trapping errors by using builtin objects 176 The Error object 176 The RangeError object 178 The ReferenceError object 178 The TypeError object 180 The SyntaxError object 181 The URIError object 181 The EvalError object 181 Using the error console log 181 Error messages 181 Writing your own messages 182 Modifying scripts and testing 184 modifying, throwing, and catching errors 184 Summary 200

debugging debugging more debugging debugging debugging Chapter 7: Debugging Tools 201 IE 8 Developer Tools (and the developer toolbar plugin for IE6 and 7) 202 Using IE developer tools 202 Open 202 A brief introduction to the user interface 203 Debugging basics of the IE debugging tool 203 HTML by using the IE8 developer tool 204 CSS by using the IE8 developer tool 205 Debugging JavaScript 206 Debugging JavaScript by using the IE8 developer tool 206 Safari or Google Chrome Web Inspector and JavaScript Debugger 211 Differences between Safari and Google Chrome 211 Debugging using Chrome 212 A brief introduction to the user interface 213 with Chrome 213 Opera JavaScript Debugger (Dragonfly) 218 Using Dragonfly 218 Starting Dragonfly 218 with Opera Dragonfly 219 Inspection and Call Stack 220 Thread Log 220 Continue, Step Into, Step Over, Step Out, and Stop at Error 220 Settings 222 Firefox and the Venkman extension 222 Using Firefox's Venkman extension 222 Obtaining the Venkman JavaScript Debugger extension 222 Opening Venkman 222 A brief introduction to the user interface 223 using Firefox's Venkman extension 224 Breakpoints or Call Stack 225 Local Variables and Watches 226 more debugging with the Venkman extension 227 Firefox and the Firebug extension 229 Summary 230

user testing creating Table ofcontents Chapter 8: Testing Tools 231 Sahi 232 Interface testing using Sahi 232 More complex testing with Sahi 235 QUnit 236 JavaScript with QUnit 236 Applying QUnit in reallife situations 240 More assertion tests for various situations 240 JSLitmus 241 ad hoc JavaScript benchmark tests 241 More complex testing with JSLitmus 244 More testing tools that you should check out 244 Summary 246 Index 247