SlideShare a Scribd company logo
www.drupaleurope.org
Salva Molina
Browser Testing
Session URL: https://www.drupaleurope.org/session/browser-testing-nightwatchjs
with Nightwatch.js
13/9/201
Salva Molina
PHP Engineer
@salva_bg
Drupal.org: slv_
Freelance
Drupal & Symfony.
Security Audits.
Devops.
Me
Nightwatch.js
● Introduction & Motivation
● 4 Artifacts to rule them all
● Nightwatch & Drupal
A somewhat familiar Friday for every developer.
The watermelon effect“ “
Deploying to production (no tests)
Browser testing with nightwatch.js - Drupal Europe
Introduction
What’s Nightwatch.js
Introduction
What’s Nightwatch.js
Test Runner with parallel execution support.
JUnit-compliant XML reports.
assert-like and expect-like validations.
Hooks: before, beforeEach, after, afterEach.
Unit Testing support.
Main Features
The bread and butter
"src_folders" : [
"./tests/nightwatch/tests/"
],
"output_folder" : "{...}/reports",
"custom_commands_path" : "{...}/commands",
"custom_assertions_path" : "{...}/assertions",
"page_objects_path" : [
"{...}/pages/example"
],
"globals_path" : "{...}/global.js",
First Stop: Nightwatch.json
Paths
"selenium" : {
"start_process" : true,
"server_path" :
"./tests/bin/selenium-server-standalone-3.13.0.jar",
"log_path" : "",
"port" : 34567,
"cli_args" : {
"webdriver.chrome.driver" : "./tests/bin/chromedriver"
}
},
First Stop: Nightwatch.json
Selenium and Webdrivers
"dev" : {
"launch_url" : "http://127.0.0.1:8000",
"selenium_port" : 9515,
"selenium_host" : "127.0.0.1",
"default_path_prefix" : "",
"desiredCapabilities": {
"browserName": "chrome"
}
}
First Stop: Nightwatch.json
Environments
var selenium = require('selenium-server');
var chromedriver = require('chromedriver');
module.exports = (function(settings) {
settings.selenium.server_path = selenium.path;
settings.selenium.cli_args["webdriver.chrome.driver"] = chromedriver.path;
return settings;
})(require('./nightwatch.json'));
Fully-customized setup
Nightwatch.conf.js
Main header
Subtitle
4 Artifacts to rule them all
Commands.
Page Objects.
Asserts.
Global Data.
Artifacts
Tests.
Many provided by default, like:
.closeWindow.
.setValue.
.saveScreenshot.
.click.
Commands
Generic actions to perform across the site
Custom Commands
commands/clickWithMessage.js
exports.command = function (selector, message) {
// Click and display a message for the action.
this.click(selector, function() {
if (this.globals.test_settings.disable_colors === true) {
console.log(' ✔ ' + message);
}
else {
console.log('033[92m ✔ 033[0m' + message);
}
});
return this;
};
Martin Fowler.
Page objects are a classic example of
encapsulation - they hide the details of
the UI structure and widgetry from other
components (the tests).
“
“
Page Objects
pages/myPage.js
Page Objects
pages/myPage.js
Page Objects
pages/myPage.js
Page Objects
pages/myPage.js
Assertions
assertions/myAssertion.js
exports.assertion = function(selector, comparedValue, msg) {
this.message = msg || util.format('Testing if value of <%s> does not equal: "%s".',
selector, comparedValue);
this.expected = comparedValue;
this.command = function(callback) {};
this.value = function(result) {};
this.pass = function(value) {};
};
BDD Expect Assertions
checkFieldAttribute: function(fieldName, attr, Value) {
this
.expect.element(fieldName).to.have.attribute(attr).equals(Value);
return this;
},
Language Chains: to, be, been, is, that, which, and,
has, have, with, at, does, of.
Global Data
data/globals.js
user: {
username: 'test3',
password: 'AcceptableUserPassword_-',
},
unexisting_user: {
username: 'nightwatch_' + Date.now(),
firstname: 'NW_First',
display_name: 'NW_First' + 'Surname' + Date.now(),
email: 'nightwatch_' + Date.now() + '@.example.net'
},
Simple Test with & w/o Page Objects.
Demo 1
Remote testing via Jenkins
Dependencies on the remote Server
Scenario
1
Scenario
1
2
Scenario
1
2
3
Scenario
Scenario
1
2
4
3
CI Configuration
"ci" : {
"launch_url" : "http://{http_auth_user}:{http_auth_pass}@127.0.0.1:8000",
"selenium_port" : 9515,
"selenium_host" : "127.0.0.1",
"default_path_prefix" : "",
"selenium" : {
"start_process": false
},
"desiredCapabilities": {
"browserName": "chrome",
"chromeOptions": {
"args": ["--headless"]
}
}
}
LIVE DEMO:
Graphical representation
Remote Testing via Jenkins
Demo 2
Drupal commands
Nightwatch & Drupal
CreateRole, CreateUser, Login, Logout,
RelativeURL, UserIsLoggedIn.
Commands
Available in 8.6.0
Install, LoginAsAdmin, Uninstall.
Script-based
Web-based
Don’t need to go through any Nightwatch documentation.
Very simple and fast setup. No custom package.json needed:
yarn install
yarn test:nightwatch
Drupal Setup
Pros
Page Objects not supported yet.
Some use cases not covered (no multiple env setup).
Need to download some other npm dependencies that you
might not want for remote testing.
Still lots to do. Can’t easily enable modules, place blocks, etc.
Drupal Setup
Cons
Module developer: YES! or… yes?
For customer sites: I would not.
Instead: Use your own setup, and simply point its config
to the commands provided by core that are somewhat
usable outside of core testing.
Commands
So, should I use Core commands for my tests?
Why Nightwatch?
Why Nightwatch?
Official Docs!
Quick install: https://github.com/salvamomo/nightwatch-starter.
Phéna Proxima on Testing.
Nightwatch after 12000 tests and 3000 hours.
Resources
Some links, tools and interesting reads
DevOps + Infrastructure
13/9/2018
TRACK SUPPORTED BY
Questions?
Danke fürs Kommen
@salva_bg
salva.momo[at]gmail.com
www.adevfromtheplains.com

More Related Content

PDF
Adventures In JavaScript Testing
PDF
PL/SQL Unit Testing Can Be Fun!
PPTX
Stress test your backend with Gatling
PDF
Performance tests with Gatling (extended)
PDF
Unit testing JavaScript using Mocha and Node
PDF
Unit testing with mocha
PDF
Performance and stability testing \w Gatling
DOCX
Batch processing Demo
Adventures In JavaScript Testing
PL/SQL Unit Testing Can Be Fun!
Stress test your backend with Gatling
Performance tests with Gatling (extended)
Unit testing JavaScript using Mocha and Node
Unit testing with mocha
Performance and stability testing \w Gatling
Batch processing Demo

What's hot (20)

PPTX
ES6, 잘 쓰고 계시죠?
PPTX
Smarter Testing With Spock
PDF
2016 W3C Conference #4 : ANGULAR + ES6
PDF
Spock Framework
PDF
Understanding JavaScript Testing
PDF
Spock: Test Well and Prosper
PDF
FwDays 2021: Metarhia Technology Stack for Node.js
PDF
PL/SQL Unit Testing Can Be Fun
PPT
Test innode
PDF
Using Groovy with Jenkins
KEY
Node.js 0.8 features
PPTX
Understanding JavaScript Testing
PPT
Unit testing with Spock Framework
PDF
Metis - RubyConf 2011 Lightning Talk
KEY
Taking a Test Drive
KEY
Testing JS with Jasmine
PDF
Intro to Sail.js
PPTX
Owl: The New Odoo UI Framework
PPTX
Protractor Training in Pune by QuickITDotnet
PDF
"Auth for React.js APP", Nikita Galkin
ES6, 잘 쓰고 계시죠?
Smarter Testing With Spock
2016 W3C Conference #4 : ANGULAR + ES6
Spock Framework
Understanding JavaScript Testing
Spock: Test Well and Prosper
FwDays 2021: Metarhia Technology Stack for Node.js
PL/SQL Unit Testing Can Be Fun
Test innode
Using Groovy with Jenkins
Node.js 0.8 features
Understanding JavaScript Testing
Unit testing with Spock Framework
Metis - RubyConf 2011 Lightning Talk
Taking a Test Drive
Testing JS with Jasmine
Intro to Sail.js
Owl: The New Odoo UI Framework
Protractor Training in Pune by QuickITDotnet
"Auth for React.js APP", Nikita Galkin
Ad

Similar to Browser testing with nightwatch.js - Drupal Europe (20)

PPTX
Browser testing with nightwatch.js
PDF
E2E testing con nightwatch.js - Drupalcamp Spain 2018
PDF
Testing in JavaScript
PPTX
Full Stack Unit Testing
PDF
UA Testing with Selenium and PHPUnit - ZendCon 2013
PDF
20160905 - BrisJS - nightwatch testing
PDF
UA testing with Selenium and PHPUnit - TrueNorthPHP 2013
PDF
Web UI test automation instruments
PDF
UA testing with Selenium and PHPUnit - PHPBenelux Summer BBQ
PDF
Node.js vs Play Framework (with Japanese subtitles)
PDF
Automated acceptance test
PPTX
Security testing of YUI powered applications
PPT
Pragmatic Parallels: Java and JavaScript
ODP
Good Practices On Test Automation
PPTX
Good karma: UX Patterns and Unit Testing in Angular with Karma
PDF
DrupalCon Dublin 2016 - Automated browser testing with Nightwatch.js
PPTX
Testing basics for developers
PDF
Тестирование и Django
PDF
Intro To JavaScript Unit Testing - Ran Mizrahi
PDF
soft-shake.ch - Hands on Node.js
Browser testing with nightwatch.js
E2E testing con nightwatch.js - Drupalcamp Spain 2018
Testing in JavaScript
Full Stack Unit Testing
UA Testing with Selenium and PHPUnit - ZendCon 2013
20160905 - BrisJS - nightwatch testing
UA testing with Selenium and PHPUnit - TrueNorthPHP 2013
Web UI test automation instruments
UA testing with Selenium and PHPUnit - PHPBenelux Summer BBQ
Node.js vs Play Framework (with Japanese subtitles)
Automated acceptance test
Security testing of YUI powered applications
Pragmatic Parallels: Java and JavaScript
Good Practices On Test Automation
Good karma: UX Patterns and Unit Testing in Angular with Karma
DrupalCon Dublin 2016 - Automated browser testing with Nightwatch.js
Testing basics for developers
Тестирование и Django
Intro To JavaScript Unit Testing - Ran Mizrahi
soft-shake.ch - Hands on Node.js
Ad

Recently uploaded (20)

PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
R24 SURVEYING LAB MANUAL for civil enggi
DOCX
573137875-Attendance-Management-System-original
PPTX
web development for engineering and engineering
PDF
composite construction of structures.pdf
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PPT
Project quality management in manufacturing
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
Internet of Things (IOT) - A guide to understanding
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
OOP with Java - Java Introduction (Basics)
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPTX
Construction Project Organization Group 2.pptx
PPTX
Geodesy 1.pptx...............................................
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
CYBER-CRIMES AND SECURITY A guide to understanding
R24 SURVEYING LAB MANUAL for civil enggi
573137875-Attendance-Management-System-original
web development for engineering and engineering
composite construction of structures.pdf
Automation-in-Manufacturing-Chapter-Introduction.pdf
Project quality management in manufacturing
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
Internet of Things (IOT) - A guide to understanding
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
OOP with Java - Java Introduction (Basics)
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
Construction Project Organization Group 2.pptx
Geodesy 1.pptx...............................................
Foundation to blockchain - A guide to Blockchain Tech
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx

Browser testing with nightwatch.js - Drupal Europe