1) Michael Bodnarchuk presented on acceptance testing in NodeJS and introduced CodeceptJS as a testing framework.
2) Acceptance testing verifies the functionality of an application from an end-user perspective and tests the full user workflow.
3) CodeceptJS allows writing acceptance tests in a synchronous manner using page objects and scenarios while leveraging Selenium and other browser automation libraries. It aims to make acceptance testing easy.
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
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
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
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
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