night watch with qa

61
Night watch …with QA Carsten Sandtner (@casarock) mediaman// Gesellschaft für Kommunikation mbH

Upload: carsten-sandtner

Post on 12-Feb-2017

83 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Night Watch with QA

Night watch…with QA

Carsten Sandtner (@casarock) mediaman// Gesellschaft für Kommunikation mbH

Page 2: Night Watch with QA

about:meCarsten Sandtner

@casarock

Head of Software Development //mediaman GmbH

Page 3: Night Watch with QA
Page 4: Night Watch with QA

Testing

Page 5: Night Watch with QA

Unit Tests

Page 6: Night Watch with QA

Integration Tests

Page 7: Night Watch with QA

System Tests

Nat

iona

l Mus

eum

of A

mer

ican

His

tory

Sm

ithso

nian

Inst

itutio

n - h

ttps:

//flic

.kr/p

/e6s

1Lr

Page 8: Night Watch with QA

User Acceptance Tests

Bret

t Jor

dan

- http

s://fl

ic.k

r/p/7

ZRSz

A

Page 9: Night Watch with QA

UAT

System Test

Integration Test

Unit Test

Preliminary design

Detailed design

Implementation

Requirements

Page 10: Night Watch with QA

UAT

Integration Test

Unit Test

Detailed design

Implementation

Requirements

System TestPreliminary design

Page 11: Night Watch with QA

by 7

2632

55 -

http

s://fl

ic.k

r/p/6

YgD

NN

Page 12: Night Watch with QA
Page 13: Night Watch with QA
Page 14: Night Watch with QA

Testing pyramid

# of Tests

easy

to

auto

mate

Page 15: Night Watch with QA

Implementation Unit Test

TDD

Page 16: Night Watch with QA

Integration Test

Unit Test

Detailed design

Implementation Unit Test

Page 17: Night Watch with QA

System Test

Integration Test

Unit Test

Preliminary design

Detailed design

Implementation

Page 18: Night Watch with QA

Automated E2E Test

Page 19: Night Watch with QA
Page 20: Night Watch with QA
Page 21: Night Watch with QA
Page 22: Night Watch with QA

– http://nightwatchjs.org/

„Nightwatch.js is an easy to use Node.js based End-to-End (E2E) testing solution for browser based apps

and websites. It uses the powerful Selenium WebDriver API to perform commands and assertions

on DOM elements.“

Page 23: Night Watch with QA

Nightwatch & WebDriver

Page 24: Night Watch with QA

Features• Clean syntax

• Build-in test runner

• support for CSS and Xpath Selectors

• Grouping and filtering of Tests

• Saucelab and Browserstack support

• Extendable (Custom Commands)

• CI support!

Page 25: Night Watch with QA

Installation

$ npm install [-g] nightwatch

… and Download Selenium-Server-Standalone!

Done.

Page 26: Night Watch with QA

Nightwatch project structure

├──bin/ | ├──chromedriver | └──seleniumdriver.jar | ├──data/ | └──globals.js | ├──reports/ | └──fancyreports.xml | ├──tests/ | ├──meaningfultest1.js | ├──meaningfultest2.js | └── … └──nightwatch.js[on]

Page 27: Night Watch with QA

Nightwatch.js

module.exports = { "src_folders": ["tests"], "output_folder": "reports", "custom_commands_path": "", "custom_assertions_path": "", "page_objects_path": "./objects/", "globals_path": "",

"selenium": { "start_process": true, "server_path": "bin/selenium-server-standalone-2.53.1.jar", "log_path": "", "host": "127.0.0.1", "port": 4444, "cli_args": { "webdriver.chrome.driver": "./bin/chromedriver", "webdriver.ie.driver": "", "webdriver.gecko.driver" : "./bin/geckodriver090" } },

Page 28: Night Watch with QA

Nightwatch.js - Test setup.

"test_settings": { "default": { "launch_url": "http://localhost", "selenium_port": 4444, "selenium_host": "localhost", "silent": true, "screenshots": { "enabled": false, "path": "" }, "desiredCapabilities": { "browserName": "chrome", "marionette": true } }, “staging“: {

. . .

},

Page 29: Night Watch with QA

Nightwatch.js - Browser setup

"chrome": { "desiredCapabilities": { "browserName": "chrome", "javascriptEnabled": true, "acceptSslCerts": true } } } };

Page 30: Night Watch with QA

Simple Nightwatch test

module.exports = { 'Google Webtechcon' : function (client) { client .url('http://www.google.com') .waitForElementVisible('body', 1000) .assert.title('Google') .assert.visible('input[type=text]') .setValue('input[type=text]', 'webtechcon') .waitForElementVisible('button[name=btnG]', 1000) .click('button[name=btnG]') .pause(1000) .assert.containsText('#rso > div.g > div > div > h3 > a', 'WebTech Conference 2016') .end(); } };

Page 31: Night Watch with QA

Test execution

$ nightwatch [-c nightwatch.js] tests/simplegoogle.js

Page 32: Night Watch with QA
Page 33: Night Watch with QA

Tests in detail

Page 34: Night Watch with QA

Arrange and assert

module.exports = { 'Google Webtechcon' : function (client) { client .url('http://www.google.com') .waitForElementVisible('body', 1000) .assert.title('Google') .assert.visible('input[type=text]') .end(); } };

arrange

assert

Page 35: Night Watch with QA

Arrange, action and assert

module.exports = { 'Google Webtechcon' : function (client) { client .url('http://www.google.com') .waitForElementVisible('body', 1000) .assert.title('Google') .assert.visible('input[type=text]') .setValue('input[type=text]', 'webtechcon') .waitForElementVisible('button[name=btnG]', 1000) .click('button[name=btnG]') .pause(1000) .assert.containsText('#rso > div.g > div > div > h3 > a', 'WebTech Conference 2016') .end(); }

arrangeassert

assert

action

Page 36: Night Watch with QA

Hardcoded values?

Page 37: Night Watch with QA

Hardcoded values

module.exports = { 'Google Webtechcon' : function (client) { client .url('http://www.google.com') .waitForElementVisible('body', 1000) .assert.title('Google') .assert.visible('input[type=text]') .end(); } };

Page 38: Night Watch with QA

Using globals

module.exports = { 'Google Webtechcon' : function (client) { var globals = client.globals;

client .url(globals.url) .waitForElementVisible('body', 1000) .assert.title(globals.static.pageTitle) .assert.visible(globals.selectors.searchField) .end(); } };

Page 39: Night Watch with QA

Define globals

module.exports = { url: 'http://www.google.com', selectors: { 'searchField': 'input[type=text]' }, static: { 'pageTitle': 'Google' } } Save as data/google.js

Page 40: Night Watch with QA

Add to config (test-settings)

module.exports = { . . .

"test_settings": { "default": { "launch_url": "http://localhost", "selenium_port": 4444, "selenium_host": "localhost", "silent": true, "screenshots": { "enabled": false, "path": "" }, "desiredCapabilities": { "browserName": "chrome", "marionette": true }, "globals": require('./data/google') },

. . .

Page 41: Night Watch with QA
Page 42: Night Watch with QA

Use Page Objects!

Page 43: Night Watch with QA

Using Page Objects

module.exports = { 'url': 'http://www.google.com',

'elements': { 'searchField': 'input[type=text]' } };

Save as object/google.js

Page 44: Night Watch with QA

Add objects to config

module.exports = { "src_folders": ["tests"], "output_folder": "reports", "custom_commands_path": "", "custom_assertions_path": "", "page_objects_path": "./objects/", "globals_path": "",

"selenium": {. . .},

"test_settings": {. . .} };

Page 45: Night Watch with QA

Add objects to config

module.exports = { 'Google Webtechcon' : function (client) { var googlePage = client.page.google(), globals = client.globals;

googlePage.navigate() .waitForElementVisible('body', 1000) .assert.title(globals.static.pageTitle) .assert.visible('@searchField') .end(); } };

Page 46: Night Watch with QA

More PageObjects awesomeness

module.exports = { 'url': 'http://www.some.url', 'elements': { 'passwordField': 'input[type=text]', 'usernameField': 'input[type=password]', 'submit': 'input[type=submit]' }, commands: [{ signInAsAdmin: function() { return this.setValue('@usernameField', 'admin') .setValue('@passwordField', 'password') .click('@submit'); } }] };

Page 47: Night Watch with QA

In your test

module.exports = { 'Admin log in' : function (browser) { var login = browser.page.admin.login();

login.navigate() .signInAsAdmin(); browser.end(); } };

Page 48: Night Watch with QA

Grouping tests

$ nightwatch --group smoketests

$ nightwatch --skipgroup smoketests

$ nightwatch --skipgroup login,whatever

Page 49: Night Watch with QA

Test groups

| ├──tests/ | ├──smoketests/ | | ├──meaningfulTest1.js | | ├──meaningfulTest2.js | | └── …… | └──login/ | ├──authAndLogin.js | └── ……

Page 50: Night Watch with QA

Tag your tests

$ nightwatch --tag login

$ nightwatch --tag login --tag something_else

$ nightwatch --skiptags login

$ nightwatch --skiptags login,something_else

Page 51: Night Watch with QA

In your test

module.exports = { '@tags': ['login', 'sanity'], 'Admin log in' : function (browser) { var login = browser.page.admin.login();

login.navigate() .signInAsAdmin(); browser.end(); } };

Page 52: Night Watch with QA

Demo

Page 53: Night Watch with QA

Nightwatch is extendable!

• Write custom commands

• add custom assertions

• write custom reporter

Page 54: Night Watch with QA

Nightwatch is Javascript!

• Using Filereaders

• CSV, Excel etc.

• write helpers if needed!

Page 55: Night Watch with QA
Page 56: Night Watch with QA

Nightwatch @Mediaman

Page 57: Night Watch with QA

The problem

Page 58: Night Watch with QA

Before Nightwatch

Page 59: Night Watch with QA

The solution

Page 60: Night Watch with QA

UAT

System Test

Integration Test

Unit Test

Preliminary design

Detailed design

Implementation

Requirements

✓ ✓

✓ ✓

✓ ✓

Page 61: Night Watch with QA

Thanks!Carsten Sandtner

@casarock

[email protected]

https://github.com/casarock

(◡‿◡✿)