Михаил Боднарчук "acceptance testing in nodejs: tools & approaches"
TRANSCRIPT
![Page 1: Михаил Боднарчук "Acceptance Testing in NodeJS: Tools & Approaches"](https://reader031.vdocuments.net/reader031/viewer/2022030318/58ed781e1a28abe07a8b4675/html5/thumbnails/1.jpg)
Михаил БоднарчукCodegyre
Acceptance Testing in NodeJS
1
![Page 2: Михаил Боднарчук "Acceptance Testing in NodeJS: Tools & Approaches"](https://reader031.vdocuments.net/reader031/viewer/2022030318/58ed781e1a28abe07a8b4675/html5/thumbnails/2.jpg)
Who Am I
Michael Bodnarchuk
@davert
PHP, Ruby, JS developer from Kyiv, Ukraine
Creator of testing frameworks Codeception (PHP), CodeceptJS (Node)2
![Page 3: Михаил Боднарчук "Acceptance Testing in NodeJS: Tools & Approaches"](https://reader031.vdocuments.net/reader031/viewer/2022030318/58ed781e1a28abe07a8b4675/html5/thumbnails/3.jpg)
What is Acceptance TestingEnd-2-End, functional, etc
3
![Page 4: Михаил Боднарчук "Acceptance Testing in NodeJS: Tools & Approaches"](https://reader031.vdocuments.net/reader031/viewer/2022030318/58ed781e1a28abe07a8b4675/html5/thumbnails/4.jpg)
An App:
4
![Page 5: Михаил Боднарчук "Acceptance Testing in NodeJS: Tools & Approaches"](https://reader031.vdocuments.net/reader031/viewer/2022030318/58ed781e1a28abe07a8b4675/html5/thumbnails/5.jpg)
What’s inside a box?
5
![Page 6: Михаил Боднарчук "Acceptance Testing in NodeJS: Tools & Approaches"](https://reader031.vdocuments.net/reader031/viewer/2022030318/58ed781e1a28abe07a8b4675/html5/thumbnails/6.jpg)
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
![Page 7: Михаил Боднарчук "Acceptance Testing in NodeJS: Tools & Approaches"](https://reader031.vdocuments.net/reader031/viewer/2022030318/58ed781e1a28abe07a8b4675/html5/thumbnails/7.jpg)
What should we test?
7
Chocolate Factory (unit/integration) - make a chocolate
Interface (acceptance/e2e) - user can get a chocolate
![Page 8: Михаил Боднарчук "Acceptance Testing in NodeJS: Tools & Approaches"](https://reader031.vdocuments.net/reader031/viewer/2022030318/58ed781e1a28abe07a8b4675/html5/thumbnails/8.jpg)
Who should write tests?
8
Unit/Integration -
Developers
Acceptance -
QA Engineers
![Page 9: Михаил Боднарчук "Acceptance Testing in NodeJS: Tools & Approaches"](https://reader031.vdocuments.net/reader031/viewer/2022030318/58ed781e1a28abe07a8b4675/html5/thumbnails/9.jpg)
We are developers!Let’s leave testing to QAs
9
![Page 10: Михаил Боднарчук "Acceptance Testing in NodeJS: Tools & Approaches"](https://reader031.vdocuments.net/reader031/viewer/2022030318/58ed781e1a28abe07a8b4675/html5/thumbnails/10.jpg)
THE ENDThank you
10
![Page 11: Михаил Боднарчук "Acceptance Testing in NodeJS: Tools & Approaches"](https://reader031.vdocuments.net/reader031/viewer/2022030318/58ed781e1a28abe07a8b4675/html5/thumbnails/11.jpg)
Well-tested software is a productof collaboration
11
Do it as team!
![Page 12: Михаил Боднарчук "Acceptance Testing in NodeJS: Tools & Approaches"](https://reader031.vdocuments.net/reader031/viewer/2022030318/58ed781e1a28abe07a8b4675/html5/thumbnails/12.jpg)
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
![Page 13: Михаил Боднарчук "Acceptance Testing in NodeJS: Tools & Approaches"](https://reader031.vdocuments.net/reader031/viewer/2022030318/58ed781e1a28abe07a8b4675/html5/thumbnails/13.jpg)
Tools for Acceptance Testing
Selenium Webdriver
PhantomJS
Nightmare
ZombieJS
CasperJS13
![Page 14: Михаил Боднарчук "Acceptance Testing in NodeJS: Tools & Approaches"](https://reader031.vdocuments.net/reader031/viewer/2022030318/58ed781e1a28abe07a8b4675/html5/thumbnails/14.jpg)
Automating Browser with Selenium
14
![Page 15: Михаил Боднарчук "Acceptance Testing in NodeJS: Tools & Approaches"](https://reader031.vdocuments.net/reader031/viewer/2022030318/58ed781e1a28abe07a8b4675/html5/thumbnails/15.jpg)
How to deal with
Locating Elements
Single Page Applications
Cloud Testing
Data In Tests15
![Page 16: Михаил Боднарчук "Acceptance Testing in NodeJS: Tools & Approaches"](https://reader031.vdocuments.net/reader031/viewer/2022030318/58ed781e1a28abe07a8b4675/html5/thumbnails/16.jpg)
Locating Elements
“Hey, click me that green button”!
By CSS (JQuery style)
By XPath (Most flexible)
By Link Text
Reuse locators in PageObjects16
GET A CHOCOLATE!!!Secured. No Credit Card Required.
![Page 17: Михаил Боднарчук "Acceptance Testing in NodeJS: Tools & Approaches"](https://reader031.vdocuments.net/reader031/viewer/2022030318/58ed781e1a28abe07a8b4675/html5/thumbnails/17.jpg)
Single Page Applications
Browser automation faster than user
DOMReady vs “‘I’ve done it, master!”
Before each step:
executeAsync((done) => waitToRender(done))
17
![Page 18: Михаил Боднарчук "Acceptance Testing in NodeJS: Tools & Approaches"](https://reader031.vdocuments.net/reader031/viewer/2022030318/58ed781e1a28abe07a8b4675/html5/thumbnails/18.jpg)
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
![Page 19: Михаил Боднарчук "Acceptance Testing in NodeJS: Tools & Approaches"](https://reader031.vdocuments.net/reader031/viewer/2022030318/58ed781e1a28abe07a8b4675/html5/thumbnails/19.jpg)
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 API19
![Page 20: Михаил Боднарчук "Acceptance Testing in NodeJS: Tools & Approaches"](https://reader031.vdocuments.net/reader031/viewer/2022030318/58ed781e1a28abe07a8b4675/html5/thumbnails/20.jpg)
Testing Emails
Open Gmail in next tab, click the latest email….
Use MailDev, MailCatcher, MailHog, MailTrap
Check sent emails via REST API
20
![Page 21: Михаил Боднарчук "Acceptance Testing in NodeJS: Tools & Approaches"](https://reader031.vdocuments.net/reader031/viewer/2022030318/58ed781e1a28abe07a8b4675/html5/thumbnails/21.jpg)
Libraries for Acceptance Testing
Selenium Webdriver JS
webdriverio
Protractor
Intern
Nightmare21
NightwatchJS
CodeceptJS
WD.js
...
![Page 22: Михаил Боднарчук "Acceptance Testing in NodeJS: Tools & Approaches"](https://reader031.vdocuments.net/reader031/viewer/2022030318/58ed781e1a28abe07a8b4675/html5/thumbnails/22.jpg)
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();
![Page 23: Михаил Боднарчук "Acceptance Testing in NodeJS: Tools & Approaches"](https://reader031.vdocuments.net/reader031/viewer/2022030318/58ed781e1a28abe07a8b4675/html5/thumbnails/23.jpg)
How to choose?Investigate, check your requirements
23
![Page 24: Михаил Боднарчук "Acceptance Testing in NodeJS: Tools & Approaches"](https://reader031.vdocuments.net/reader031/viewer/2022030318/58ed781e1a28abe07a8b4675/html5/thumbnails/24.jpg)
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
![Page 25: Михаил Боднарчук "Acceptance Testing in NodeJS: Tools & Approaches"](https://reader031.vdocuments.net/reader031/viewer/2022030318/58ed781e1a28abe07a8b4675/html5/thumbnails/25.jpg)
CodeceptJSto rule them all
25
![Page 26: Михаил Боднарчук "Acceptance Testing in NodeJS: Tools & Approaches"](https://reader031.vdocuments.net/reader031/viewer/2022030318/58ed781e1a28abe07a8b4675/html5/thumbnails/26.jpg)
CodeceptJS
One framework using other libraries
Synchronous (not really, uses global promise)
Scenario Driven
With PageObjects, Interactive Shell, Error output... 26
![Page 27: Михаил Боднарчук "Acceptance Testing in NodeJS: Tools & Approaches"](https://reader031.vdocuments.net/reader031/viewer/2022030318/58ed781e1a28abe07a8b4675/html5/thumbnails/27.jpg)
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();
![Page 28: Михаил Боднарчук "Acceptance Testing in NodeJS: Tools & Approaches"](https://reader031.vdocuments.net/reader031/viewer/2022030318/58ed781e1a28abe07a8b4675/html5/thumbnails/28.jpg)
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
![Page 29: Михаил Боднарчук "Acceptance Testing in NodeJS: Tools & Approaches"](https://reader031.vdocuments.net/reader031/viewer/2022030318/58ed781e1a28abe07a8b4675/html5/thumbnails/29.jpg)
Interactive Shell
29
![Page 30: Михаил Боднарчук "Acceptance Testing in NodeJS: Tools & Approaches"](https://reader031.vdocuments.net/reader031/viewer/2022030318/58ed781e1a28abe07a8b4675/html5/thumbnails/30.jpg)
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');
}
![Page 31: Михаил Боднарчук "Acceptance Testing in NodeJS: Tools & Approaches"](https://reader031.vdocuments.net/reader031/viewer/2022030318/58ed781e1a28abe07a8b4675/html5/thumbnails/31.jpg)
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
![Page 32: Михаил Боднарчук "Acceptance Testing in NodeJS: Tools & Approaches"](https://reader031.vdocuments.net/reader031/viewer/2022030318/58ed781e1a28abe07a8b4675/html5/thumbnails/32.jpg)
Try CodeceptJS today!
http://codecept.io
npm install -g codeceptjs
@codeceptjs
Author: Michael Bodnarchuk @davert 32
![Page 33: Михаил Боднарчук "Acceptance Testing in NodeJS: Tools & Approaches"](https://reader031.vdocuments.net/reader031/viewer/2022030318/58ed781e1a28abe07a8b4675/html5/thumbnails/33.jpg)
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 CodeceptJS33
![Page 34: Михаил Боднарчук "Acceptance Testing in NodeJS: Tools & Approaches"](https://reader031.vdocuments.net/reader031/viewer/2022030318/58ed781e1a28abe07a8b4675/html5/thumbnails/34.jpg)
Questions?
Michael Bodnarchuk
Follow me: @davert
https://github.com/codeception/codeceptjs
http://codecept.io
34