fighting layout bugs
play

Fighting Layout Bugs Techniques to automatically verify the work of - PowerPoint PPT Presentation

Fighting Layout Bugs Techniques to automatically verify the work of HTML and CSS programmers QCon London 2010 Who am I? Michael Tamm System Architect Selenium committer Conference Speaker author of numerous JUnit tests ;)


  1. Fighting Layout Bugs Techniques to automatically verify the work of HTML and CSS programmers QCon London 2010

  2. Who am I? Michael Tamm  System Architect  Selenium committer  Conference Speaker  author of numerous JUnit tests ;)  big fan of IntelliJ IDEA, Hamcrest, Mockito, FindBugs, ... 2 / 96 Fighting Layout Bugs – QCon London 2010

  3. You all know this ... Presentation Layer Application Layer Business Logic Layer Persistence Layer 3 / 96 Fighting Layout Bugs – QCon London 2010

  4. Agenda Technique #1 Continuous HTML validation Technique #2 Continuous CSS validation Technique #3 Detect typical layout bugs using JavaScript and image processing Technique #4 Automatically detect violations of the design rules of your website 4 / 96 Fighting Layout Bugs – QCon London 2010

  5. Agenda Technique #1 Continuous HTML validation Technique #2 Continuous CSS validation Technique #3 Detect typical layout bugs using JavaScript and image processing Technique #4 Automatically detect violations of the design rules of your website 5 / 96 Fighting Layout Bugs – QCon London 2010

  6. Idea Prevent layout bugs by always delivering valid HTML pages. 6 / 96 Fighting Layout Bugs – QCon London 2010

  7. How? A Browser Extension?  Only works in one browser.  Does not validate pages automatically.  Can not make the build fail 7 / 96 Fighting Layout Bugs – QCon London 2010

  8. How? Scan files during the build process?  Doesn't work for templates (*.jsp, *.vm, ...) 8 / 96 Fighting Layout Bugs – QCon London 2010

  9. How? Validate HTML during your frontend tests!  Option 1: A separate test, which validates a well defined set of pages  Option 2: Inside every frontend test, each time you get a new page  Should use the W3C Markup Validation Service 9 / 96 Fighting Layout Bugs – QCon London 2010

  10. W3C Markup Validation Service 10 / 96 Fighting Layout Bugs – QCon London 2010

  11. W3C Markup Validation Service 11 / 96 Fighting Layout Bugs – QCon London 2010

  12. W3C Markup Validation Service 12 / 96 Fighting Layout Bugs – QCon London 2010

  13. W3C Markup Validation Service 13 / 96 Fighting Layout Bugs – QCon London 2010

  14. How to fail faster than waiting for CI? Use a javax.servlet.Filter!  Works in all browsers.  Can validate HTML automatically.  Should not hamper daily work.  Should use the W3C Markup Validation Service too. 14 / 96 Fighting Layout Bugs – QCon London 2010

  15. The W3CMarkupValidationFilter class How it works:  Inside the doFilter method: responseWrapper = new TeeHttpServletResponse(response); filterChain.doFilter(request, responseWrapper);  The TeeHttpServletReponse writes the reponse a) immediatly back to the browser and b) into an internal buffer.  After doFilter returns, the HTML is fetched from, the buffer and send to the W3C Markup Validation Service.  A small JavaScript snippet is appended to the response (after the closing </html> tag), which displays either a green or a red box, depending on the validation result. 15 / 96 Fighting Layout Bugs – QCon London 2010

  16. W3CMarkupValidationFilter in action Demo 16 / 96 Fighting Layout Bugs – QCon London 2010

  17. W3CMarkupValidationFilter in action 17 / 96 Fighting Layout Bugs – QCon London 2010

  18. W3CMarkupValidationFilter in action 18 / 96 Fighting Layout Bugs – QCon London 2010

  19. W3CMarkupValidationFilter in action 19 / 96 Fighting Layout Bugs – QCon London 2010

  20. W3CMarkupValidationFilter in action 20 / 96 Fighting Layout Bugs – QCon London 2010

  21. W3CMarkupValidationFilter in action 21 / 96 Fighting Layout Bugs – QCon London 2010

  22. Some final thoughts Try it out http://w3c-markup-validation-filter.googlecode.com/ How to deal with ads?  Do you need to integrate invalid HTML into your web page provided from a third party?  You can add a switch to your web application to disable all ads.  You can extend the W3CMarkupValidationFilter and strip out those snippets, which should not be validated. 22 / 96 Fighting Layout Bugs – QCon London 2010

  23. Agenda Technique #1 Continuous HTML validation Technique #2 Continuous CSS validation Technique #3 Detect typical layout bugs using JavaScript and image processing Technique #4 Automatically detect violations of the design rules of your website 23 / 96 Fighting Layout Bugs – QCon London 2010

  24. Idea Prevent layout bugs by always delivering valid CSS. 24 / 96 Fighting Layout Bugs – QCon London 2010

  25. How? A Browser Extension?  Only works in one browser.  Does not validate pages automatically.  Can not make the build fail 25 / 96 Fighting Layout Bugs – QCon London 2010

  26. How? Scan files during the build process?  CSS is not only in *.css files, but also in HTML (templates) inside <style> elements and/or style attributes 26 / 96 Fighting Layout Bugs – QCon London 2010

  27. How? Scan files during the build process!  CSS is not only in *.css files, but also in HTML (templates) inside <style> elements and/or style attributes  Nevertheless, why not validate the *.css files? 27 / 96 Fighting Layout Bugs – QCon London 2010

  28. CSS Validation Service 28 / 96 Fighting Layout Bugs – QCon London 2010

  29. How? Should you use the CSS Validation Service?  Complains about some CSS hacks, e.g. ... { *display: ... }  Doesn't complain about: * html ... { ... }  Complains about unknown CSS properties / values, e.g. ... { -moz-border-radius: ... } ... { filter: progid:DXImageTransform.... } ... { ...: expression(...) } 29 / 96 Fighting Layout Bugs – QCon London 2010

  30. Example 30 / 96 Fighting Layout Bugs – QCon London 2010

  31. Example 31 / 96 Fighting Layout Bugs – QCon London 2010

  32. How? Validate CSS during your frontend tests!  This is another reasonable option. A javax.servlet.Filter!  Haven't done that yet, but sounds like a nice idea to me. 32 / 96 Fighting Layout Bugs – QCon London 2010

  33. But! Valid CSS is not good enough ... 33 / 96 Fighting Layout Bugs – QCon London 2010

  34. Typical layout bug: invalid URLs in the CSS 34 / 96 Fighting Layout Bugs – QCon London 2010

  35. Typical layout bug: HTML and CSS do not match 35 / 96 Fighting Layout Bugs – QCon London 2010

  36. Agenda Technique #1 Continuous HTML validation Technique #2 Continuous CSS validation Technique #3 Detect typical layout bugs using JavaScript and image processing Technique #4 Automatically detect violations of the design rules of your website 36 / 96 Fighting Layout Bugs – QCon London 2010

  37. Idea Detect layout bugs by simulating the human eye. 37 / 96 Fighting Layout Bugs – QCon London 2010

  38. Typical layout bug: text truncated at vertical edge 38 / 96 Fighting Layout Bugs – QCon London 2010

  39. Typical layout bug: text truncated at horizontal edge 39 / 96 Fighting Layout Bugs – QCon London 2010

  40. Typical layout bug: text overlaps vertical edge 40 / 96 Fighting Layout Bugs – QCon London 2010

  41. Typical layout bug: text overlaps vertical edge 41 / 96 Fighting Layout Bugs – QCon London 2010

  42. Typical layout bug: not enough space between text and edge 42 / 96 Fighting Layout Bugs – QCon London 2010

  43. How to automatically detect those layout bugs?  We need to know, which pixels belong to text.  We need to know, which pixels belong to a vertical or horizontal edge.  If text pixels and edge pixels overlap, we have found a layout bug.  We need to somehow report a found layout bug. 43 / 96 Fighting Layout Bugs – QCon London 2010

  44. 1.) Detecting text How the SimpleTextDetector works:  Inject jQuery into currently displayed page  jQuery('*').css('color', '#000000');  Take screenshot  jQuery('*').css('color', '#fffff');  Take another screenshot  Compare the two screenshots: All different pixels are probably text. 44 / 96 Fighting Layout Bugs – QCon London 2010

  45. SimpleTextDetector in action 45 / 96 Fighting Layout Bugs – QCon London 2010

  46. SimpleTextDetector in action 46 / 96 Fighting Layout Bugs – QCon London 2010

  47. SimpleTextDetector in action 47 / 96 Fighting Layout Bugs – QCon London 2010

  48. SimpleTextDetector in action 48 / 96 Fighting Layout Bugs – QCon London 2010

  49. SimpleTextDetector in action 49 / 96 Fighting Layout Bugs – QCon London 2010

  50. 2.) Detecting vertical edges How the SimpleEdgeDetector works:  Inject jQuery into currently displayed page  jQuery('*').css('color', 'transparent');  Take screenshot  Find vertical pixel sequences of a certain minimal length, where each pixel has the same color (or a very similar one)  Only select those, which have a high contrast to the left or right  Only select those, which have a certain minimal length 50 / 96 Fighting Layout Bugs – QCon London 2010

  51. SimpleEdgeDetector in action 51 / 96 Fighting Layout Bugs – QCon London 2010

  52. SimpleEdgeDetector in action 52 / 96 Fighting Layout Bugs – QCon London 2010

  53. SimpleEdgeDetector in action 53 / 96 Fighting Layout Bugs – QCon London 2010

  54. SimpleEdgeDetector in action 54 / 96 Fighting Layout Bugs – QCon London 2010

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend