SlideShare a Scribd company logo
DrupalCon Dublin 2016 - Automated browser testing with Nightwatch.js
AUTOMATED END-TO-END
TESTING WITH NIGHTWATCH.js
Vladimir Roudakov
29 Sep 2016 Front End bit.ly/dce16-nwatch
Vladimir ROUDAKOV
bit.ly/dce16-nwatch
@VladimirAus
DrupalCon Dublin 2016 - Automated browser testing with Nightwatch.js
Prologue
WHY TESTING?
SOFTWARE DEVELOPMENT CYCLE
REQUIREMENTS
TESTS
IMPLEMENTATION
1. Requirements
● Search for surname
● Display person’s information
2. Manual test
● Go to search engine
● Type surname into search box
● Check for result in right hand side area
DrupalCon Dublin 2016 - Automated browser testing with Nightwatch.js
3. Automated test
● A: URL is available and <body> is visible
● B: Search button is visible
● Enter surname and click search
● C: Right hand side area is visible
● D: Right hand side area contains person’s details
module.exports = {
'As a user I want to see name prediction in right hand side block' :
function (browser) {
browser
.url('http://www.google.com')
.waitForElementVisible('body', 1000)
.setValue('input[type=text]', 'buytaert')
.waitForElementVisible('button[name=btnG]', 1000)
.click('button[name=btnG]')
.waitForElementVisible('#rhs_block', 1000)
.assert.containsText('#main', 'Dries Buytaert')
.end();
}
};
4. Running the test
1. Command line test runner
2. Tests are in JavaScript
3. Uses CSS selectors
● input[type=text]
● button[name=btnG]
● #rhs_block
● #main
4. Continuous Integration support
5. Cloud services support
6. Easy to extend
● Custom commands
● Custom assertions
● Custom reporters
REPORTS
STANDARD PROCESS
Developer
F1F1
F2
STANDARD PROCESS
Developer
PM
F3, ...
F1F1
F2
F1
F2
F2 ready?
Sure
STANDARD PROCESS
BA
Developer
PM
F3, ...
F1F1
F2
F1
F2
F2 ready?
Sure
Great!
To production!
STANDARD PROCESS
BA
DeveloperClient
PM
F3, ...
F1F1
F2
F1
F2
F2 ready?
Sure
Great!
To production!
F2 ready!
Great!
STANDARD PROCESS
BA
DeveloperClient
PM
F3, ...
F1F1
F2
F1
F2
F2 ready?
Sure
Great!
To production!
F2 ready!
Great!
F1?
DrupalCon Dublin 2016 - Automated browser testing with Nightwatch.js
ADDING AUTOMATED TESTING
BA
DeveloperClient
PM
F1F1
F2
ADDING AUTOMATED TESTING
BA
DeveloperClient
PM
F1F1
F2
ADDING AUTOMATED TESTING
BA
DeveloperClient
PM
F1F1
F2
ADDING AUTOMATED TESTING
BA
DeveloperClient
PM
F1F1
F2
Yes, but F1 is
broken...
F2 ready?
DrupalCon Dublin 2016 - Automated browser testing with Nightwatch.js
Who like reports?
DEVELOPERS
Technical detailed report on
● New features and existing functionality
● Integration on latest test environment and UAT
● Sprint retrospective
Who like reports?
INTERNAL TEAM: Managers, PMs, BAs
Report with less technical details on multiple environments
● Track sprint / release progress
● Measure velocity
● Integrate with internal tools: email, chat
Who like reports?
CLIENTS
Report with no technical details on pre release environment
● Test coverage
● Ability to identify missing / not clarified features
Report output
● Visual
● Command line
● JUnit XML
● Custom reporters, e.g. JSON
TESTS
Nightwatch tests
● Written in JavaScript
● Each test can have multiple assertions
module.exports = {
'As a user I want to see name prediction in right hand side block' :
function (browser) {
browser
.url('http://www.google.com')
.waitForElementVisible('body', 1000)
.setValue('input[type=text]', 'buytaert')
.waitForElementVisible('button[name=btnG]', 1000)
.click('button[name=btnG]')
.waitForElementVisible('#rhs_block', 1000)
.assert.containsText('#main', 'Dries Buytaert')
.end();
}
};
module.exports = {
'As a user I want to see name prediction in right hand side block' :
function (browser) {
browser
.url('http://www.google.com')
.waitForElementVisible('body', 1000)
.setValue('input[type=text]', 'buytaert')
.waitForElementVisible('button[name=btnG]', 1000)
.click('button[name=btnG]')
.waitForElementVisible('#rhs_block', 1000)
.assert.containsText('#main', 'Dries Buytaert')
.end();
}
};
module.exports = {
'As a user I want to see name prediction in right hand side block' :
function (browser) {
browser
.url('http://www.google.com')
.waitForElementVisible('body', 1000)
.setValue('input[type=text]', 'buytaert')
.waitForElementVisible('button[name=btnG]', 1000)
.click('button[name=btnG]')
.waitForElementVisible('#rhs_block', 1000)
.assert.containsText('#main', 'Dries Buytaert')
.end();
}
};
module.exports = {
'As a user I want to see name prediction in right hand side block' :
function (browser) {
browser
.url('http://www.google.com')
.waitForElementVisible('body', 1000)
.setValue('input[type=text]', 'buytaert')
.waitForElementVisible('button[name=btnG]', 1000)
.click('button[name=btnG]')
.waitForElementVisible('#rhs_block', 1000)
.assert.containsText('#main', 'Dries Buytaert')
.end();
}
};
module.exports = {
'As a user I want to see name prediction in right hand side block' :
function (browser) {
browser
.url('http://www.google.com')
.waitForElementVisible('body', 1000)
.setValue('input[type=text]', 'buytaert')
.waitForElementVisible('button[name=btnG]', 1000)
.click('button[name=btnG]')
.waitForElementVisible('#rhs_block', 1000)
.assert.containsText('#main', 'Dries Buytaert')
.end();
}
};
module.exports = {
'As a user I want to see name prediction in right hand side block' :
function (browser) {
browser
.url('http://www.google.com')
.waitForElementVisible('body', 1000)
.setValue('input[type=text]', 'buytaert')
.waitForElementVisible('button[name=btnG]', 1000)
.click('button[name=btnG]')
.waitForElementVisible('#rhs_block', 1000)
.assert.containsText('#main', 'Dries Buytaert')
.end();
}
};
Nightwatch tests
● Each file can have multiple tests
● Each folder can have multiple folders and files
Nightwatch tests
● Group tests according to functionality
● Tag your tests for better granular testing
module.exports = {
'@tags': ['sprint3', 'issue 15674'],
'demo login test': function (browser) {
// test code
}
};
ENVIRONMENT
Local environment - selenium
scripts driver
Selenium
● Selenium is a suite of tools to automate web browsers across
many platforms.
● Supports many operating systems
● Runs as a server on Java
● Writing tests is complicated
...
"selenium" : {
"start_process" : false,
"server_path" : "/usr/local/.../seleniumserver2.jar",
"log_path" : "",
"host" : "127.0.0.1",
"port" : 4444,
"cli_args" : {
"webdriver.chrome.driver" : "./chromedriver",
"webdriver.gecko.driver" : "./geckodriver",
"webdriver.ie.driver" : ""
}
...
DrupalCon Dublin 2016 - Automated browser testing with Nightwatch.js
Selenium web driver
Allows selenium to use native browser engines
● Firefox - new Gecko driver
● Safari - requeres
● chrome
● IE / edge browser - ability to run IE in linux
● PhantomJS
DrupalCon Dublin 2016 - Automated browser testing with Nightwatch.js
...
"selenium" : {
"start_process" : false,
"server_path" : "/usr/local/.../seleniumserver2.jar",
"log_path" : "",
"host" : "127.0.0.1",
"port" : 4444,
"cli_args" : {
"webdriver.chrome.driver" : "./chromedriver",
"webdriver.gecko.driver" : "./geckodriver",
"webdriver.ie.driver" : ""
}
...
No desktop environment - Xvfb
scripts driver
Xvfb
● Virtual screen to run browser
● Native functionality
Using cloud services
scripts
DrupalCon Dublin 2016 - Automated browser testing with Nightwatch.js
"selenium" : {
"start_process" : false,
"host": "ondemand.saucelabs.com",
"port": 80
},
"test_settings" : {
"default" : {
"output": true,
"selenium_host": "ondemand.saucelabs.com",
"selenium_port": 80,
"username": "${SAUCE_USERNAME}",
"access_key": "${SAUCE_ACCESS_KEY}",
"desiredCapabilities": {
"browserName": "chrome",
"platform": "Windows 10",
"version": "48"
"selenium" : {
"start_process" : false,
"host": "ondemand.saucelabs.com",
"port": 80
},
"test_settings" : {
"default" : {
"output": true,
"selenium_host": "ondemand.saucelabs.com",
"selenium_port": 80,
"username": "${SAUCE_USERNAME}",
"access_key": "${SAUCE_ACCESS_KEY}",
"desiredCapabilities": {
"browserName": "chrome",
"platform": "Windows 10",
"version": "48"
"selenium" : {
"start_process" : false,
"host": "ondemand.saucelabs.com",
"port": 80
},
"test_settings" : {
"default" : {
"output": true,
"selenium_host": "ondemand.saucelabs.com",
"selenium_port": 80,
"username": "${SAUCE_USERNAME}",
"access_key": "${SAUCE_ACCESS_KEY}",
"desiredCapabilities": {
"browserName": "chrome",
"platform": "Windows 10",
"version": "48"
Epilogue
WHY NIGHTWATCH.js?
Conclusion
● Command line test runner
● Uses JavaScript
● Uses CSS selectors / XPath
● Continuous Integration support
● Cloud services support
Advantages
● Test ANY website
● Complements unit testing
● Various reports
● Visual artifacts (screenshots, videos)
● CI / Cloud services support
Disadvantages
● Takes time for initial setup
● Basic cording knowledge required
Resources
● http://nightwatchjs.org/
● https://github.com/nightwatchjs/nightwatch
● http://www.seleniumhq.org/
● http://www.saucelabs.com/
More resources
JavaScript Unit Testing
Matthew Grill
https://events.drupal.org/dublin2016/sessions/javascript-unit-testing
Evaluate This Session
THANK YOU!
events.drupal.org/dublin2016/schedule
QUESTIONS?
bit.ly/dce16-nwatch
@VladimirAus

More Related Content

PPTX
Testing frontends with nightwatch & saucelabs
PPTX
Обзор автоматизации тестирования на JavaScript
PDF
20160905 - BrisJS - nightwatch testing
PPTX
Protractor framework – how to make stable e2e tests for Angular applications
PDF
Workshop 12: AngularJS Parte I
PPTX
Compatibility Detector Tool of Chrome extensions
PDF
Introduction to Protractor
PDF
UI Testing Best Practices - An Expected Journey
Testing frontends with nightwatch & saucelabs
Обзор автоматизации тестирования на JavaScript
20160905 - BrisJS - nightwatch testing
Protractor framework – how to make stable e2e tests for Angular applications
Workshop 12: AngularJS Parte I
Compatibility Detector Tool of Chrome extensions
Introduction to Protractor
UI Testing Best Practices - An Expected Journey

What's hot (20)

PDF
Vuejs testing
PDF
22 j query1
PPT
Creating the interfaces of the future with the APIs of today
PDF
Sane Async Patterns
PPTX
AngularJS Architecture
PDF
Night Watch with QA
PPTX
Modules and injector
PPTX
Code ceptioninstallation
PDF
Test automation & Seleniun by oren rubin
PDF
Backbone.js
PPTX
Protractor Training in Pune by QuickITDotnet
PDF
Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점
PDF
Introduction to Selenium and Ruby
PDF
Better Testing With PHP Unit
PPTX
Django + Vue, JavaScript de 3ª generación para modernizar Django
PDF
Selenide Alternative in Practice - Implementation & Lessons learned [Selenium...
PPTX
Vue.js + Django - configuración para desarrollo con webpack y HMR
PDF
Join the darkside: Selenium testing with Nightwatch.js
PDF
Bonnes pratiques de développement avec Node js
PPTX
How to Build SPA with Vue Router 2.0
Vuejs testing
22 j query1
Creating the interfaces of the future with the APIs of today
Sane Async Patterns
AngularJS Architecture
Night Watch with QA
Modules and injector
Code ceptioninstallation
Test automation & Seleniun by oren rubin
Backbone.js
Protractor Training in Pune by QuickITDotnet
Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점
Introduction to Selenium and Ruby
Better Testing With PHP Unit
Django + Vue, JavaScript de 3ª generación para modernizar Django
Selenide Alternative in Practice - Implementation & Lessons learned [Selenium...
Vue.js + Django - configuración para desarrollo con webpack y HMR
Join the darkside: Selenium testing with Nightwatch.js
Bonnes pratiques de développement avec Node js
How to Build SPA with Vue Router 2.0
Ad

Viewers also liked (10)

PDF
DrupalGov 2017: Testing any day: guide to end to end test driven Drupal projects
DOCX
Anointing to excel
PDF
Testing nightwatch, by David Torroija
PDF
The Javascript Toolkit 2.0
PDF
Evolving legacy to microservices and ddd
PPTX
Browser Automated Testing Frameworks - Nightwatch.js
PDF
Fullstack End-to-end test automation with Node.js, one year later
PDF
Making views - DrupalGov Canberra 2017
PDF
Getting By Without "QA"
PDF
Nightwatch at Tilt
DrupalGov 2017: Testing any day: guide to end to end test driven Drupal projects
Anointing to excel
Testing nightwatch, by David Torroija
The Javascript Toolkit 2.0
Evolving legacy to microservices and ddd
Browser Automated Testing Frameworks - Nightwatch.js
Fullstack End-to-end test automation with Node.js, one year later
Making views - DrupalGov Canberra 2017
Getting By Without "QA"
Nightwatch at Tilt
Ad

Similar to DrupalCon Dublin 2016 - Automated browser testing with Nightwatch.js (20)

PPTX
Web based automation testing on Node.js environment
PDF
Node.js and Selenium Webdriver, a journey from the Java side
PDF
Browser testing with nightwatch.js - Drupal Europe
PPTX
Browser testing with nightwatch.js
PDF
Intelligent Testing Tool: Selenium Web Driver
PPTX
Automate testing with behat, selenium, phantom js and nightwatch.js (5)
PDF
PPTX
One to rule them all
PPTX
Testing Testing everywhere
ODP
Mastering selenium for automated acceptance tests
PDF
Deep Dive Into NightWatch- Workshop by Pallavi Sharma.pdf
PDF
Front-End Testing: Demystified
PPTX
Automated Testing on Web Applications
PPTX
Nightwatch JS for End to End Tests
PPTX
Automated Testing using JavaScript
PDF
E2E testing con nightwatch.js - Drupalcamp Spain 2018
ODP
PDF
Webdriver.io
PDF
Build Fail-Proof Tests in Any Browser with Selenium
PPTX
End to End Testing with nightwatchjs
Web based automation testing on Node.js environment
Node.js and Selenium Webdriver, a journey from the Java side
Browser testing with nightwatch.js - Drupal Europe
Browser testing with nightwatch.js
Intelligent Testing Tool: Selenium Web Driver
Automate testing with behat, selenium, phantom js and nightwatch.js (5)
One to rule them all
Testing Testing everywhere
Mastering selenium for automated acceptance tests
Deep Dive Into NightWatch- Workshop by Pallavi Sharma.pdf
Front-End Testing: Demystified
Automated Testing on Web Applications
Nightwatch JS for End to End Tests
Automated Testing using JavaScript
E2E testing con nightwatch.js - Drupalcamp Spain 2018
Webdriver.io
Build Fail-Proof Tests in Any Browser with Selenium
End to End Testing with nightwatchjs

More from Vladimir Roudakov (20)

PDF
What's new in Drupal 8.7 (Brisbane Drupal Meetup Brisbane)
PDF
Gitlab for JS developers (BrisJs meetup, 2019-Apr-01)
PDF
Gitlab for PHP developers (Brisbane PHP meetup, 2019-Jan-29)
PDF
Bootstrap 4: what's new, using in Drupal, Bootstrap and php, Bootstrap tools
PDF
Drupal Brisbane Meetup :: Drupal in late 2017-2018
PDF
10 tips for continuous integration
PDF
Testing any day: guide to end to end test driven WordPress projects
PDF
Brisbane Drupal meetup 2016 Apr - whats new in Drupal 8.1
PDF
Brisbane Drupal meetup - 2016 Mar - Build module in Drupal 8
PDF
Brisbane Drupal meetup - 2016 Jan - Drupal hostings
PDF
Bootstrap. December 2015 [Brisbane Drupal meetup]
PDF
DrupalCamp Melbourne 2015. Bootstrap: framework and theme.
PDF
Drupal 8 update. November 2015 [Brisbane Drupal meetup]
PDF
Drupal 8 update. June 2015 [Brisbane Drupal meetup]
PDF
Drupal 8 update. May 2015 [Brisbane Drupal meetup]
PDF
Drupal 8 update. March 2015 [Brisbane Drupal meetup]
PDF
Drupal 8 update. November 2015 [Brisbane Drupal meetup]
PDF
Drupal LMS. February 2015 [Brisbane Drupal meetup]
PDF
Drupal 8 update. February 2015 [Brisbane Drupal meetup]
PDF
Drupal 8 update & drush: October 2014
What's new in Drupal 8.7 (Brisbane Drupal Meetup Brisbane)
Gitlab for JS developers (BrisJs meetup, 2019-Apr-01)
Gitlab for PHP developers (Brisbane PHP meetup, 2019-Jan-29)
Bootstrap 4: what's new, using in Drupal, Bootstrap and php, Bootstrap tools
Drupal Brisbane Meetup :: Drupal in late 2017-2018
10 tips for continuous integration
Testing any day: guide to end to end test driven WordPress projects
Brisbane Drupal meetup 2016 Apr - whats new in Drupal 8.1
Brisbane Drupal meetup - 2016 Mar - Build module in Drupal 8
Brisbane Drupal meetup - 2016 Jan - Drupal hostings
Bootstrap. December 2015 [Brisbane Drupal meetup]
DrupalCamp Melbourne 2015. Bootstrap: framework and theme.
Drupal 8 update. November 2015 [Brisbane Drupal meetup]
Drupal 8 update. June 2015 [Brisbane Drupal meetup]
Drupal 8 update. May 2015 [Brisbane Drupal meetup]
Drupal 8 update. March 2015 [Brisbane Drupal meetup]
Drupal 8 update. November 2015 [Brisbane Drupal meetup]
Drupal LMS. February 2015 [Brisbane Drupal meetup]
Drupal 8 update. February 2015 [Brisbane Drupal meetup]
Drupal 8 update & drush: October 2014

Recently uploaded (20)

PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
cuic standard and advanced reporting.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
KodekX | Application Modernization Development
PPTX
sap open course for s4hana steps from ECC to s4
PPT
Teaching material agriculture food technology
PDF
Empathic Computing: Creating Shared Understanding
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Cloud computing and distributed systems.
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Advanced methodologies resolving dimensionality complications for autism neur...
cuic standard and advanced reporting.pdf
Unlocking AI with Model Context Protocol (MCP)
NewMind AI Weekly Chronicles - August'25 Week I
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
MIND Revenue Release Quarter 2 2025 Press Release
Programs and apps: productivity, graphics, security and other tools
KodekX | Application Modernization Development
sap open course for s4hana steps from ECC to s4
Teaching material agriculture food technology
Empathic Computing: Creating Shared Understanding
MYSQL Presentation for SQL database connectivity
Chapter 3 Spatial Domain Image Processing.pdf
Encapsulation_ Review paper, used for researhc scholars
Diabetes mellitus diagnosis method based random forest with bat algorithm
Spectral efficient network and resource selection model in 5G networks
Cloud computing and distributed systems.
Building Integrated photovoltaic BIPV_UPV.pdf
Network Security Unit 5.pdf for BCA BBA.

DrupalCon Dublin 2016 - Automated browser testing with Nightwatch.js