Slide 1

Slide 1 text

P H A N T O M C S S C O M P L E T E U I T E S T I N G

Slide 2

Slide 2 text

PhantomCSS is a CasperJS module for automating visual regression testing with PhantomJS and Resemble.js. For testing Web apps, live style guides and responsive layouts

Slide 3

Slide 3 text

Test coverage of UI without implementation coupling. Tests that reflect the designer model, not the developer model. Graphical idioms not functional primitives.

Slide 4

Slide 4 text

Developed at Huddle. Tools that help people in business work together to create and share content. At its core, a thick client web application for files.

Slide 5

Slide 5 text

More than 40 features, up to 4 views per feature. :hover :active :focus :valid

Slide 6

Slide 6 text

• Our Selenium end-to-end tests were our only UI tests. We needed fast UI tests, independent of end-to-end • Jasmine tests supported and hindered JavaScript development in equal measure. We wanted to refactor our app without needing to change all the tests • Refactoring CSS involved manual regression testing. We wanted automated CSS tests • Our Selenium end-to-end tests were our only UI tests. We needed fast UI tests, independent of end-to-end • Jasmine tests supported and hindered JavaScript development in equal measure. We wanted to refactor our app without needing to change all the tests • Refactoring CSS involved manual regression testing. We wanted automated CSS tests

Slide 7

Slide 7 text

Unit Service UI Test Pyramid - M I K E C O H N , S U C C E E D I N G W I T H A G I L E ( 1 )

Slide 8

Slide 8 text

Unit Service UI/end-to-end Not a test pyramid UI tests are slow, without clear separation of functional tests

Slide 9

Slide 9 text

UI/Unit Service E2E Test Pyramid UI tests should be fast!

Slide 10

Slide 10 text

Unit tests provide fast automated assertions of expected state or behaviour. Each test runs independently of each other. A unit test for UI should test the expected result of JS, HTML and CSS as a single concern S Y S T E M U N D E R T E S T J A VA S C R I P T H T M L C S S F I X T U R E I N T E R FA C E

Slide 11

Slide 11 text

Tests for rendered UI provide implicit coverage of CSS, HTML and JavaScript regardless of technology choices – M A R T I N F O W L E R ( 2 ) “A classic test only cares about the final state - not how that state was derived. ” J A VA S C R I P T H T M L C S S F I X T U R E I N T E R FA C E

Slide 12

Slide 12 text

Isolating the system under test makes feedback faster and tests less fragile. Without speed and confidence, code is perceived to be less malleable and tests become worthless J A VA S C R I P T H T M L C S S F I X T U R E I N T E R FA C E

Slide 13

Slide 13 text

casper.addListener('page.initialized', function(){! ! phantomxhr.fake({! ! ! url: "/api/coffee/list",! ! ! responseBody: {! ! ! ! types: [! ! ! ! ! {name: 'Espresso'},! ! ! ! ! {name: 'Latte'},! ! ! ! ! {name: 'Cappuccino'}! ! ! ! ]! ! ! }! ! });! ! ! casper.removeListener('page.initialized');! });! ! casper.! ! start( “http://my.coffee.local” ).! ! then(function(){! ! ! casper.click('#coffee-machine-button');! ! ! ! ! ! casper.waitForSelector('#myModal:not([style*="display: none"])',! ! ! ! function success(){! ! ! ! ! phantomcss.screenshot('#myModal', 'coffee machine dialog');! ! ! ! },! ! ! ! function timeout(){! ! ! ! ! casper.test.fail('Should see coffee machine');! ! ! ! }! ! ! );! ! }); casper.addListener('page.initialized', function(){! ! phantomxhr.fake({! ! ! url: "/api/coffee/list",! ! ! responseBody: {! ! ! ! types: [! ! ! ! ! {name: 'Espresso'},! ! ! ! ! {name: 'Latte'},! ! ! ! ! {name: 'Cappuccino'}! ! ! ! ]! ! ! }! ! });! ! ! casper.removeListener('page.initialized');! });! ! casper.! ! start( “http://my.coffee.local” ).! ! then(function(){! ! ! casper.click('#coffee-machine-button');! ! ! ! ! ! casper.waitForSelector('#myModal:not([style*="display: none"])',! ! ! ! function success(){! ! ! ! ! phantomcss.screenshot('#myModal', 'coffee machine dialog');! ! ! ! },! ! ! ! function timeout(){! ! ! ! ! casper.test.fail('Should see coffee machine');! ! ! ! }! ! ! );! ! }); Create an API stub to feed fake data to the UI Generate a screenshot and compare to existing

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

Write a failing test Hack the code to make the test pass Refactor the code Keep hacking until it looks good Add a visual test Visual tests can support TDD and refactoring of the entire UI not just the styling – K E N T B E C K , T E S T- D R I V E N D E V E L O P M E N T ( 3 )

Slide 16

Slide 16 text

1. Succeeding with Agile: Software Development Using Scrum - Mike Cohn 2. http://martinfowler.com/articles/mocksArentStubs.html - Martin Fowler 3. Test-Driven Development - Kent Beck

Slide 17

Slide 17 text

P H A N T O M C S S C O M P L E T E U I T E S T I N G https://github.com/Huddle/PhantomCSS @ J A M E S C RY E R