SlideShare une entreprise Scribd logo
1  sur  34
Михаил Боднарчук
Codegyre
Acceptance Testing in NodeJS
1
Who Am I
Michael Bodnarchuk
@davert
PHP, Ruby, JS developer from Kyiv, Ukraine
Creator of testing frameworks Codeception (PHP), CodeceptJS (Node)
2
What is Acceptance Testing
End-2-End, functional, etc
3
An App:
4
What’s inside a box?
5
Interface
6
GET A CHOCOLATE!!!
Secured. No Credit Card Required. Free for
OpenSource. Moneyback Guarantee.
Just click this f*ckn green button!
pleeeeease….
Made with Love by Willy Wonka
What should we test?
7
Chocolate Factory (unit/integration) - make a chocolate
Interface (acceptance/e2e) - user can get a chocolate
Who should write tests?
8
Unit/Integration -
Developers
Acceptance -
QA Engineers
We are developers!
Let’s leave testing to QAs
9
THE END
Thank you
10
Well-tested software is a product
of collaboration
11
Do it as team!
NodeJS for Test Automation Engineers (QA):
12
JavaScript???
How to deal with async?
Which tools to use?
How to test Single Page applications?
Using locators in dynamic HTML
Tools for Acceptance Testing
Selenium Webdriver
PhantomJS
Nightmare
ZombieJS
13
Automating Browser with Selenium
14
How to deal with
Locating Elements
Single Page Applications
Cloud Testing
Data In Tests
15
Locating Elements
“Hey, click me that green button”!
By CSS (JQuery style)
By XPath (Most flexible)
By Link Text
Reuse locators in PageObjects
16
GET A CHOCOLATE!!!
Secured. No Credit Card Required.
Single Page Applications
Browser automation faster than user
DOMReady vs “‘I’ve done it, master!”
Before each step:
executeAsync((done) => waitToRender(done))
17
Cloud Testing (SauceLabs, BrowserStack, TestingBot)
Testing app on different platforms (Windows, OSX)
Mobile testing (on real devices)
In different browsers (IE8+, FF, Opera, Safari)
Through Tunnels
Via WebDriver protocol 18
From 29$/month
Slower than local testing
Data overhead
Data in Tests
Isolation: Data should be cleaned between tests
Create/Delete all data inside a test
Loading fixtures into database
Loading database dump
Created/Deleted via API 19
Testing Emails
Open Gmail in next tab, click the latest email….
Use MailDev, MailCatcher, MailHog, MailTrap
Check sent emails via REST API
20
Libraries for Acceptance Testing
Selenium Webdriver JS
webdriverio
Protractor
Intern
Nightmare
21
NightwatchJS
CodeceptJS
WD.js
...
Different Bindings, Different APIs
client // webdriverio
.init()
.url('https://localhost/')
.setValue('input[name=login], 'john')
.setValue('input[name=password], '123456')
.click('input[type=submit]')
.getText('.welcome').then(function(text) {
return assert(text, 'Welcome');
});
driver.get('http://localhost/'); // Protractor
driver.findElement(protractor.By.name('login'))
.sendKeys('john');
driver.findElement(protractor.By.name('password'))
.sendKeys(‘123456’);
22
client // NightwatchJS
.url('http://localhost.com')
.setValue('input[type=login]', 'john')
.setValue('input[type=password]', '123456)
.click('button[type=submit]')
.assert.containsText('.welcome','Welcome')
.end();
How to choose?
Investigate, check your requirements
23
Choosing Library
24
Best docs, flexible API, synchronous ⇒ webdriverio
Java-like official Selenium library ⇒ Selenium WebdriverJS
For AngularJS ⇒ Protractor
Most featured ⇒ NightwatchJS
Acceptance Testing + Unit Testing ⇒ Intern
CodeceptJS
to rule them all
25
CodeceptJS
One framework using other libraries
Synchronous (not really, uses global promise)
Scenario Driven
With PageObjects, Interactive Shell, Error output... 26
Synchronous looking Test
Scenario('log in as user', (I) => {
I.amOnPage('/');
I.click('Login');
I.fillField('Username', 'john');
I.fillField('Password', '123456');
I.click('Enter');
I.see('Welcome');
}
27
// assertion from webdriverio helper
see(text) {
return this.browser.getText()
.then(function (source) {
return stringIncludes()[assertType](text, source);
});
// action from webdriverio helper
click(locator, context) {
let client = this.browser;
let clickMethod = this.browser.isMobile ? 'touchClick' : 'elementIdClick';
if (context) {
client = client.element(context);
}
return findClickable(client, locator).then(function (res) {
if (!res.value || res.value.length === 0) {
if (typeof(locator) === "object") locator = JSON.stringify(locator);
throw new Error(`Clickable element ${locator.toString()} was not found
by text|CSS|XPath`);
}
let elem = res.value[0];
return this[clickMethod](elem.ELEMENT);
});
}
// adding to global promise
recorder.addStep(new Step(helper, action), args);
return recorder.promise();
Scenario Driven: Executed Step by Step
• I am on page ‘/’
• I fill field ‘Username’, ‘john’
• I fill field ‘Password’, ‘123456’
• I click ‘Enter’
• I see ‘Welcome’
✓OK
28
Interactive Shell
29
PageObject, PageFragment
Scenario('log in as user', (I, loginPage) => {
loginPage.logInWith('john', '123456');
I.see('Welcome');
}
30
Automatically Injected
(angular-style)
// Login steps moved to loginPage:
logInWith(name, pass) {
I.amOnPage('/');
I.click('Login');
I.fillField('Username', name);
I.fillField('Password', pass);
I.click('Enter');
}
And….
Based on Mocha testing framework.
Designed for scenario driven acceptance testing in BDD-style
Uses ES6 natively without transpiler.
Selenium WebDriver integration using webdriverio (..Protractor, Nigthmare)
Easily create tests, pageobjects, stepobjects with CLI generators.
31
Try CodeceptJS today!
http://codecept.io
npm install -g codeceptjs
@codeceptjs
Author: Michael Bodnarchuk @davert 32
Conclusions
Acceptance Testing should be done by developers and QAs
Use the same language for code and tests
NodeJS browser testing is hard (various libraries, async)
Use REST API for data, fetching emails, etc
Use CodeceptJS
33
Questions?
Michael Bodnarchuk
Follow me: @davert
https://github.com/codeception/codeceptjs
http://codecept.io
34

Contenu connexe

Tendances

Tendances (20)

Play with Angular JS
Play with Angular JSPlay with Angular JS
Play with Angular JS
 
Protractor overview
Protractor overviewProtractor overview
Protractor overview
 
Webdriver cheatsheets summary
Webdriver cheatsheets summaryWebdriver cheatsheets summary
Webdriver cheatsheets summary
 
Efficient JavaScript Unit Testing, May 2012
Efficient JavaScript Unit Testing, May 2012Efficient JavaScript Unit Testing, May 2012
Efficient JavaScript Unit Testing, May 2012
 
Take Control of your Integration Testing with TestContainers
Take Control of your Integration Testing with TestContainersTake Control of your Integration Testing with TestContainers
Take Control of your Integration Testing with TestContainers
 
Angular Application Testing
Angular Application TestingAngular Application Testing
Angular Application Testing
 
Automated Web Testing using JavaScript
Automated Web Testing using JavaScriptAutomated Web Testing using JavaScript
Automated Web Testing using JavaScript
 
A Closer Look At React Native
A Closer Look At React NativeA Closer Look At React Native
A Closer Look At React Native
 
JavaScript + Jenkins = Winning!
JavaScript + Jenkins = Winning!JavaScript + Jenkins = Winning!
JavaScript + Jenkins = Winning!
 
Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...
Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...
Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...
 
Angular1x and Angular 2 for Beginners
Angular1x and Angular 2 for BeginnersAngular1x and Angular 2 for Beginners
Angular1x and Angular 2 for Beginners
 
ReactJS vs AngularJS - Head to Head comparison
ReactJS vs AngularJS - Head to Head comparisonReactJS vs AngularJS - Head to Head comparison
ReactJS vs AngularJS - Head to Head comparison
 
Gems Of Selenium
Gems Of SeleniumGems Of Selenium
Gems Of Selenium
 
Front-End Testing: Demystified
Front-End Testing: DemystifiedFront-End Testing: Demystified
Front-End Testing: Demystified
 
2015 in tothebox-introtddbdd
2015 in tothebox-introtddbdd2015 in tothebox-introtddbdd
2015 in tothebox-introtddbdd
 
AngularJS + React
AngularJS + ReactAngularJS + React
AngularJS + React
 
DDD with Behat
DDD with BehatDDD with Behat
DDD with Behat
 
SQL or NoSQL - how to choose
SQL or NoSQL - how to chooseSQL or NoSQL - how to choose
SQL or NoSQL - how to choose
 
Automated Smoke Tests with Protractor
Automated Smoke Tests with ProtractorAutomated Smoke Tests with Protractor
Automated Smoke Tests with Protractor
 
Protractor end-to-end testing framework for angular js
Protractor   end-to-end testing framework for angular jsProtractor   end-to-end testing framework for angular js
Protractor end-to-end testing framework for angular js
 

Similaire à Михаил Боднарчук "Acceptance Testing in NodeJS: Tools & Approaches"

Using Selenium to Improve a Teams Development Cycle
Using Selenium to Improve a Teams Development CycleUsing Selenium to Improve a Teams Development Cycle
Using Selenium to Improve a Teams Development Cycle
seleniumconf
 
Philip Shurpik "Architecting React Native app"
Philip Shurpik "Architecting React Native app"Philip Shurpik "Architecting React Native app"
Philip Shurpik "Architecting React Native app"
Fwdays
 
Selenium withnet
Selenium withnetSelenium withnet
Selenium withnet
Vlad Maniak
 

Similaire à Михаил Боднарчук "Acceptance Testing in NodeJS: Tools & Approaches" (20)

Automated acceptance test
Automated acceptance testAutomated acceptance test
Automated acceptance test
 
Node.js and Selenium Webdriver, a journey from the Java side
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
 
Real-Time Communication Testing Evolution with WebRTC
Real-Time Communication Testing Evolution with WebRTCReal-Time Communication Testing Evolution with WebRTC
Real-Time Communication Testing Evolution with WebRTC
 
Automated Testing using JavaScript
Automated Testing using JavaScriptAutomated Testing using JavaScript
Automated Testing using JavaScript
 
Using Selenium to Improve a Teams Development Cycle
Using Selenium to Improve a Teams Development CycleUsing Selenium to Improve a Teams Development Cycle
Using Selenium to Improve a Teams Development Cycle
 
Selenium With Spices
Selenium With SpicesSelenium With Spices
Selenium With Spices
 
OWASP ZAP Workshop for QA Testers
OWASP ZAP Workshop for QA TestersOWASP ZAP Workshop for QA Testers
OWASP ZAP Workshop for QA Testers
 
Builda responsivetypescriptwebdriverio framework
Builda responsivetypescriptwebdriverio frameworkBuilda responsivetypescriptwebdriverio framework
Builda responsivetypescriptwebdriverio framework
 
Build a responsive typescript webdriverio framework
Build a responsive typescript webdriverio frameworkBuild a responsive typescript webdriverio framework
Build a responsive typescript webdriverio framework
 
Testcontainers - Geekout EE 2017 presentation
Testcontainers - Geekout EE 2017 presentationTestcontainers - Geekout EE 2017 presentation
Testcontainers - Geekout EE 2017 presentation
 
Coding Naked
Coding NakedCoding Naked
Coding Naked
 
Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)
 
Good practices for debugging Selenium and Appium tests
Good practices for debugging Selenium and Appium testsGood practices for debugging Selenium and Appium tests
Good practices for debugging Selenium and Appium tests
 
Binary Studio Academy: .NET Code Testing
Binary Studio Academy: .NET Code TestingBinary Studio Academy: .NET Code Testing
Binary Studio Academy: .NET Code Testing
 
Philip Shurpik "Architecting React Native app"
Philip Shurpik "Architecting React Native app"Philip Shurpik "Architecting React Native app"
Philip Shurpik "Architecting React Native app"
 
qooxdoo - Open Source Ajax Framework
qooxdoo - Open Source Ajax Frameworkqooxdoo - Open Source Ajax Framework
qooxdoo - Open Source Ajax Framework
 
Selenium withnet
Selenium withnetSelenium withnet
Selenium withnet
 
Integration tests: use the containers, Luke!
Integration tests: use the containers, Luke!Integration tests: use the containers, Luke!
Integration tests: use the containers, Luke!
 
NET Code Testing
NET Code TestingNET Code Testing
NET Code Testing
 
Test Automation Framework with BDD and Cucumber
Test Automation Framework with BDD and CucumberTest Automation Framework with BDD and Cucumber
Test Automation Framework with BDD and Cucumber
 

Plus de Fwdays

Plus de Fwdays (20)

"How Preply reduced ML model development time from 1 month to 1 day",Yevhen Y...
"How Preply reduced ML model development time from 1 month to 1 day",Yevhen Y..."How Preply reduced ML model development time from 1 month to 1 day",Yevhen Y...
"How Preply reduced ML model development time from 1 month to 1 day",Yevhen Y...
 
"GenAI Apps: Our Journey from Ideas to Production Excellence",Danil Topchii
"GenAI Apps: Our Journey from Ideas to Production Excellence",Danil Topchii"GenAI Apps: Our Journey from Ideas to Production Excellence",Danil Topchii
"GenAI Apps: Our Journey from Ideas to Production Excellence",Danil Topchii
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
"What is a RAG system and how to build it",Dmytro Spodarets
"What is a RAG system and how to build it",Dmytro Spodarets"What is a RAG system and how to build it",Dmytro Spodarets
"What is a RAG system and how to build it",Dmytro Spodarets
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
"Distributed graphs and microservices in Prom.ua", Maksym Kindritskyi
"Distributed graphs and microservices in Prom.ua",  Maksym Kindritskyi"Distributed graphs and microservices in Prom.ua",  Maksym Kindritskyi
"Distributed graphs and microservices in Prom.ua", Maksym Kindritskyi
 
"Rethinking the existing data loading and processing process as an ETL exampl...
"Rethinking the existing data loading and processing process as an ETL exampl..."Rethinking the existing data loading and processing process as an ETL exampl...
"Rethinking the existing data loading and processing process as an ETL exampl...
 
"How Ukrainian IT specialist can go on vacation abroad without crossing the T...
"How Ukrainian IT specialist can go on vacation abroad without crossing the T..."How Ukrainian IT specialist can go on vacation abroad without crossing the T...
"How Ukrainian IT specialist can go on vacation abroad without crossing the T...
 
"The Strength of Being Vulnerable: the experience from CIA, Tesla and Uber", ...
"The Strength of Being Vulnerable: the experience from CIA, Tesla and Uber", ..."The Strength of Being Vulnerable: the experience from CIA, Tesla and Uber", ...
"The Strength of Being Vulnerable: the experience from CIA, Tesla and Uber", ...
 
"[QUICK TALK] Radical candor: how to achieve results faster thanks to a cultu...
"[QUICK TALK] Radical candor: how to achieve results faster thanks to a cultu..."[QUICK TALK] Radical candor: how to achieve results faster thanks to a cultu...
"[QUICK TALK] Radical candor: how to achieve results faster thanks to a cultu...
 
"[QUICK TALK] PDP Plan, the only one door to raise your salary and boost care...
"[QUICK TALK] PDP Plan, the only one door to raise your salary and boost care..."[QUICK TALK] PDP Plan, the only one door to raise your salary and boost care...
"[QUICK TALK] PDP Plan, the only one door to raise your salary and boost care...
 
"4 horsemen of the apocalypse of working relationships (+ antidotes to them)"...
"4 horsemen of the apocalypse of working relationships (+ antidotes to them)"..."4 horsemen of the apocalypse of working relationships (+ antidotes to them)"...
"4 horsemen of the apocalypse of working relationships (+ antidotes to them)"...
 
"Reconnecting with Purpose: Rediscovering Job Interest after Burnout", Anast...
"Reconnecting with Purpose: Rediscovering Job Interest after Burnout",  Anast..."Reconnecting with Purpose: Rediscovering Job Interest after Burnout",  Anast...
"Reconnecting with Purpose: Rediscovering Job Interest after Burnout", Anast...
 
"Mentoring 101: How to effectively invest experience in the success of others...
"Mentoring 101: How to effectively invest experience in the success of others..."Mentoring 101: How to effectively invest experience in the success of others...
"Mentoring 101: How to effectively invest experience in the success of others...
 
"Mission (im) possible: How to get an offer in 2024?", Oleksandra Myronova
"Mission (im) possible: How to get an offer in 2024?",  Oleksandra Myronova"Mission (im) possible: How to get an offer in 2024?",  Oleksandra Myronova
"Mission (im) possible: How to get an offer in 2024?", Oleksandra Myronova
 
"Why have we learned how to package products, but not how to 'package ourselv...
"Why have we learned how to package products, but not how to 'package ourselv..."Why have we learned how to package products, but not how to 'package ourselv...
"Why have we learned how to package products, but not how to 'package ourselv...
 
"How to tame the dragon, or leadership with imposter syndrome", Oleksandr Zin...
"How to tame the dragon, or leadership with imposter syndrome", Oleksandr Zin..."How to tame the dragon, or leadership with imposter syndrome", Oleksandr Zin...
"How to tame the dragon, or leadership with imposter syndrome", Oleksandr Zin...
 

Dernier

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Dernier (20)

ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 

Михаил Боднарчук "Acceptance Testing in NodeJS: Tools & Approaches"

  • 2. Who Am I Michael Bodnarchuk @davert PHP, Ruby, JS developer from Kyiv, Ukraine Creator of testing frameworks Codeception (PHP), CodeceptJS (Node) 2
  • 3. What is Acceptance Testing End-2-End, functional, etc 3
  • 6. Interface 6 GET A CHOCOLATE!!! Secured. No Credit Card Required. Free for OpenSource. Moneyback Guarantee. Just click this f*ckn green button! pleeeeease…. Made with Love by Willy Wonka
  • 7. What should we test? 7 Chocolate Factory (unit/integration) - make a chocolate Interface (acceptance/e2e) - user can get a chocolate
  • 8. Who should write tests? 8 Unit/Integration - Developers Acceptance - QA Engineers
  • 9. We are developers! Let’s leave testing to QAs 9
  • 11. Well-tested software is a product of collaboration 11 Do it as team!
  • 12. NodeJS for Test Automation Engineers (QA): 12 JavaScript??? How to deal with async? Which tools to use? How to test Single Page applications? Using locators in dynamic HTML
  • 13. Tools for Acceptance Testing Selenium Webdriver PhantomJS Nightmare ZombieJS 13
  • 14. Automating Browser with Selenium 14
  • 15. How to deal with Locating Elements Single Page Applications Cloud Testing Data In Tests 15
  • 16. Locating Elements “Hey, click me that green button”! By CSS (JQuery style) By XPath (Most flexible) By Link Text Reuse locators in PageObjects 16 GET A CHOCOLATE!!! Secured. No Credit Card Required.
  • 17. Single Page Applications Browser automation faster than user DOMReady vs “‘I’ve done it, master!” Before each step: executeAsync((done) => waitToRender(done)) 17
  • 18. Cloud Testing (SauceLabs, BrowserStack, TestingBot) Testing app on different platforms (Windows, OSX) Mobile testing (on real devices) In different browsers (IE8+, FF, Opera, Safari) Through Tunnels Via WebDriver protocol 18 From 29$/month Slower than local testing Data overhead
  • 19. Data in Tests Isolation: Data should be cleaned between tests Create/Delete all data inside a test Loading fixtures into database Loading database dump Created/Deleted via API 19
  • 20. Testing Emails Open Gmail in next tab, click the latest email…. Use MailDev, MailCatcher, MailHog, MailTrap Check sent emails via REST API 20
  • 21. Libraries for Acceptance Testing Selenium Webdriver JS webdriverio Protractor Intern Nightmare 21 NightwatchJS CodeceptJS WD.js ...
  • 22. Different Bindings, Different APIs client // webdriverio .init() .url('https://localhost/') .setValue('input[name=login], 'john') .setValue('input[name=password], '123456') .click('input[type=submit]') .getText('.welcome').then(function(text) { return assert(text, 'Welcome'); }); driver.get('http://localhost/'); // Protractor driver.findElement(protractor.By.name('login')) .sendKeys('john'); driver.findElement(protractor.By.name('password')) .sendKeys(‘123456’); 22 client // NightwatchJS .url('http://localhost.com') .setValue('input[type=login]', 'john') .setValue('input[type=password]', '123456) .click('button[type=submit]') .assert.containsText('.welcome','Welcome') .end();
  • 23. How to choose? Investigate, check your requirements 23
  • 24. Choosing Library 24 Best docs, flexible API, synchronous ⇒ webdriverio Java-like official Selenium library ⇒ Selenium WebdriverJS For AngularJS ⇒ Protractor Most featured ⇒ NightwatchJS Acceptance Testing + Unit Testing ⇒ Intern
  • 26. CodeceptJS One framework using other libraries Synchronous (not really, uses global promise) Scenario Driven With PageObjects, Interactive Shell, Error output... 26
  • 27. Synchronous looking Test Scenario('log in as user', (I) => { I.amOnPage('/'); I.click('Login'); I.fillField('Username', 'john'); I.fillField('Password', '123456'); I.click('Enter'); I.see('Welcome'); } 27 // assertion from webdriverio helper see(text) { return this.browser.getText() .then(function (source) { return stringIncludes()[assertType](text, source); }); // action from webdriverio helper click(locator, context) { let client = this.browser; let clickMethod = this.browser.isMobile ? 'touchClick' : 'elementIdClick'; if (context) { client = client.element(context); } return findClickable(client, locator).then(function (res) { if (!res.value || res.value.length === 0) { if (typeof(locator) === "object") locator = JSON.stringify(locator); throw new Error(`Clickable element ${locator.toString()} was not found by text|CSS|XPath`); } let elem = res.value[0]; return this[clickMethod](elem.ELEMENT); }); } // adding to global promise recorder.addStep(new Step(helper, action), args); return recorder.promise();
  • 28. Scenario Driven: Executed Step by Step • I am on page ‘/’ • I fill field ‘Username’, ‘john’ • I fill field ‘Password’, ‘123456’ • I click ‘Enter’ • I see ‘Welcome’ ✓OK 28
  • 30. PageObject, PageFragment Scenario('log in as user', (I, loginPage) => { loginPage.logInWith('john', '123456'); I.see('Welcome'); } 30 Automatically Injected (angular-style) // Login steps moved to loginPage: logInWith(name, pass) { I.amOnPage('/'); I.click('Login'); I.fillField('Username', name); I.fillField('Password', pass); I.click('Enter'); }
  • 31. And…. Based on Mocha testing framework. Designed for scenario driven acceptance testing in BDD-style Uses ES6 natively without transpiler. Selenium WebDriver integration using webdriverio (..Protractor, Nigthmare) Easily create tests, pageobjects, stepobjects with CLI generators. 31
  • 32. Try CodeceptJS today! http://codecept.io npm install -g codeceptjs @codeceptjs Author: Michael Bodnarchuk @davert 32
  • 33. Conclusions Acceptance Testing should be done by developers and QAs Use the same language for code and tests NodeJS browser testing is hard (various libraries, async) Use REST API for data, fetching emails, etc Use CodeceptJS 33
  • 34. Questions? Michael Bodnarchuk Follow me: @davert https://github.com/codeception/codeceptjs http://codecept.io 34