SlideShare a Scribd company logo
1 of 20
Download to read offline
Visual Testing
Using PhantomCss
Vishnu Narang
@vishnu_narang
Shridhar Deshmukh
@_shree33
Why did we use it?
What was our use case?
Our use case.
● We are on a project, working on a multi-national,
multi locale marketing website. Each page of the
website is made up of modules. Each module can be
used on many pages with different content.
● Recently, we got a unique requirement. We needed to
go live in middle-east countries for which we needed
to support Right-to-Left (RTL) languages like Arabic.
Our use case. ..cont
● Not only does the content flow from right to left,
even the layout and the interactions needed to flow
from right to left.
● Obviously, we needed to change lots of CSS/HTML in
our common code to support this.
While implementing this, we realised one thing...
breaking CSS is easy, testing it is hard.
Breaking css is easy, testing it is hard...
● Every time you make a change in common css code for a
website, you always have the possibility that something else
breaks on some other page.
● In our case, changing css for RTL for some module sometimes
broke it’s LTR variation on some pages.
● We had to plan a CSS testing strategy.
CSS testing options..
● Jasmine:
We used jasmine for our javascript tests. But nothing stopped us from using it for CSS
“Unit” tests.
We would only test the following for elements:
○ Is it floated Left or Right
eg: expect($el).toHaveCss({float: right});
○ Does it have Left: auto or greater than zero.
eg: expect($el).toHaveCss({left: auto});
○ Is it on the left or right of another element.
eg: expect(rightElOffset).toBeGreaterThan(leftElOffset); right Element
(rightEl)
left Element
(leftEl)
$el(left: auto)
$el
What is PhantomCss?
● Tool for Automated Visual Testing.
● Used for Web Apps, Live style guides and
responsive layouts.
How it works?
● PhantomJs for headless webkit.
● CasperJs for screenshots.
● ResembleJs for image comparison.
Example
padding: 11px 19px; padding: 11px 20px;
Installation (based on Mac OS)
npm install phantomjs
...And start visual regression testing
git clone https://github.com/Huddle/PhantomCSS.git
brew install casperjs
● Layout related issues.
Demo
Demo
● Layout related issues.
● Selector based tests.
● Layout related issues.
● Selector based tests.
● Action based tests.
Demo
Best Practices
● Name your screenshots carefully
● Use same OS/Browser for both runs
● Test only when you need
● Don’t always take fullpage screenshots
When not to use it?
● Right at the start of your project when the
pages keep changing.
● On a small project with very few pages.
● When you have a better tool to do your
job.
Advanced Features
● Making it deterministic using network
monitoring and wait time. (github.gist)
● Parallel execution using multi-threading
(sbt) + PhantomCss
References & Resources
● Official Repo: https://github.com/Huddle/PhantomCSS
● Our Modified version:
https://github.com/vishnun/visual_testing_using_phantomcss
● github gist for network monitoring:
https://gist.github.com/vishnun/23c66b0bc6b6194cf5cc
● More tools and wrappers:
grunt-phantomcss, PhantomXHR, PhantomFlow and grunt-
phantomflow.
THANKS
Youtube Video of this talk.

More Related Content

Viewers also liked (8)

TDC 2014 SP - Visual Regression Testing com PhantomCSS
TDC 2014 SP - Visual Regression Testing com PhantomCSSTDC 2014 SP - Visual Regression Testing com PhantomCSS
TDC 2014 SP - Visual Regression Testing com PhantomCSS
 
AngularJS Best Practices
AngularJS Best PracticesAngularJS Best Practices
AngularJS Best Practices
 
Kavya Prasad_Resume
Kavya Prasad_ResumeKavya Prasad_Resume
Kavya Prasad_Resume
 
PradeepKumar_Tableau Developer
PradeepKumar_Tableau DeveloperPradeepKumar_Tableau Developer
PradeepKumar_Tableau Developer
 
Naveen QlikView Developer
Naveen QlikView DeveloperNaveen QlikView Developer
Naveen QlikView Developer
 
Jagannath cv
Jagannath cvJagannath cv
Jagannath cv
 
Resume_Ganesh_updated
Resume_Ganesh_updatedResume_Ganesh_updated
Resume_Ganesh_updated
 
RESUME_TEJA
RESUME_TEJARESUME_TEJA
RESUME_TEJA
 

Similar to Visual testing using PhantomCss

Responsive web design & mobile web development - a technical and business app...
Responsive web design & mobile web development - a technical and business app...Responsive web design & mobile web development - a technical and business app...
Responsive web design & mobile web development - a technical and business app...
Atos_Worldline
 
Responsive, adaptive and responsible - keynote at NebraskaJS
Responsive, adaptive and responsible - keynote at NebraskaJSResponsive, adaptive and responsible - keynote at NebraskaJS
Responsive, adaptive and responsible - keynote at NebraskaJS
Christian Heilmann
 

Similar to Visual testing using PhantomCss (20)

"Crafting a Third-Party Banking Library with Web Components and React", Germa...
"Crafting a Third-Party Banking Library with Web Components and React", Germa..."Crafting a Third-Party Banking Library with Web Components and React", Germa...
"Crafting a Third-Party Banking Library with Web Components and React", Germa...
 
Web Development: Making it the right way
Web Development: Making it the right wayWeb Development: Making it the right way
Web Development: Making it the right way
 
Hybrid Application Development
Hybrid Application DevelopmentHybrid Application Development
Hybrid Application Development
 
Web II - 01 - Introduction to server-side development
Web II - 01 - Introduction to server-side developmentWeb II - 01 - Introduction to server-side development
Web II - 01 - Introduction to server-side development
 
Use React tools for better Angular apps
Use React tools for better Angular appsUse React tools for better Angular apps
Use React tools for better Angular apps
 
Xlab #2: wzorce projektowe
Xlab #2: wzorce projektoweXlab #2: wzorce projektowe
Xlab #2: wzorce projektowe
 
Intro to Flutter
Intro to FlutterIntro to Flutter
Intro to Flutter
 
React Workshop
React WorkshopReact Workshop
React Workshop
 
Html 5 mobile - nitty gritty
Html 5 mobile - nitty grittyHtml 5 mobile - nitty gritty
Html 5 mobile - nitty gritty
 
Javascript
JavascriptJavascript
Javascript
 
Quo vadis, JavaScript? Devday.pl keynote
Quo vadis, JavaScript? Devday.pl keynoteQuo vadis, JavaScript? Devday.pl keynote
Quo vadis, JavaScript? Devday.pl keynote
 
Responsive web design & mobile web development - a technical and business app...
Responsive web design & mobile web development - a technical and business app...Responsive web design & mobile web development - a technical and business app...
Responsive web design & mobile web development - a technical and business app...
 
Skill Session - Web Multi Device
Skill Session - Web Multi DeviceSkill Session - Web Multi Device
Skill Session - Web Multi Device
 
GWT Reloaded
GWT ReloadedGWT Reloaded
GWT Reloaded
 
Six reasons to learn JavaScript
Six reasons to learn JavaScriptSix reasons to learn JavaScript
Six reasons to learn JavaScript
 
Beyond the Standards
Beyond the StandardsBeyond the Standards
Beyond the Standards
 
Js basics
Js basicsJs basics
Js basics
 
Angular Vienna - Use React tools for better Angular apps
Angular Vienna - Use React tools for better Angular appsAngular Vienna - Use React tools for better Angular apps
Angular Vienna - Use React tools for better Angular apps
 
Responsive, adaptive and responsible - keynote at NebraskaJS
Responsive, adaptive and responsible - keynote at NebraskaJSResponsive, adaptive and responsible - keynote at NebraskaJS
Responsive, adaptive and responsible - keynote at NebraskaJS
 
Testing Angular 2 Applications - Rich Web 2016
Testing Angular 2 Applications - Rich Web 2016Testing Angular 2 Applications - Rich Web 2016
Testing Angular 2 Applications - Rich Web 2016
 

Recently uploaded

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Recently uploaded (20)

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 

Visual testing using PhantomCss

  • 1. Visual Testing Using PhantomCss Vishnu Narang @vishnu_narang Shridhar Deshmukh @_shree33
  • 2. Why did we use it? What was our use case?
  • 3. Our use case. ● We are on a project, working on a multi-national, multi locale marketing website. Each page of the website is made up of modules. Each module can be used on many pages with different content. ● Recently, we got a unique requirement. We needed to go live in middle-east countries for which we needed to support Right-to-Left (RTL) languages like Arabic.
  • 4. Our use case. ..cont ● Not only does the content flow from right to left, even the layout and the interactions needed to flow from right to left. ● Obviously, we needed to change lots of CSS/HTML in our common code to support this. While implementing this, we realised one thing...
  • 5. breaking CSS is easy, testing it is hard.
  • 6. Breaking css is easy, testing it is hard... ● Every time you make a change in common css code for a website, you always have the possibility that something else breaks on some other page. ● In our case, changing css for RTL for some module sometimes broke it’s LTR variation on some pages. ● We had to plan a CSS testing strategy.
  • 7. CSS testing options.. ● Jasmine: We used jasmine for our javascript tests. But nothing stopped us from using it for CSS “Unit” tests. We would only test the following for elements: ○ Is it floated Left or Right eg: expect($el).toHaveCss({float: right}); ○ Does it have Left: auto or greater than zero. eg: expect($el).toHaveCss({left: auto}); ○ Is it on the left or right of another element. eg: expect(rightElOffset).toBeGreaterThan(leftElOffset); right Element (rightEl) left Element (leftEl) $el(left: auto) $el
  • 8. What is PhantomCss? ● Tool for Automated Visual Testing. ● Used for Web Apps, Live style guides and responsive layouts.
  • 9. How it works? ● PhantomJs for headless webkit. ● CasperJs for screenshots. ● ResembleJs for image comparison.
  • 10. Example padding: 11px 19px; padding: 11px 20px;
  • 11. Installation (based on Mac OS) npm install phantomjs ...And start visual regression testing git clone https://github.com/Huddle/PhantomCSS.git brew install casperjs
  • 12. ● Layout related issues. Demo
  • 13. Demo ● Layout related issues. ● Selector based tests.
  • 14. ● Layout related issues. ● Selector based tests. ● Action based tests. Demo
  • 15. Best Practices ● Name your screenshots carefully ● Use same OS/Browser for both runs ● Test only when you need ● Don’t always take fullpage screenshots
  • 16. When not to use it? ● Right at the start of your project when the pages keep changing. ● On a small project with very few pages. ● When you have a better tool to do your job.
  • 17. Advanced Features ● Making it deterministic using network monitoring and wait time. (github.gist) ● Parallel execution using multi-threading (sbt) + PhantomCss
  • 18.
  • 19. References & Resources ● Official Repo: https://github.com/Huddle/PhantomCSS ● Our Modified version: https://github.com/vishnun/visual_testing_using_phantomcss ● github gist for network monitoring: https://gist.github.com/vishnun/23c66b0bc6b6194cf5cc ● More tools and wrappers: grunt-phantomcss, PhantomXHR, PhantomFlow and grunt- phantomflow.

Editor's Notes

  1. Talk about the two things to test: Unit tests using Jasmine and Regression testing using screenshot comparison.
  2. PhantomCss is command line tools that can be used to automate the visual regression testing. In this process PhantomCss visits the specified web pages and take snapshots of them, may be at different viewport sizes. And then It compares these images with your baseline images that were taken before you made any changes in CSS. The images are compared pixel by pixel to determine if their is any difference between baseline image and newly taken image. For failed comparison PhantomCss creates comparison image which highlights the portion of images which actually got changed in newer snapshot. You can use PhantomCss to test your web app, if you are making any major refactoring around your css. You can also use PhantomCss to make sure that the change that you made for desktop breakpoint is not breaking mobile or tablet layout. With phantomCss you compare whole page with another page, and you can also compare part/section of page.
  3. PhantomCss is a combination of 3 different tools Phantom Js - is a headless webkit browser that allows you to render web pages Casper Js - A Navigation and scripting tool that allows you to interact with the page rendered by phantomJs Resembe Js - compares two images pixel by pixel and determine the differences between them