SlideShare a Scribd company logo
Frontend automation and stability
@matenadasdi
Ustream, Inc
Common sentences from the past
Writing tests is a huge overhead
Browsers are unpredictable and we are not able to test real behaviour
Let’s write this frontend task in PHP, Ruby, Python, Bash …
Selenium is unstable and complicated
“
It’s a new ERA
Let’s ride it!
Testing
!
Trendy question:
TDD is dead?
</flame>
TDD/BDD/HDD/DVD…
It doesn’t matter,
Testing is a must in large scale!
Good news! We have everything what we need
Hundreds of tools and frameworks - Mocha, Jasmine, Jest, Karma, QUnit
Headless browsers - PhantomJS, SlimerJS, TrifleJS
Headless navigation scripting libs - CasperJS, DalekJS
Our setup at
1. Unit testing
Criterions for efficient unit testing
Separated layers with different responsibilities for easier mocking
Business Logic and the representation have to be separated
Dependency Injection
Mocha + Chai
framework:
Node and Browser support
Separate assert libraries
Tons of reporters
mocking:
SinonJS
Spies, Stubs, Mocks
Assertions for invocations
Faking AJAX, server
Works with lot of frameworks
module dependency mocking:
SquireJS
Dependency injector for RequireJS
mock / store
It’s not an overhead, easy to run and write!
Coverage?
function coverage
function epam (speaker, onStage)
{
var talking = false;
!
if (speaker && onStage){
talking = true;
}
!
return talking;
}
if epam called once, its covered
statement coverage
function epam (speaker, onStage)
{
var talking = false;
!
if (speaker && onStage){
talking = true;
}
!
return talking;
}
with testing epam(true, true),
all statement will be executed,
so its covered
branch coverage
function epam (speaker, onStage)
{
var talking = false;
!
if (speaker && onStage){
talking = true;
}
!
return talking;
}
with testing
epam(true, true), and epam (true, false)
all execution paths will be covered
Ok it’s nice, but is it possible in JS?
;)
Istanbul
https://github.com/gotwarlost/istanbul
Esprima based
statement, branch, function coverage
multiple reporters
command line support
Karma test runner
http://karma-runner.github.io/0.12/index.html
+
WebStorm integration
Istanbul code coverage support
Mocha, Jasmine, QUnit support
Jenkins, Travis support
Unit tests cannot cover everything!
Browser / DOM / Interaction specific behaviour
should be tested in a different way
2. UI testing
The genie is out of the bottle
Navigation scripting in Node
We use CasperJS
Node.js based navigation scripting
PhantomJS & SlimerJS support
screenshot capture
not necessary to use its testing framework
Pro:
phantomjs based browsers only
Cons:
This is Node, you can do everything!
Create your own modules
you can call global casper from everywhere
DalekJS is coming up!
Real browser support
Chrome, FF, IE, Mobile Safari
It can run in headless browsers too
Pro:
strict testing framework interface
small documentation and not enough methods
still developer preview (0.0.8)
Cons:
3. Test automation team
selenium, real browsers, complex features, mobile devices
4. Manual QA team
Smoke tests, regression tests, screenshot comparison tool, internal debug tools
Automation
We picked Grunt
NPM for dependency management
we could port every frontend related task to Node
we use 12 grunt plugins (2800+ available globally)
be careful, lot of tasks can lead to a huge/complex grunt file
we have an own structure for task configurations
Thanks to Grunt...
Why not Gulp?
a bad question
Node streams are awesome, but it can be hard for non-js devs
Code over configuration
713 plugins and coming up really fast
Try both, and maybe use both!
Gulp is good tool too!
Standards & Rules
!
Our previous setup was too simple
JSLint manually (!)
YuiCompressor after commits in Jenkins
Rules are not rules if you break them!
Everyone writes different code
and it’s normal
Code style! Be aggressive!
a smarter JSLint
separated configuration file
everyone can run the same config
most IDEs can read it globally
Esprima!!!!!!!!!!!!!!!!!!!!!!!!!!44
https://github.com/ariya/esprima
more possibilities with
{
"type": "Program",
"body": [{
"type": "IfStatement",
"test": {
"type": "Identifier",
"name": "epam"
},
“consequent": {
"type": "BlockStatement",
"body": [{
"type": "ExpressionStatement",
"expression": {
"type": "AssignmentExpression",
"operator": "=",
"left": {
"type": "Identifier",
"name": "conf"
},
"right": {
"type": "Literal",
"value": "SEC",
"raw": "'SEC'"
}
}
}]
},
"alternate": null
}]
var epam = true;
!
if (epam) {
conf = 'SEC';
}
Semantics & your own rules
Esprima based
pluginable
thanks to the AST it can examine semantics
Esprima based rule definitions
Complexity report
Does it matter?
Who wouldn’t wanna track these?
http://jscomplexity.org/complexity
Lines of code (LOC)
Halstead complexity measures
Maintainability index
Cyclomatic complexity
Cyclomatic complexity = E - N + 2P
linearly independent paths in the method
E = number of edges in the flow graph
N = number of nodes in the flow graph
P = number of nodes that have exit points
6 -6 + 2 = 2
JSComplexity & Plato
We run complexity report in Jenkins nightly build for our whole JS codebase
https://www.npmjs.org/package/complexity-report
Plato is a great tool for manual examinations
https://github.com/es-analysis/plato
Frontend automation and stability
CI Integration
CI can run your tools automatically and periodically
It can catch accidental commits
Nearly every grunt plugin supports .xml reporters
this 3 simple things
can lead to a more stable and scalable JS codebase
Testing Automation Standards & rules
!
Thank you!
Questions?
!
!
@matenadasdi

More Related Content

PDF
Web Development syllabus
DOCX
PRIYANKA Resume
PPTX
Windows registry гэж юу вэ?
PPTX
Web Application Testing
PPTX
Front end Tips Tricks & Tools
PDF
Sinau Bareng Frontend Web Development @ DiLo Malang
PDF
Front End Tooling and Performance - Codeaholics HK 2015
PDF
User eXperience & Front End Development
Web Development syllabus
PRIYANKA Resume
Windows registry гэж юу вэ?
Web Application Testing
Front end Tips Tricks & Tools
Sinau Bareng Frontend Web Development @ DiLo Malang
Front End Tooling and Performance - Codeaholics HK 2015
User eXperience & Front End Development

Viewers also liked (20)

PDF
Webinar: Front End Web Development - Trendy Web Designs Using HTML5
PDF
Frontend SPOF
PDF
Architecting your Frontend
PDF
建立前端开发团队 (Front-end Development Environment)
PDF
Grunt js for the Enterprise Vol.1: Frontend Performance with Phantomas
PDF
Wrangling Large Scale Frontend Web Applications
PDF
A modern front end development workflow for Magnolia at Atlassian
PDF
How to Build Front-End Web Apps that Scale - FutureJS
PPTX
Frontend technologies
PPTX
W3 conf hill-html5-security-realities
PDF
Frontend at Scale - The Tumblr Story
PPTX
Modern Frontend Technology
PDF
TechTalk #85 : Latest Frontend Technologies
PDF
Front End Development Workflow Tools
PDF
The Frontend Developer Landscape Explained and the Rise of Advanced Frontend ...
PDF
engage 2015 - Domino App Development - Where should I go now?
PDF
Front End Development - Beyond Javascript (Robin Cannon)
PDF
Modern front end development
PPT
Scaling Front-End Performance - Velocity 2016
PDF
7 grzechów głównych - frontend i design
Webinar: Front End Web Development - Trendy Web Designs Using HTML5
Frontend SPOF
Architecting your Frontend
建立前端开发团队 (Front-end Development Environment)
Grunt js for the Enterprise Vol.1: Frontend Performance with Phantomas
Wrangling Large Scale Frontend Web Applications
A modern front end development workflow for Magnolia at Atlassian
How to Build Front-End Web Apps that Scale - FutureJS
Frontend technologies
W3 conf hill-html5-security-realities
Frontend at Scale - The Tumblr Story
Modern Frontend Technology
TechTalk #85 : Latest Frontend Technologies
Front End Development Workflow Tools
The Frontend Developer Landscape Explained and the Rise of Advanced Frontend ...
engage 2015 - Domino App Development - Where should I go now?
Front End Development - Beyond Javascript (Robin Cannon)
Modern front end development
Scaling Front-End Performance - Velocity 2016
7 grzechów głównych - frontend i design
Ad

Similar to Frontend automation and stability (20)

PDF
Ustream vs Legacy, It's never too late to start your fight! #Jsist 2014
PPTX
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
PDF
3 WAYS TO TEST YOUR COLDFUSION API
PDF
3 WAYS TO TEST YOUR COLDFUSION API -
PDF
How do I Write Testable Javascript so I can Test my CF API on Server and Client
PPTX
How do I write Testable Javascript so I can Test my CF API on Server and Client
PDF
Node.js Development Workflow Automation with Grunt.js
PPTX
Java script unit testing
PDF
How to write Testable Javascript
PDF
How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016
PPTX
Testing nodejs apps
PDF
JavaScript TDD with Jasmine and Karma
PDF
JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"
PDF
Quick tour to front end unit testing using jasmine
PDF
Automated Web Testing using JavaScript
PDF
JavaScript Test-Driven Development with Jasmine 2.0 and Karma
PPTX
TDD and the Legacy Code Black Hole
PDF
Testing in FrontEnd World by Nikita Galkin
PDF
JAVASCRIPT TDD(Test driven Development) & Qunit Tutorial
PPTX
Automated Testing using JavaScript
Ustream vs Legacy, It's never too late to start your fight! #Jsist 2014
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
3 WAYS TO TEST YOUR COLDFUSION API
3 WAYS TO TEST YOUR COLDFUSION API -
How do I Write Testable Javascript so I can Test my CF API on Server and Client
How do I write Testable Javascript so I can Test my CF API on Server and Client
Node.js Development Workflow Automation with Grunt.js
Java script unit testing
How to write Testable Javascript
How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016
Testing nodejs apps
JavaScript TDD with Jasmine and Karma
JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"
Quick tour to front end unit testing using jasmine
Automated Web Testing using JavaScript
JavaScript Test-Driven Development with Jasmine 2.0 and Karma
TDD and the Legacy Code Black Hole
Testing in FrontEnd World by Nikita Galkin
JAVASCRIPT TDD(Test driven Development) & Qunit Tutorial
Automated Testing using JavaScript
Ad

Recently uploaded (20)

PPTX
Spectroscopy.pptx food analysis technology
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Approach and Philosophy of On baking technology
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Encapsulation theory and applications.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Electronic commerce courselecture one. Pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
Spectroscopy.pptx food analysis technology
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Approach and Philosophy of On baking technology
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
The AUB Centre for AI in Media Proposal.docx
Encapsulation_ Review paper, used for researhc scholars
Encapsulation theory and applications.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Understanding_Digital_Forensics_Presentation.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Electronic commerce courselecture one. Pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Digital-Transformation-Roadmap-for-Companies.pptx
MYSQL Presentation for SQL database connectivity
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Programs and apps: productivity, graphics, security and other tools

Frontend automation and stability

  • 1. Frontend automation and stability @matenadasdi Ustream, Inc
  • 2. Common sentences from the past Writing tests is a huge overhead Browsers are unpredictable and we are not able to test real behaviour Let’s write this frontend task in PHP, Ruby, Python, Bash … Selenium is unstable and complicated “
  • 3. It’s a new ERA Let’s ride it!
  • 5. ! Trendy question: TDD is dead? </flame>
  • 7. Good news! We have everything what we need Hundreds of tools and frameworks - Mocha, Jasmine, Jest, Karma, QUnit Headless browsers - PhantomJS, SlimerJS, TrifleJS Headless navigation scripting libs - CasperJS, DalekJS
  • 10. Criterions for efficient unit testing Separated layers with different responsibilities for easier mocking Business Logic and the representation have to be separated Dependency Injection
  • 11. Mocha + Chai framework: Node and Browser support Separate assert libraries Tons of reporters mocking: SinonJS Spies, Stubs, Mocks Assertions for invocations Faking AJAX, server Works with lot of frameworks module dependency mocking: SquireJS Dependency injector for RequireJS mock / store
  • 12. It’s not an overhead, easy to run and write!
  • 13. Coverage? function coverage function epam (speaker, onStage) { var talking = false; ! if (speaker && onStage){ talking = true; } ! return talking; } if epam called once, its covered statement coverage function epam (speaker, onStage) { var talking = false; ! if (speaker && onStage){ talking = true; } ! return talking; } with testing epam(true, true), all statement will be executed, so its covered branch coverage function epam (speaker, onStage) { var talking = false; ! if (speaker && onStage){ talking = true; } ! return talking; } with testing epam(true, true), and epam (true, false) all execution paths will be covered
  • 14. Ok it’s nice, but is it possible in JS? ;)
  • 15. Istanbul https://github.com/gotwarlost/istanbul Esprima based statement, branch, function coverage multiple reporters command line support Karma test runner http://karma-runner.github.io/0.12/index.html + WebStorm integration Istanbul code coverage support Mocha, Jasmine, QUnit support Jenkins, Travis support
  • 16. Unit tests cannot cover everything! Browser / DOM / Interaction specific behaviour should be tested in a different way
  • 17. 2. UI testing The genie is out of the bottle
  • 19. We use CasperJS Node.js based navigation scripting PhantomJS & SlimerJS support screenshot capture not necessary to use its testing framework Pro: phantomjs based browsers only Cons:
  • 20. This is Node, you can do everything! Create your own modules you can call global casper from everywhere
  • 21. DalekJS is coming up! Real browser support Chrome, FF, IE, Mobile Safari It can run in headless browsers too Pro: strict testing framework interface small documentation and not enough methods still developer preview (0.0.8) Cons:
  • 22. 3. Test automation team selenium, real browsers, complex features, mobile devices
  • 23. 4. Manual QA team Smoke tests, regression tests, screenshot comparison tool, internal debug tools
  • 26. NPM for dependency management we could port every frontend related task to Node we use 12 grunt plugins (2800+ available globally) be careful, lot of tasks can lead to a huge/complex grunt file we have an own structure for task configurations Thanks to Grunt...
  • 27. Why not Gulp? a bad question
  • 28. Node streams are awesome, but it can be hard for non-js devs Code over configuration 713 plugins and coming up really fast Try both, and maybe use both! Gulp is good tool too!
  • 30. Our previous setup was too simple JSLint manually (!) YuiCompressor after commits in Jenkins
  • 31. Rules are not rules if you break them!
  • 32. Everyone writes different code and it’s normal
  • 33. Code style! Be aggressive! a smarter JSLint separated configuration file everyone can run the same config most IDEs can read it globally
  • 35. { "type": "Program", "body": [{ "type": "IfStatement", "test": { "type": "Identifier", "name": "epam" }, “consequent": { "type": "BlockStatement", "body": [{ "type": "ExpressionStatement", "expression": { "type": "AssignmentExpression", "operator": "=", "left": { "type": "Identifier", "name": "conf" }, "right": { "type": "Literal", "value": "SEC", "raw": "'SEC'" } } }] }, "alternate": null }] var epam = true; ! if (epam) { conf = 'SEC'; }
  • 36. Semantics & your own rules Esprima based pluginable thanks to the AST it can examine semantics
  • 37. Esprima based rule definitions
  • 39. Who wouldn’t wanna track these? http://jscomplexity.org/complexity Lines of code (LOC) Halstead complexity measures Maintainability index Cyclomatic complexity
  • 40. Cyclomatic complexity = E - N + 2P linearly independent paths in the method E = number of edges in the flow graph N = number of nodes in the flow graph P = number of nodes that have exit points 6 -6 + 2 = 2
  • 41. JSComplexity & Plato We run complexity report in Jenkins nightly build for our whole JS codebase https://www.npmjs.org/package/complexity-report Plato is a great tool for manual examinations https://github.com/es-analysis/plato
  • 43. CI Integration CI can run your tools automatically and periodically It can catch accidental commits Nearly every grunt plugin supports .xml reporters
  • 44. this 3 simple things can lead to a more stable and scalable JS codebase Testing Automation Standards & rules !