Automated Frontend Testing

Neil Crosby
Neil CrosbyWeb developer, problem solver, tinkerer, sharer at LOVEFiLM
Automated
Frontend Testing
                                                 NeilCrosby




     (Image from “The Korean Robot” - http://www.flickr.com/photos/zebrapares/1344995547/)
Who am I?

@NeilCrosby
European Frontend Architect for Search
at Yahoo!
I help look after frontend code quality.
What’s this talk about?


 • Automatically and regularly testing frontend
   code against known standards.
 • Why? What?     How? Where?
Why?
What? How?
 Where?
Why test?

• We all want to write code that works.
• Testing improves reliability.
• Repeatedly testing minimises regressions.
• Automatic testing can pick up “dumb-ass”
  mistakes.
That sounds lovely


• Normally that doesn’t happen though.
• Normally what happens is...
1. We build things.
They adhere to our
    standards.
2. We go to the pub.
3. Later, we add more
         code.
4. Our code stops
 adhering to our
    standards.
5. Things become less
   easy to maintain.
6. Bugs creep in.
7. We go to the pub in
       despair.
8. Repeat.
So...

• Test automatically and often.
• By adhering to a known standard, and
  constantly testing against it, it becomes
  easier to spot problems with the code that
  we're writing.
And that saves money
              Fewer bugs
                  ==
          Less time fixing bugs
                  ==
   More time developing new features.
Why?
What? How?
 Where?
What’s normally tested
   Backend         Frontend                In-Browser
(API, functions) (HTML, CSS, JS)           (Functional)
                   Validators, JsLint,
     *Unit                                   Selenium
                      YSlow etc.
                                           Sometimes
Automatic via CI        Manual
                                         automatic via CI
                    Adhoc, when
  Well defined                            Fairly well defined
                    remembered
Why not use Selenium?

 • Selenium tests code after it’s been
   interpreted by the browser.
 • Good for functional testing, not so good for
   testing discrete units of code.
Discrete Units?


• I’m looking at testing the quality of our
  HTML, CSS and JavaScript.
• It should all adhere to a known standard.
So we’re testing what?


• The code that leaves the server.
• Before it is interpreted by the browser.
What should we test?

• Currently I’m testing against:
 • W3C HTML Validator        validator.w3.org


 • W3C CSS Validator     jigsaw.w3.org/css-validator


 • JsLint jslint.com
Validation is a dirty word


  • People don’t like the word.
  • They always ask “what if?”.
Custom DTD


• Custom DTDs can help you create your
  own internal standard.
Custom DTDs are Easy

<!ENTITY % HTML.strict SYSTEM quot;strict.dtdquot;>
%HTML.strict;
<!ATTLIST OL
  %attrs; -- %coreattrs, %i18n, %events --
  start NUMBER #IMPLIED -- starting sequence number --
  >
Why?
What? How?
 Where?
How do I do this testing?


  • I’ve been writing a test suite!
  • http://github.com/NeilCrosby/frontend-
    test-suite (CC Attribution-Share Alike)
Currently in Phase 1


• Tests can easily be run against known units
  of HTML, CSS and JavaScript.
• I’m using phpunit as the framework.
HTML Testing

• By default tests against HTML 4.01 Strict.
• Test against custom DTDs.
• Module and full page testing.
• Test files, URLs or strings.
CSS Testing

• By default tests against CSS 2.1.
• Known exceptions to the standards can be
  allowed to pass validation.
• Test files, URLs or strings.
JavaScript Testing


• Test against any configuration JsLint allows.
• Test files, URLs or strings.
Add to your CI


• Run these tests in your hourly builds.
• Run them as a pre-commit hook.
Be a good citizen

• You’ll be running these tests frequently.
• Set up your own local versions of the
  HTML Validator, CSS Validator and JsLint.
• Instructions available on the web.
Running these tests

• If you need to test a simple site, it’s easy -
  pass a config object to
  TheCodeTrainEasyFrontendTestSuite.
• Otherwise, write custom TestCase
  extensions (still not hard).
Including the Suite

require_once(

     'TheCodeTrainEasyFrontendTestSuite.php'

);
Creating the Tests
class SomeTestSuite extends
TheCodeTrainEasyFrontendTestSuite {
    public static function suite() {
        return parent::suite(array(
          ‘html’ => array( ... ),
          ‘css’ => array( ... ),
          ‘js’ => array( ... ),
        ));
    }
}
Creating the Tests
class SomeTestSuite extends
TheCodeTrainEasyFrontendTestSuite {
    public static function suite() {
        return parent::suite(array(
          ‘html’ => array( ... ),
          ‘css’ => array( ... ),
          ‘js’ => array( ... ),
        ));
    }
}
Creating the Tests
class SomeTestSuite extends
TheCodeTrainEasyFrontendTestSuite {
    public static function suite() {
        return parent::suite(array(
         ‘html’ => array( ... ),
         ‘css’ => array( ... ),
         ‘js’ => array( ... ),
        ));
    }
}
Creating the Tests
class SomeTestSuite extends
TheCodeTrainEasyFrontendTestSuite {
    public static function suite() {
        return parent::suite(array(
         ‘html’ => array( ... ),
         ‘css’ => array( ... ),
         ‘js’ => array( ... ),
        ));
    }
}
The ‘html/css/js’ arrays
  ‘html’ => array(
      ‘validator’ => ‘http://yourvalidator’,
      ‘tests’ => array(
        ‘http://someurl.to/test’,
        ‘file://some/file/to/test’,
        ‘<p>Some string to test</p>’,
      ),
      ‘options’ => array( ... )
  )
The ‘html/css/js’ arrays
  ‘html’ => array(
      ‘validator’ => ‘http://yourvalidator’,
      ‘tests’ => array(
        ‘http://someurl.to/test’,
        ‘file://some/file/to/test’,
        ‘<p>Some string to test</p>’,
      ),
      ‘options’ => array( ... )
  )
The ‘html/css/js’ arrays
  ‘html’ => array(
      ‘validator’ => ‘http://yourvalidator’,
      ‘tests’ => array(
        ‘http://someurl.to/test’,
        ‘file://some/file/to/test’,
        ‘<p>Some string to test</p>’,
      ),
      ‘options’ => array( ... )
  )
The ‘html/css/js’ arrays
  ‘html’ => array(
      ‘validator’ => ‘http://yourvalidator’,
      ‘tests’ => array(
        ‘http://someurl.to/test’,
        ‘file://some/file/to/test’,
        ‘<p>Some string to test</p>’,
      ),
      ‘options’ => array( ... )
  )
The Options Array
‘options’ => array(
    ‘doctype_override’ =>
     ‘<!DOCTYPE HTML SYSTEM
     quot;http://site/doctype.dtdquot;>’,
    ‘document_section’ =>
     TheCodeTrainHtmlValidator::HTML_CHUNK,
    ‘document_section_position’ =>
     TheCodeTrainHtmlValidator::POSITION_HEAD
)
The Options Array
‘options’ => array(
    ‘doctype_override’ =>
     ‘<!DOCTYPE HTML SYSTEM
     quot;http://site/doctype.dtdquot;>’,
    ‘document_section’ =>
     TheCodeTrainHtmlValidator::HTML_CHUNK,
    ‘document_section_position’ =>
     TheCodeTrainHtmlValidator::POSITION_HEAD
)
The Options Array
‘options’ => array(
    ‘doctype_override’ =>
     ‘<!DOCTYPE HTML SYSTEM
     quot;http://site/doctype.dtdquot;>’,
    ‘document_section’ =>
     TheCodeTrainHtmlValidator::HTML_CHUNK,
    ‘document_section_position’ =>
     TheCodeTrainHtmlValidator::POSITION_HEAD
)
The Options Array
‘options’ => array(
    ‘doctype_override’ =>
     ‘<!DOCTYPE HTML SYSTEM
     quot;http://site/doctype.dtdquot;>’,
    ‘document_section’ =>
     TheCodeTrainHtmlValidator::HTML_CHUNK,
    ‘document_section_position’ =>
     TheCodeTrainHtmlValidator::POSITION_HEAD
)
Options?
• Custom doctypes, full page or module,
  position on page.
• Options can also be given for individual
  tests.
      array(
           ‘file://some/file/to/test’,
           array( your_options )
      )
Running these tests
> phpunit SomeTestSuite


PHPUnit 3.3.1 by Sebastian Bergmann.


.........


Time: 7 seconds


OK (9 tests, 9 assertions)
Some failures
....F.....


Failed asserting that
Array
(
    [0] => Array
     (
         [line] => 7
         [errortype] =>
         [error] => syntax of attribute value does not conform to declared value
         [original_line] => <label for=quot;quot;>Some label</label>
     )
)
 is false.
Some failures
.....F....


Failed asserting that
Array
(
    [0] => Array
     (
         [line] => 1
         [errortype] => parse-error
      [error] => Value Error : display (http://www.w3.org/TR/CSS21/
visuren.html#propdef-display) inlin is not a display value :
         [original_line] =>   p
     )
)
 is false.
Why?
What? How?
 Where?
Where’s this used?


• Yahoo! - SearchMonkey
• TheCodeTrain.co.uk’s WordPress theme.
It’s found problems

• Security holes.
• Form usability issues.
• Other suspect HTML.
The Future!
Phase 2 - The Future
• Test for things a simple DTD check can’t
  pick up on.
• CodeSniffer.
• Whitelisting sections of code - e.g. adverts.
• Basic accessibility testing - working with the
  experts at Yahoo!.
Available Online
• This talk: http://icanhaz.com/aft
• The Code (please fork and contribute):
  http://github.com/NeilCrosby/frontend-
  test-suite
• Twitter: automated frontend testing,
  @NeilCrosby
• My blog hub: http://neilcrosby.com
1 of 57

Recommended

Night Watch with QA by
Night Watch with QANight Watch with QA
Night Watch with QACarsten Sandtner
1.4K views61 slides
20160905 - BrisJS - nightwatch testing by
20160905 - BrisJS - nightwatch testing20160905 - BrisJS - nightwatch testing
20160905 - BrisJS - nightwatch testingVladimir Roudakov
756 views52 slides
Join the darkside: Selenium testing with Nightwatch.js by
Join the darkside: Selenium testing with Nightwatch.jsJoin the darkside: Selenium testing with Nightwatch.js
Join the darkside: Selenium testing with Nightwatch.jsSeth McLaughlin
42.5K views76 slides
Testing Web Applications by
Testing Web ApplicationsTesting Web Applications
Testing Web ApplicationsSeth McLaughlin
4K views51 slides
Testing nightwatch, by David Torroija by
Testing nightwatch, by David TorroijaTesting nightwatch, by David Torroija
Testing nightwatch, by David TorroijaDavid Torroija
1.3K views28 slides
Fullstack End-to-end test automation with Node.js, one year later by
Fullstack End-to-end test automation with Node.js, one year laterFullstack End-to-end test automation with Node.js, one year later
Fullstack End-to-end test automation with Node.js, one year laterMek Srunyu Stittri
4.9K views49 slides

More Related Content

What's hot

Front-End Testing: Demystified by
Front-End Testing: DemystifiedFront-End Testing: Demystified
Front-End Testing: DemystifiedSeth McLaughlin
9.9K views43 slides
Node.js and Selenium Webdriver, a journey from the Java side by
Node.js and Selenium Webdriver, a journey from the Java sideNode.js and Selenium Webdriver, a journey from the Java side
Node.js and Selenium Webdriver, a journey from the Java sideMek Srunyu Stittri
25.9K views56 slides
ForwardJS 2017 - Fullstack end-to-end Test Automation with node.js by
ForwardJS 2017 -  Fullstack end-to-end Test Automation with node.jsForwardJS 2017 -  Fullstack end-to-end Test Automation with node.js
ForwardJS 2017 - Fullstack end-to-end Test Automation with node.jsMek Srunyu Stittri
2.1K views30 slides
Protractor Tutorial Quality in Agile 2015 by
Protractor Tutorial Quality in Agile 2015Protractor Tutorial Quality in Agile 2015
Protractor Tutorial Quality in Agile 2015Andrew Eisenberg
2.1K views53 slides
Front-end Automated Testing by
Front-end Automated TestingFront-end Automated Testing
Front-end Automated TestingRuben Teijeiro
4.5K views45 slides
Automate testing with behat, selenium, phantom js and nightwatch.js (5) by
Automate testing with behat, selenium, phantom js and nightwatch.js (5)Automate testing with behat, selenium, phantom js and nightwatch.js (5)
Automate testing with behat, selenium, phantom js and nightwatch.js (5)Faichi Solutions
856 views42 slides

What's hot(20)

Front-End Testing: Demystified by Seth McLaughlin
Front-End Testing: DemystifiedFront-End Testing: Demystified
Front-End Testing: Demystified
Seth McLaughlin9.9K views
Node.js and Selenium Webdriver, a journey from the Java side by Mek Srunyu Stittri
Node.js and Selenium Webdriver, a journey from the Java sideNode.js and Selenium Webdriver, a journey from the Java side
Node.js and Selenium Webdriver, a journey from the Java side
Mek Srunyu Stittri25.9K views
ForwardJS 2017 - Fullstack end-to-end Test Automation with node.js by Mek Srunyu Stittri
ForwardJS 2017 -  Fullstack end-to-end Test Automation with node.jsForwardJS 2017 -  Fullstack end-to-end Test Automation with node.js
ForwardJS 2017 - Fullstack end-to-end Test Automation with node.js
Mek Srunyu Stittri2.1K views
Protractor Tutorial Quality in Agile 2015 by Andrew Eisenberg
Protractor Tutorial Quality in Agile 2015Protractor Tutorial Quality in Agile 2015
Protractor Tutorial Quality in Agile 2015
Andrew Eisenberg2.1K views
Front-end Automated Testing by Ruben Teijeiro
Front-end Automated TestingFront-end Automated Testing
Front-end Automated Testing
Ruben Teijeiro4.5K views
Automate testing with behat, selenium, phantom js and nightwatch.js (5) by Faichi Solutions
Automate testing with behat, selenium, phantom js and nightwatch.js (5)Automate testing with behat, selenium, phantom js and nightwatch.js (5)
Automate testing with behat, selenium, phantom js and nightwatch.js (5)
Faichi Solutions856 views
Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015 by Codemotion
Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015
Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015
Codemotion1.4K views
High Performance JavaScript 2011 by Nicholas Zakas
High Performance JavaScript 2011High Performance JavaScript 2011
High Performance JavaScript 2011
Nicholas Zakas10.1K views
Automation Abstraction Layers: Page Objects and Beyond by Alan Richardson
Automation Abstraction Layers: Page Objects and BeyondAutomation Abstraction Layers: Page Objects and Beyond
Automation Abstraction Layers: Page Objects and Beyond
Alan Richardson67.3K views
Automated Testing in Angular Slides by Jim Lynch
Automated Testing in Angular SlidesAutomated Testing in Angular Slides
Automated Testing in Angular Slides
Jim Lynch503 views
Hands on Exploration of Page Objects and Abstraction Layers with Selenium Web... by Alan Richardson
Hands on Exploration of Page Objects and Abstraction Layers with Selenium Web...Hands on Exploration of Page Objects and Abstraction Layers with Selenium Web...
Hands on Exploration of Page Objects and Abstraction Layers with Selenium Web...
Alan Richardson52.3K views
Getting By Without "QA" by Dave King
Getting By Without "QA"Getting By Without "QA"
Getting By Without "QA"
Dave King2K views
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton) by Cogapp
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Cogapp3K views
Selenide Alternative in Practice - Implementation & Lessons learned [Selenium... by Iakiv Kramarenko
Selenide Alternative in Practice - Implementation & Lessons learned [Selenium...Selenide Alternative in Practice - Implementation & Lessons learned [Selenium...
Selenide Alternative in Practice - Implementation & Lessons learned [Selenium...
Iakiv Kramarenko3.3K views
Workshop: Functional testing made easy with PHPUnit & Selenium (phpCE Poland,... by Ondřej Machulda
Workshop: Functional testing made easy with PHPUnit & Selenium (phpCE Poland,...Workshop: Functional testing made easy with PHPUnit & Selenium (phpCE Poland,...
Workshop: Functional testing made easy with PHPUnit & Selenium (phpCE Poland,...
Ondřej Machulda2K views
jQuery Proven Performance Tips & Tricks by Addy Osmani
jQuery Proven Performance Tips & TricksjQuery Proven Performance Tips & Tricks
jQuery Proven Performance Tips & Tricks
Addy Osmani175.6K views
Test automation & Seleniun by oren rubin by Oren Rubin
Test automation & Seleniun by oren rubinTest automation & Seleniun by oren rubin
Test automation & Seleniun by oren rubin
Oren Rubin2.1K views
Agile JavaScript Testing by Scott Becker
Agile JavaScript TestingAgile JavaScript Testing
Agile JavaScript Testing
Scott Becker6.2K views

Viewers also liked

Laravel Unit Testing by
Laravel Unit TestingLaravel Unit Testing
Laravel Unit TestingDr. Syed Hassan Amin
3.9K views30 slides
PayPal's NemoJS and Applitools Eyes - Visual Testing with Node.js by
PayPal's NemoJS and Applitools Eyes - Visual Testing with Node.jsPayPal's NemoJS and Applitools Eyes - Visual Testing with Node.js
PayPal's NemoJS and Applitools Eyes - Visual Testing with Node.jsApplitools
2.3K views30 slides
Building testable chrome extensions by
Building testable chrome extensionsBuilding testable chrome extensions
Building testable chrome extensionsSeth McLaughlin
2K views24 slides
PAVE by
PAVEPAVE
PAVEMike Wilhelm
179 views8 slides
How to write Testable Javascript by
How to write Testable JavascriptHow to write Testable Javascript
How to write Testable JavascriptColdFusionConference
1.1K views69 slides
How To Combine Back-End 
 & Front-End Testing with BlazeMeter & Sauce Labs by
How To Combine Back-End 
 & Front-End Testing with BlazeMeter & Sauce LabsHow To Combine Back-End 
 & Front-End Testing with BlazeMeter & Sauce Labs
How To Combine Back-End 
 & Front-End Testing with BlazeMeter & Sauce LabsSauce Labs
3.3K views18 slides

Viewers also liked(20)

PayPal's NemoJS and Applitools Eyes - Visual Testing with Node.js by Applitools
PayPal's NemoJS and Applitools Eyes - Visual Testing with Node.jsPayPal's NemoJS and Applitools Eyes - Visual Testing with Node.js
PayPal's NemoJS and Applitools Eyes - Visual Testing with Node.js
Applitools2.3K views
Building testable chrome extensions by Seth McLaughlin
Building testable chrome extensionsBuilding testable chrome extensions
Building testable chrome extensions
Seth McLaughlin2K views
How To Combine Back-End 
 & Front-End Testing with BlazeMeter & Sauce Labs by Sauce Labs
How To Combine Back-End 
 & Front-End Testing with BlazeMeter & Sauce LabsHow To Combine Back-End 
 & Front-End Testing with BlazeMeter & Sauce Labs
How To Combine Back-End 
 & Front-End Testing with BlazeMeter & Sauce Labs
Sauce Labs3.3K views
How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016 by Gavin Pickin
How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016
How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016
Gavin Pickin427 views
Varshneya samdarshi lmu_symposium_2016 by GRNsight
Varshneya samdarshi lmu_symposium_2016Varshneya samdarshi lmu_symposium_2016
Varshneya samdarshi lmu_symposium_2016
GRNsight1.4K views
Introduction To Web Application Testing by Ynon Perek
Introduction To Web Application TestingIntroduction To Web Application Testing
Introduction To Web Application Testing
Ynon Perek3.3K views
Javascript Unit Testing Tools by PixelCrayons
Javascript Unit Testing ToolsJavascript Unit Testing Tools
Javascript Unit Testing Tools
PixelCrayons770 views
Web based automation testing on Node.js environment by Yu-Lin Huang
Web based automation testing on Node.js environmentWeb based automation testing on Node.js environment
Web based automation testing on Node.js environment
Yu-Lin Huang353 views
Automated Testing in WordPress, Really?! by Ptah Dunbar
Automated Testing in WordPress, Really?!Automated Testing in WordPress, Really?!
Automated Testing in WordPress, Really?!
Ptah Dunbar22.6K views
Test Automation With Cucumber JVM, Selenium, and Mocha by Salesforce Developers
Test Automation With Cucumber JVM, Selenium, and MochaTest Automation With Cucumber JVM, Selenium, and Mocha
Test Automation With Cucumber JVM, Selenium, and Mocha
An Introduction to Unit Testing by Joe Tremblay
An Introduction to Unit TestingAn Introduction to Unit Testing
An Introduction to Unit Testing
Joe Tremblay3.6K views
Outside In - Behaviour Driven Development (BDD) by Naresh Jain
Outside In - Behaviour Driven Development (BDD)Outside In - Behaviour Driven Development (BDD)
Outside In - Behaviour Driven Development (BDD)
Naresh Jain8.1K views
Python in the Hadoop Ecosystem (Rock Health presentation) by Uri Laserson
Python in the Hadoop Ecosystem (Rock Health presentation)Python in the Hadoop Ecosystem (Rock Health presentation)
Python in the Hadoop Ecosystem (Rock Health presentation)
Uri Laserson168.2K views
Web Application Testing by Richa Goel
Web Application TestingWeb Application Testing
Web Application Testing
Richa Goel10.6K views
Unit Testing Front End JavaScript by FITC
Unit Testing Front End JavaScriptUnit Testing Front End JavaScript
Unit Testing Front End JavaScript
FITC1.9K views
Unit Test + Functional Programming = Love by Alvaro Videla
Unit Test + Functional Programming = LoveUnit Test + Functional Programming = Love
Unit Test + Functional Programming = Love
Alvaro Videla16.9K views
Node Foundation Membership Overview 20160907 by NodejsFoundation
Node Foundation Membership Overview 20160907Node Foundation Membership Overview 20160907
Node Foundation Membership Overview 20160907
NodejsFoundation1.1M views

Similar to Automated Frontend Testing

Testing ASP.NET - Progressive.NET by
Testing ASP.NET - Progressive.NETTesting ASP.NET - Progressive.NET
Testing ASP.NET - Progressive.NETBen Hall
5K views86 slides
Efficient JavaScript Development by
Efficient JavaScript DevelopmentEfficient JavaScript Development
Efficient JavaScript Developmentwolframkriesing
962 views52 slides
Code Quality Practice and Tools by
Code Quality Practice and ToolsCode Quality Practice and Tools
Code Quality Practice and ToolsBob Paulin
866 views39 slides
Token Testing Slides by
Token  Testing SlidesToken  Testing Slides
Token Testing Slidesericholscher
6.9K views87 slides
Testing Ext JS and Sencha Touch by
Testing Ext JS and Sencha TouchTesting Ext JS and Sencha Touch
Testing Ext JS and Sencha TouchMats Bryntse
8.4K views67 slides
Browser-Based testing using Selenium by
Browser-Based testing using SeleniumBrowser-Based testing using Selenium
Browser-Based testing using Seleniumret0
1.2K views37 slides

Similar to Automated Frontend Testing(20)

Testing ASP.NET - Progressive.NET by Ben Hall
Testing ASP.NET - Progressive.NETTesting ASP.NET - Progressive.NET
Testing ASP.NET - Progressive.NET
Ben Hall5K views
Efficient JavaScript Development by wolframkriesing
Efficient JavaScript DevelopmentEfficient JavaScript Development
Efficient JavaScript Development
wolframkriesing962 views
Code Quality Practice and Tools by Bob Paulin
Code Quality Practice and ToolsCode Quality Practice and Tools
Code Quality Practice and Tools
Bob Paulin866 views
Token Testing Slides by ericholscher
Token  Testing SlidesToken  Testing Slides
Token Testing Slides
ericholscher6.9K views
Testing Ext JS and Sencha Touch by Mats Bryntse
Testing Ext JS and Sencha TouchTesting Ext JS and Sencha Touch
Testing Ext JS and Sencha Touch
Mats Bryntse8.4K views
Browser-Based testing using Selenium by ret0
Browser-Based testing using SeleniumBrowser-Based testing using Selenium
Browser-Based testing using Selenium
ret01.2K views
Beyond Cookies, Persistent Storage For Web Applications Web Directions North ... by BradNeuberg
Beyond Cookies, Persistent Storage For Web Applications Web Directions North ...Beyond Cookies, Persistent Storage For Web Applications Web Directions North ...
Beyond Cookies, Persistent Storage For Web Applications Web Directions North ...
BradNeuberg1.6K views
Java script unit testing by Mats Bryntse
Java script unit testingJava script unit testing
Java script unit testing
Mats Bryntse3K views
High Performance Django 1 by DjangoCon2008
High Performance Django 1High Performance Django 1
High Performance Django 1
DjangoCon20081.1K views
High Performance Django by DjangoCon2008
High Performance DjangoHigh Performance Django
High Performance Django
DjangoCon20081.3K views
WebTest - Efficient Functional Web Testing with HtmlUnit and Beyond by mguillem
WebTest - Efficient Functional Web Testing with HtmlUnit and BeyondWebTest - Efficient Functional Web Testing with HtmlUnit and Beyond
WebTest - Efficient Functional Web Testing with HtmlUnit and Beyond
mguillem5.1K views
Nanoformats by rozario
NanoformatsNanoformats
Nanoformats
rozario438 views
An Introduction To jQuery by Andy Gibson
An Introduction To jQueryAn Introduction To jQuery
An Introduction To jQuery
Andy Gibson517 views
Progressive Enhancement with JavaScript and Ajax by Christian Heilmann
Progressive Enhancement with JavaScript and AjaxProgressive Enhancement with JavaScript and Ajax
Progressive Enhancement with JavaScript and Ajax
Christian Heilmann738 views
Efficient JavaScript Development by wolframkriesing
Efficient JavaScript DevelopmentEfficient JavaScript Development
Efficient JavaScript Development
wolframkriesing707 views
Pragmatic Parallels: Java and JavaScript by davejohnson
Pragmatic Parallels: Java and JavaScriptPragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScript
davejohnson1.2K views

More from Neil Crosby

team++; making your team work better together by
team++; making your team work better togetherteam++; making your team work better together
team++; making your team work better togetherNeil Crosby
7.6K views39 slides
team++ by
team++team++
team++Neil Crosby
2.6K views32 slides
Geolocation and Beer by
Geolocation and BeerGeolocation and Beer
Geolocation and BeerNeil Crosby
10.3K views33 slides
Lagging Pipes by
Lagging PipesLagging Pipes
Lagging PipesNeil Crosby
908 views46 slides
Yahoo! Pipes: Munging, Mixing and Mashing by
Yahoo! Pipes: Munging, Mixing and MashingYahoo! Pipes: Munging, Mixing and Mashing
Yahoo! Pipes: Munging, Mixing and MashingNeil Crosby
1.5K views22 slides
Search Monkey - Open Hack London '09 by
Search Monkey - Open Hack London '09Search Monkey - Open Hack London '09
Search Monkey - Open Hack London '09Neil Crosby
1.2K views23 slides

More from Neil Crosby(11)

team++; making your team work better together by Neil Crosby
team++; making your team work better togetherteam++; making your team work better together
team++; making your team work better together
Neil Crosby7.6K views
Geolocation and Beer by Neil Crosby
Geolocation and BeerGeolocation and Beer
Geolocation and Beer
Neil Crosby10.3K views
Yahoo! Pipes: Munging, Mixing and Mashing by Neil Crosby
Yahoo! Pipes: Munging, Mixing and MashingYahoo! Pipes: Munging, Mixing and Mashing
Yahoo! Pipes: Munging, Mixing and Mashing
Neil Crosby1.5K views
Search Monkey - Open Hack London '09 by Neil Crosby
Search Monkey - Open Hack London '09Search Monkey - Open Hack London '09
Search Monkey - Open Hack London '09
Neil Crosby1.2K views
I'll Show You Mine If You Show Me Yours... by Neil Crosby
I'll Show You Mine If You Show Me Yours...I'll Show You Mine If You Show Me Yours...
I'll Show You Mine If You Show Me Yours...
Neil Crosby5.3K views
TV Tubes - Talkin' 'bout my automation... by Neil Crosby
TV Tubes - Talkin' 'bout my automation...TV Tubes - Talkin' 'bout my automation...
TV Tubes - Talkin' 'bout my automation...
Neil Crosby672 views
Starting to Monkey Around With Yahoo! Search Monkey by Neil Crosby
Starting to Monkey Around With Yahoo! Search MonkeyStarting to Monkey Around With Yahoo! Search Monkey
Starting to Monkey Around With Yahoo! Search Monkey
Neil Crosby4.4K views
Multi-level vCards by Neil Crosby
Multi-level vCardsMulti-level vCards
Multi-level vCards
Neil Crosby726 views

Recently uploaded

Anti-Cancer Drugs-Medicinal Chemistry by
Anti-Cancer Drugs-Medicinal ChemistryAnti-Cancer Drugs-Medicinal Chemistry
Anti-Cancer Drugs-Medicinal ChemistryNarminHamaaminHussen
7 views41 slides
New Icon Presentation.pdf by
New Icon Presentation.pdfNew Icon Presentation.pdf
New Icon Presentation.pdfsydneyjrichardson
20 views5 slides
Anthelmintic Drugs-Medicinal Chemistry by
Anthelmintic Drugs-Medicinal ChemistryAnthelmintic Drugs-Medicinal Chemistry
Anthelmintic Drugs-Medicinal ChemistryNarminHamaaminHussen
5 views23 slides
Design System in Figma A to Z.pdf by
Design System in Figma A to Z.pdfDesign System in Figma A to Z.pdf
Design System in Figma A to Z.pdfAtiqur Rahaman
18 views16 slides
Benzodiazepines--Medicinal Chemistry by
Benzodiazepines--Medicinal ChemistryBenzodiazepines--Medicinal Chemistry
Benzodiazepines--Medicinal ChemistryNarminHamaaminHussen
6 views32 slides
Free World aids day Template from Best presentation design agency by
Free World aids day Template from Best presentation design agencyFree World aids day Template from Best presentation design agency
Free World aids day Template from Best presentation design agencyslideceotemplates
5 views10 slides

Recently uploaded(20)

Design System in Figma A to Z.pdf by Atiqur Rahaman
Design System in Figma A to Z.pdfDesign System in Figma A to Z.pdf
Design System in Figma A to Z.pdf
Atiqur Rahaman18 views
Free World aids day Template from Best presentation design agency by slideceotemplates
Free World aids day Template from Best presentation design agencyFree World aids day Template from Best presentation design agency
Free World aids day Template from Best presentation design agency
Scopic UX Design Test Task.pdf by Atiqur Rahaman
Scopic UX Design Test Task.pdfScopic UX Design Test Task.pdf
Scopic UX Design Test Task.pdf
Atiqur Rahaman283 views
217 Drive - All on upper.pptx by vidstor282
217 Drive - All on upper.pptx217 Drive - All on upper.pptx
217 Drive - All on upper.pptx
vidstor28214 views
Presentation (1).pdf by hjksa
Presentation (1).pdfPresentation (1).pdf
Presentation (1).pdf
hjksa17 views
Doing Footwear - Footwear Factory by Doing Footwear
Doing Footwear - Footwear FactoryDoing Footwear - Footwear Factory
Doing Footwear - Footwear Factory
Doing Footwear10 views
Oregon Ducks 4 Spencer Webb Hoodie by brandshop1
Oregon Ducks 4 Spencer Webb HoodieOregon Ducks 4 Spencer Webb Hoodie
Oregon Ducks 4 Spencer Webb Hoodie
brandshop112 views
TISFLEET WEB DESIGN PROJECT by Rabius Sany
TISFLEET WEB DESIGN PROJECTTISFLEET WEB DESIGN PROJECT
TISFLEET WEB DESIGN PROJECT
Rabius Sany38 views
Big Deal Curmel Moton Shirt by brandshop1
Big Deal Curmel Moton ShirtBig Deal Curmel Moton Shirt
Big Deal Curmel Moton Shirt
brandshop18 views

Automated Frontend Testing

  • 1. Automated Frontend Testing NeilCrosby (Image from “The Korean Robot” - http://www.flickr.com/photos/zebrapares/1344995547/)
  • 2. Who am I? @NeilCrosby European Frontend Architect for Search at Yahoo! I help look after frontend code quality.
  • 3. What’s this talk about? • Automatically and regularly testing frontend code against known standards. • Why? What? How? Where?
  • 5. Why test? • We all want to write code that works. • Testing improves reliability. • Repeatedly testing minimises regressions. • Automatic testing can pick up “dumb-ass” mistakes.
  • 6. That sounds lovely • Normally that doesn’t happen though. • Normally what happens is...
  • 7. 1. We build things. They adhere to our standards.
  • 8. 2. We go to the pub.
  • 9. 3. Later, we add more code.
  • 10. 4. Our code stops adhering to our standards.
  • 11. 5. Things become less easy to maintain.
  • 13. 7. We go to the pub in despair.
  • 15. So... • Test automatically and often. • By adhering to a known standard, and constantly testing against it, it becomes easier to spot problems with the code that we're writing.
  • 16. And that saves money Fewer bugs == Less time fixing bugs == More time developing new features.
  • 18. What’s normally tested Backend Frontend In-Browser (API, functions) (HTML, CSS, JS) (Functional) Validators, JsLint, *Unit Selenium YSlow etc. Sometimes Automatic via CI Manual automatic via CI Adhoc, when Well defined Fairly well defined remembered
  • 19. Why not use Selenium? • Selenium tests code after it’s been interpreted by the browser. • Good for functional testing, not so good for testing discrete units of code.
  • 20. Discrete Units? • I’m looking at testing the quality of our HTML, CSS and JavaScript. • It should all adhere to a known standard.
  • 21. So we’re testing what? • The code that leaves the server. • Before it is interpreted by the browser.
  • 22. What should we test? • Currently I’m testing against: • W3C HTML Validator validator.w3.org • W3C CSS Validator jigsaw.w3.org/css-validator • JsLint jslint.com
  • 23. Validation is a dirty word • People don’t like the word. • They always ask “what if?”.
  • 24. Custom DTD • Custom DTDs can help you create your own internal standard.
  • 25. Custom DTDs are Easy <!ENTITY % HTML.strict SYSTEM quot;strict.dtdquot;> %HTML.strict; <!ATTLIST OL %attrs; -- %coreattrs, %i18n, %events -- start NUMBER #IMPLIED -- starting sequence number -- >
  • 27. How do I do this testing? • I’ve been writing a test suite! • http://github.com/NeilCrosby/frontend- test-suite (CC Attribution-Share Alike)
  • 28. Currently in Phase 1 • Tests can easily be run against known units of HTML, CSS and JavaScript. • I’m using phpunit as the framework.
  • 29. HTML Testing • By default tests against HTML 4.01 Strict. • Test against custom DTDs. • Module and full page testing. • Test files, URLs or strings.
  • 30. CSS Testing • By default tests against CSS 2.1. • Known exceptions to the standards can be allowed to pass validation. • Test files, URLs or strings.
  • 31. JavaScript Testing • Test against any configuration JsLint allows. • Test files, URLs or strings.
  • 32. Add to your CI • Run these tests in your hourly builds. • Run them as a pre-commit hook.
  • 33. Be a good citizen • You’ll be running these tests frequently. • Set up your own local versions of the HTML Validator, CSS Validator and JsLint. • Instructions available on the web.
  • 34. Running these tests • If you need to test a simple site, it’s easy - pass a config object to TheCodeTrainEasyFrontendTestSuite. • Otherwise, write custom TestCase extensions (still not hard).
  • 35. Including the Suite require_once( 'TheCodeTrainEasyFrontendTestSuite.php' );
  • 36. Creating the Tests class SomeTestSuite extends TheCodeTrainEasyFrontendTestSuite { public static function suite() { return parent::suite(array( ‘html’ => array( ... ), ‘css’ => array( ... ), ‘js’ => array( ... ), )); } }
  • 37. Creating the Tests class SomeTestSuite extends TheCodeTrainEasyFrontendTestSuite { public static function suite() { return parent::suite(array( ‘html’ => array( ... ), ‘css’ => array( ... ), ‘js’ => array( ... ), )); } }
  • 38. Creating the Tests class SomeTestSuite extends TheCodeTrainEasyFrontendTestSuite { public static function suite() { return parent::suite(array( ‘html’ => array( ... ), ‘css’ => array( ... ), ‘js’ => array( ... ), )); } }
  • 39. Creating the Tests class SomeTestSuite extends TheCodeTrainEasyFrontendTestSuite { public static function suite() { return parent::suite(array( ‘html’ => array( ... ), ‘css’ => array( ... ), ‘js’ => array( ... ), )); } }
  • 40. The ‘html/css/js’ arrays ‘html’ => array( ‘validator’ => ‘http://yourvalidator’, ‘tests’ => array( ‘http://someurl.to/test’, ‘file://some/file/to/test’, ‘<p>Some string to test</p>’, ), ‘options’ => array( ... ) )
  • 41. The ‘html/css/js’ arrays ‘html’ => array( ‘validator’ => ‘http://yourvalidator’, ‘tests’ => array( ‘http://someurl.to/test’, ‘file://some/file/to/test’, ‘<p>Some string to test</p>’, ), ‘options’ => array( ... ) )
  • 42. The ‘html/css/js’ arrays ‘html’ => array( ‘validator’ => ‘http://yourvalidator’, ‘tests’ => array( ‘http://someurl.to/test’, ‘file://some/file/to/test’, ‘<p>Some string to test</p>’, ), ‘options’ => array( ... ) )
  • 43. The ‘html/css/js’ arrays ‘html’ => array( ‘validator’ => ‘http://yourvalidator’, ‘tests’ => array( ‘http://someurl.to/test’, ‘file://some/file/to/test’, ‘<p>Some string to test</p>’, ), ‘options’ => array( ... ) )
  • 44. The Options Array ‘options’ => array( ‘doctype_override’ => ‘<!DOCTYPE HTML SYSTEM quot;http://site/doctype.dtdquot;>’, ‘document_section’ => TheCodeTrainHtmlValidator::HTML_CHUNK, ‘document_section_position’ => TheCodeTrainHtmlValidator::POSITION_HEAD )
  • 45. The Options Array ‘options’ => array( ‘doctype_override’ => ‘<!DOCTYPE HTML SYSTEM quot;http://site/doctype.dtdquot;>’, ‘document_section’ => TheCodeTrainHtmlValidator::HTML_CHUNK, ‘document_section_position’ => TheCodeTrainHtmlValidator::POSITION_HEAD )
  • 46. The Options Array ‘options’ => array( ‘doctype_override’ => ‘<!DOCTYPE HTML SYSTEM quot;http://site/doctype.dtdquot;>’, ‘document_section’ => TheCodeTrainHtmlValidator::HTML_CHUNK, ‘document_section_position’ => TheCodeTrainHtmlValidator::POSITION_HEAD )
  • 47. The Options Array ‘options’ => array( ‘doctype_override’ => ‘<!DOCTYPE HTML SYSTEM quot;http://site/doctype.dtdquot;>’, ‘document_section’ => TheCodeTrainHtmlValidator::HTML_CHUNK, ‘document_section_position’ => TheCodeTrainHtmlValidator::POSITION_HEAD )
  • 48. Options? • Custom doctypes, full page or module, position on page. • Options can also be given for individual tests. array( ‘file://some/file/to/test’, array( your_options ) )
  • 49. Running these tests > phpunit SomeTestSuite PHPUnit 3.3.1 by Sebastian Bergmann. ......... Time: 7 seconds OK (9 tests, 9 assertions)
  • 50. Some failures ....F..... Failed asserting that Array ( [0] => Array ( [line] => 7 [errortype] => [error] => syntax of attribute value does not conform to declared value [original_line] => <label for=quot;quot;>Some label</label> ) ) is false.
  • 51. Some failures .....F.... Failed asserting that Array ( [0] => Array ( [line] => 1 [errortype] => parse-error [error] => Value Error : display (http://www.w3.org/TR/CSS21/ visuren.html#propdef-display) inlin is not a display value : [original_line] => p ) ) is false.
  • 53. Where’s this used? • Yahoo! - SearchMonkey • TheCodeTrain.co.uk’s WordPress theme.
  • 54. It’s found problems • Security holes. • Form usability issues. • Other suspect HTML.
  • 56. Phase 2 - The Future • Test for things a simple DTD check can’t pick up on. • CodeSniffer. • Whitelisting sections of code - e.g. adverts. • Basic accessibility testing - working with the experts at Yahoo!.
  • 57. Available Online • This talk: http://icanhaz.com/aft • The Code (please fork and contribute): http://github.com/NeilCrosby/frontend- test-suite • Twitter: automated frontend testing, @NeilCrosby • My blog hub: http://neilcrosby.com

Editor's Notes

  1. I&#x2019;m also lazy.
  2. Unfiltered data labels pointing to non-existent input elements