SlideShare une entreprise Scribd logo
1  sur  30
Télécharger pour lire hors ligne
Full-Stack End-to-End
Test Automation with
Node.js
One year later
ForwardJS 2017
Chris Clayman
Mek Stittri
2
First things first
Airware, we are a drone company.
We build complete enterprise drone solutions; Cloud Platform, Ground Control
Station, Drone Integration and etc
We are Hiring! - http://www.airware.com/careers
● iOS Software Engineer
● Javascript Software Engineer
Or just come talk to us :)
3
A Bit About Us
The Automation team at Airware, we do drone stuffs.
Continuous Deployment & Test Automation tools aka Quality Ops
Chris Clayman
@chrisclayman
github.com/kidmillions
Mek Stittri
@mekdev
github.com/mekdev
Overheard at the Monday workshops
"I don't write tests, testing sucks"
Let's talk About Test Automation
Let us give
you a
warm hug.
Why Node.js for Test Automation
QA, Automation engineers
Frontend engineers
Backend engineers
Java
Javascript
Java
Python
Javascript
Java
Ruby
Javascript
Node.js
Company A Company B Company C
Node.js
Javascript
Node.js
Airware
- Node.js adoption, more and more company moving to node.js
- Share code with the whole engineering team
- Play to the engineering team’s strength
True Full-Stack
Delivery Team
Functional tests that
interacts with the webapp
as a user would.
Full-Stack End-to-End Automation
Visual
UI Interaction
Http Restful API
Javascript Unit tests
Microservice Integration
Unit tests
DB & Data Schema tests
Martin Fowler - Test Pyramid, Google Testing Blog
2014 Google Test Automation Conference
Tools for tests
● Visual Diff Engine
● Selenium-Webdriver
● REST API Client
Small
Unit tests
Big
E2E tests
Medium
Integration tests
z’ Test
Pyramid
Cost of test
Amount of tests
Client implementation that maps to your HTTP
RESTful Backend API
Simulating browser AJAX calls and acts like a user.
Via GET / POST / PUT / DELETE requests and etc..
Request libraries:
- requests - https://github.com/request/request
- request-promise - https://github.com/request/request-promise
- etc...
REST API Client
Anyone here use selenium for automation ?
Industry standard for web browser automation
Language-neutral coding interface: C#, JavaScript , Java, Python, Ruby
Official Project - https://github.com/SeleniumHQ/selenium
Selenium Webdriver
$ npm i selenium-webdriver
Visual Diff Engine
Bitmap comparison tool for screenshot validation.
Validates a given screenshot against a baseline
image
Available tools:
- Applitools - https://applitools.com/ integrates with selenium JS
- Sikuli, roll your own framework - http://www.sikuli.org/
Baseline Changes
Timeline
Q2 2015
The Early Age
Rapid Prototyping Phase
The Middle Age
“The Promise Manager”
Evaluating multiple test frameworks
Test Runner
- Mocha / Karma
- Ava / Jest
API - Http library
- request
- co-request
- request-promise
- Supertest / Chakram
UI - Selenium bindings
- Nightwatch
- WebdriverIO
- selenium-webdriver (WebdriverJS)
Q3 2015 Q3 2016 - Present
- ES6/ES2015
- Promises
- ESLint
- Went with Mocha
- Picked selenium-webdriver
aka WebDriverJs
Built-in Promise Manager
(synchronous like behavior)
- Went with co-request
Generator calls, easier
(synchronous like behavior)
- Applitools visual diff
- ES7/2016+
- Async Await
- Babel
- ESLint + StandardJS
- Flowtype (facebook)
- selenium-webdriver
- Switched to request lib
Async / Await solves a lot of
the previous problems, no
more callbacks or thenables
The Modern Age
“Async/Await” and beyond
Lessons Learnt
We made mistakes so you don’t
have to!
Recipe for a
Node/Selenium
Framework
- Representation of Pages (Page Objects)
- Readable tests
- Frontend testability
- Robust backend API
- Clients to interact with said API
- De-async testing approach
- Visual tests
- Accurate and descriptive reporting
Automation Framework Ingredients
- Representation of a page or
component.
- We use class syntax
- Abstract UI interaction
implementation to a
BasePage or UI utility
outside of the pageobject
- Map page objects 1-to-1 to
pages and components
Page Object Model (POM)
const CHANGE_PASSWORD_BTN = 'button.change-passwd'
class ProfilePage extends BasePage {
clickChangePassword () {
click(CHANGE_PASSWORD_BTN)
}
}
Readable Tests
clusterImageGallery.currentSelectedImageAnnotationIndicatorExistsInTrack()
Great work,
Chip!
- Anyone should be able to read or write tests
- Abstract low level webdriver implementation
outside of page objects, e.g. Navigation utility
- Long-as-hell method names are actually OK
as long as they clarify the test
- Testability is a product requirement
- Cook data models into your elements
- Stop Xpath in its tracks. Use CSS selectors
Frontend Testability
Xpath Selector
//div[@class='example']//a
CSS Selector
div.example a
Frontend Testability
- Data attributes for testing framework - image name, image uuid
- Clear and concise selectors (ideally separate from styling concerns)
data attributes: image id, name
Concise selectors
- class .main-image
- Image track .slick-track
- Selection status .selected
- UI tests should limit UI interaction
to only the functionality being
tested
- Build a client to speak to your
backend through HTTP (still act
as an ‘outsider’ user)
- Setup test data, simply navigate
to it, and interact
- If you can’t expose your backend,
bootstrap test data beforehand
Use the Backend API
it('Validate Bob's profile', function () {
const user = apiClient.getUser('bob')
// if you know Bob's user id,
// you can go straight to his profile
driver.goToProfile(user.id)
const title = profilePage.getTitle()
assert.isEqual(title, 'Bob's Killer Profile')
})
The gordian knot:
- Selenium actions and the WebDriver
API are asynchronous
- JavaScript is built for asynchronicity
- Tests should run in a synchronous
manner and in a wholly deterministic
order
De-asyncing Tests
How to cleanly write async actions in a sync manner?
….sandwiches?
It’s like we finish each
other’s….
- At first, we used the promise manager extensively
- Heavily dependent on selenium-webdriver control flows
The promise manager / control flow
● Implicitly synchronizes asynchronous actions
● Coordinates the scheduling and execution of all commands
● Maintains a queue of scheduled tasks and executes them in order
De-asyncing Via Promise Manager
driver.get('http://www.google.com/ncr');
driver.findElement({name: 'q'}).sendKeys('webdriver');
driver.findElement({name: 'btnGn'}).click();
driver.get('http://www.google.com/ncr')
.then(function() {
return driver.findElement({name: 'q'});
})
.then(function(q) {
return q.sendKeys('webdriver');
})
.then(function() {
return driver.findElement({name: 'btnG'});
})
.then(function(btnG) {
return btnG.click();
});
test.it('Verify data from both frontend and backend', function() {
var apiClient = new ApiClient();
var projectFromBackend;
// API Portion of the test
var flow = webdriver.promise.controlFlow();
flow.execute(function *(){
yield webClient.login(USER001_EMAIL, USER_PASSWORD);
var projects = yield apiClient.getProjects();
projectFromBackend = projectutil.getProjectByName(projects, QA_PROJECT);
});
// UI Portion of the test
var login = new LoginPage(driver);
login.enterUserInfo(USER001_EMAIL, USER_PASSWORD);
var topNav = new TopNav(driver);
topNav.getProjects().then(function (projects){
Logger.debug('Projects from backend:', projectsFromBackend);
Logger.debug('Projects from frontend:', projects);
assert.equal(projectsFromBackend.size, projects.size);
});
- Not Readable / flat
- Not testrunner-agnostic
- Non-standard
API part of the test
HTTP Requests
Issues with Promise Manager
Context switch to
REST API calls
UI Part of the test
Selenium & Browser
var test = require('selenium-webdriver/testing');
JobsPage.prototype.getJobList = function () {
this.waitForDisplayed(By.css('.job-table'));
const jobNames = [];
const defer = promise.defer();
const flow = promise.controlFlow();
const jobList = this.driver.findElement(By.css('.job-table'));
// get entries
flow.execute(() => {
jobList.findElements(By.css('.show-pointer')).then((jobs) => {
// Get text on all the elements
jobs.forEach((job) => {
let jobName;
flow.execute(function () {
job.findElement(By.css('.job-table-row-name')).then((element) => {
element.getText().then((text) => {
jobName = text;
});
// look up more table cells...
});
}).then(() => {
jobNames.push({
jobName: jobName
});
});
});
});
}).then(() => {
// fulfill results
defer.fulfill(jobNames);
});
return defer.promise;
};
Bad complexity
+ promise chaining =
Async / Await
function notAsync () {
foo().then((bar) => {
console.log(bar)
});
}
async function isAsync() {
const bar = await foo();
console.log(bar)
}
Node > 7.6ES5
Given function foo() that returns a promise...
C’mon gang, let’s write a test!
https://github.com/airware/webdriver-mocha-async-await-example
- When reporting, consider what information you need in
order to be successful
- Failures First
- Flakiness vs. Failure
- Assertion messaging
- Screenshots
- Video
- Screenshots very useful if done right
- Integrate them into test reports
- Use them for visual testing (shoutout to Applitools)
Reporting and Visual Testing
Applitools - Automated Visual Testing
"I don't write tests, testing sucks"
"Test automation is easy with
JavaScript "
When You Talk About Test Automation
Airware github repo code example:
https://github.com/airware/webdriver-mocha-async-await-example
ForwardJS Organizers
Dave, Taylor, Tracy and team
Special Thanks
Saucelabs - browser CI infrastructure
Feedback on selenium and node.js prototyping
● Neil Manvar
● Kristian Meier
● Adam Pilger
● Christian Bromann
Applitools
Automated Visual Diff Engine from Applitools
● Moshe Milman
● Matan Carmi
● Adam Carmi
● Ryan Peterson
MochaJS
Github
#mochajs
Test runner
Selenium Webdriver
Github
Browser
Automation
WebdriverIO
Github
@webdriverio
Easy to use
Selenium API
Mature Mobile APIs
Appium
Github
@AppiumDevs
Mobile & Native Apps
Automation
JavaScript Community and Open Source Projects.
The world runs on OSS - Please help support these projects!
Thank you!
Q & A

Contenu connexe

Tendances

Hands on Exploration of Page Objects and Abstraction Layers with Selenium Web...
Hands on Exploration of Page Objects and Abstraction Layers with Selenium Web...Hands on Exploration of Page Objects and Abstraction Layers with Selenium Web...
Hands on Exploration of Page Objects and Abstraction Layers with Selenium Web...Alan Richardson
 
Automated Testing in Angular Slides
Automated Testing in Angular SlidesAutomated Testing in Angular Slides
Automated Testing in Angular SlidesJim Lynch
 
[CLIW] Web testing
[CLIW] Web testing[CLIW] Web testing
[CLIW] Web testingBogdan Gaza
 
Webdriver cheatsheets summary
Webdriver cheatsheets summaryWebdriver cheatsheets summary
Webdriver cheatsheets summaryAlan Richardson
 
GlobalLogic Test Automation Online TechTalk “Playwright — A New Hope”
GlobalLogic Test Automation Online TechTalk “Playwright — A New Hope”GlobalLogic Test Automation Online TechTalk “Playwright — A New Hope”
GlobalLogic Test Automation Online TechTalk “Playwright — A New Hope”GlobalLogic Ukraine
 
Automation Abstraction Layers: Page Objects and Beyond
Automation Abstraction Layers: Page Objects and BeyondAutomation Abstraction Layers: Page Objects and Beyond
Automation Abstraction Layers: Page Objects and BeyondAlan Richardson
 
Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015
Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015
Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015Codemotion
 
Protractor Tutorial Quality in Agile 2015
Protractor Tutorial Quality in Agile 2015Protractor Tutorial Quality in Agile 2015
Protractor Tutorial Quality in Agile 2015Andrew Eisenberg
 
Introduction to Protractor
Introduction to ProtractorIntroduction to Protractor
Introduction to ProtractorFlorian Fesseler
 
Better Page Object Handling with Loadable Component Pattern
Better Page Object Handling with Loadable Component PatternBetter Page Object Handling with Loadable Component Pattern
Better Page Object Handling with Loadable Component PatternSargis Sargsyan
 
Nightwatch JS for End to End Tests
Nightwatch JS for End to End TestsNightwatch JS for End to End Tests
Nightwatch JS for End to End TestsSriram Angajala
 
Introducing Playwright's New Test Runner
Introducing Playwright's New Test RunnerIntroducing Playwright's New Test Runner
Introducing Playwright's New Test RunnerApplitools
 
Protractor Testing Automation Tool Framework / Jasmine Reporters
Protractor Testing Automation Tool Framework / Jasmine ReportersProtractor Testing Automation Tool Framework / Jasmine Reporters
Protractor Testing Automation Tool Framework / Jasmine ReportersHaitham Refaat
 
Philip Shurpik "Architecting React Native app"
Philip Shurpik "Architecting React Native app"Philip Shurpik "Architecting React Native app"
Philip Shurpik "Architecting React Native app"Fwdays
 
Selenide Alternative in Practice - Implementation & Lessons learned [Selenium...
Selenide Alternative in Practice - Implementation & Lessons learned [Selenium...Selenide Alternative in Practice - Implementation & Lessons learned [Selenium...
Selenide Alternative in Practice - Implementation & Lessons learned [Selenium...Iakiv Kramarenko
 
Step by step - Selenium 3 web-driver - From Scratch
Step by step - Selenium 3 web-driver - From Scratch  Step by step - Selenium 3 web-driver - From Scratch
Step by step - Selenium 3 web-driver - From Scratch Haitham Refaat
 
Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...
Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...
Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...Iakiv Kramarenko
 
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)Cogapp
 

Tendances (20)

Night Watch with QA
Night Watch with QANight Watch with QA
Night Watch with QA
 
Hands on Exploration of Page Objects and Abstraction Layers with Selenium Web...
Hands on Exploration of Page Objects and Abstraction Layers with Selenium Web...Hands on Exploration of Page Objects and Abstraction Layers with Selenium Web...
Hands on Exploration of Page Objects and Abstraction Layers with Selenium Web...
 
Automated Testing in Angular Slides
Automated Testing in Angular SlidesAutomated Testing in Angular Slides
Automated Testing in Angular Slides
 
[CLIW] Web testing
[CLIW] Web testing[CLIW] Web testing
[CLIW] Web testing
 
Webdriver cheatsheets summary
Webdriver cheatsheets summaryWebdriver cheatsheets summary
Webdriver cheatsheets summary
 
GlobalLogic Test Automation Online TechTalk “Playwright — A New Hope”
GlobalLogic Test Automation Online TechTalk “Playwright — A New Hope”GlobalLogic Test Automation Online TechTalk “Playwright — A New Hope”
GlobalLogic Test Automation Online TechTalk “Playwright — A New Hope”
 
Automation Abstraction Layers: Page Objects and Beyond
Automation Abstraction Layers: Page Objects and BeyondAutomation Abstraction Layers: Page Objects and Beyond
Automation Abstraction Layers: Page Objects and Beyond
 
Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015
Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015
Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015
 
Protractor Tutorial Quality in Agile 2015
Protractor Tutorial Quality in Agile 2015Protractor Tutorial Quality in Agile 2015
Protractor Tutorial Quality in Agile 2015
 
Introduction to Protractor
Introduction to ProtractorIntroduction to Protractor
Introduction to Protractor
 
Better Page Object Handling with Loadable Component Pattern
Better Page Object Handling with Loadable Component PatternBetter Page Object Handling with Loadable Component Pattern
Better Page Object Handling with Loadable Component Pattern
 
Nightwatch JS for End to End Tests
Nightwatch JS for End to End TestsNightwatch JS for End to End Tests
Nightwatch JS for End to End Tests
 
Introducing Playwright's New Test Runner
Introducing Playwright's New Test RunnerIntroducing Playwright's New Test Runner
Introducing Playwright's New Test Runner
 
Protractor Testing Automation Tool Framework / Jasmine Reporters
Protractor Testing Automation Tool Framework / Jasmine ReportersProtractor Testing Automation Tool Framework / Jasmine Reporters
Protractor Testing Automation Tool Framework / Jasmine Reporters
 
Philip Shurpik "Architecting React Native app"
Philip Shurpik "Architecting React Native app"Philip Shurpik "Architecting React Native app"
Philip Shurpik "Architecting React Native app"
 
Selenide Alternative in Practice - Implementation & Lessons learned [Selenium...
Selenide Alternative in Practice - Implementation & Lessons learned [Selenium...Selenide Alternative in Practice - Implementation & Lessons learned [Selenium...
Selenide Alternative in Practice - Implementation & Lessons learned [Selenium...
 
Step by step - Selenium 3 web-driver - From Scratch
Step by step - Selenium 3 web-driver - From Scratch  Step by step - Selenium 3 web-driver - From Scratch
Step by step - Selenium 3 web-driver - From Scratch
 
Lean Quality & Engineering
Lean Quality & EngineeringLean Quality & Engineering
Lean Quality & Engineering
 
Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...
Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...
Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...
 
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
 

Similaire à ForwardJS 2017 - Fullstack end-to-end Test Automation with node.js

Automated acceptance test
Automated acceptance testAutomated acceptance test
Automated acceptance testBryan Liu
 
Selenium RC: Automated Testing of Modern Web Applications
Selenium RC: Automated Testing of Modern Web ApplicationsSelenium RC: Automated Testing of Modern Web Applications
Selenium RC: Automated Testing of Modern Web Applicationsqooxdoo
 
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJSAngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJSmurtazahaveliwala
 
Real world selenium resume which gets more job interviews
Real world selenium resume which gets more job interviewsReal world selenium resume which gets more job interviews
Real world selenium resume which gets more job interviewsABSoft Trainings
 
Protractor framework architecture with example
Protractor framework architecture with exampleProtractor framework architecture with example
Protractor framework architecture with exampleshadabgilani
 
Beginning AngularJS
Beginning AngularJSBeginning AngularJS
Beginning AngularJSTroy Miles
 
Continous UI testing with Espresso and Jenkins
Continous UI testing with Espresso and JenkinsContinous UI testing with Espresso and Jenkins
Continous UI testing with Espresso and JenkinsSylwester Madej
 
Test strategy for web development
Test strategy for web developmentTest strategy for web development
Test strategy for web developmentalice yang
 
Automation - web testing with selenium
Automation - web testing with seleniumAutomation - web testing with selenium
Automation - web testing with seleniumTzirla Rozental
 
Rest web service_with_spring_hateoas
Rest web service_with_spring_hateoasRest web service_with_spring_hateoas
Rest web service_with_spring_hateoasZeid Hassan
 
Front End Development for Back End Developers - vJUG24 2017
Front End Development for Back End Developers - vJUG24 2017Front End Development for Back End Developers - vJUG24 2017
Front End Development for Back End Developers - vJUG24 2017Matt Raible
 
VishalSinha_Resume_Ora
VishalSinha_Resume_OraVishalSinha_Resume_Ora
VishalSinha_Resume_OraVishal Sinha
 
Using HttpWatch Plug-in with Selenium Automation in Java
Using HttpWatch Plug-in with Selenium Automation in JavaUsing HttpWatch Plug-in with Selenium Automation in Java
Using HttpWatch Plug-in with Selenium Automation in JavaSandeep Tol
 
Selenium Testing Training in Bangalore
Selenium Testing Training in BangaloreSelenium Testing Training in Bangalore
Selenium Testing Training in Bangalorerajkamal560066
 
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)Ondřej Machulda
 
Deploying applications to Cloud with Google App Engine
Deploying applications to Cloud with Google App EngineDeploying applications to Cloud with Google App Engine
Deploying applications to Cloud with Google App EngineAlexander Zamkovyi
 
Java script unit testing
Java script unit testingJava script unit testing
Java script unit testingMats Bryntse
 
Python Ireland Nov 2009 Talk - Appengine
Python Ireland Nov 2009 Talk - AppenginePython Ireland Nov 2009 Talk - Appengine
Python Ireland Nov 2009 Talk - AppenginePython Ireland
 

Similaire à ForwardJS 2017 - Fullstack end-to-end Test Automation with node.js (20)

Automated acceptance test
Automated acceptance testAutomated acceptance test
Automated acceptance test
 
Selenium RC: Automated Testing of Modern Web Applications
Selenium RC: Automated Testing of Modern Web ApplicationsSelenium RC: Automated Testing of Modern Web Applications
Selenium RC: Automated Testing of Modern Web Applications
 
Protractor overview
Protractor overviewProtractor overview
Protractor overview
 
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJSAngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
 
Real world selenium resume which gets more job interviews
Real world selenium resume which gets more job interviewsReal world selenium resume which gets more job interviews
Real world selenium resume which gets more job interviews
 
Protractor framework architecture with example
Protractor framework architecture with exampleProtractor framework architecture with example
Protractor framework architecture with example
 
Beginning AngularJS
Beginning AngularJSBeginning AngularJS
Beginning AngularJS
 
Continous UI testing with Espresso and Jenkins
Continous UI testing with Espresso and JenkinsContinous UI testing with Espresso and Jenkins
Continous UI testing with Espresso and Jenkins
 
Test strategy for web development
Test strategy for web developmentTest strategy for web development
Test strategy for web development
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Automation - web testing with selenium
Automation - web testing with seleniumAutomation - web testing with selenium
Automation - web testing with selenium
 
Rest web service_with_spring_hateoas
Rest web service_with_spring_hateoasRest web service_with_spring_hateoas
Rest web service_with_spring_hateoas
 
Front End Development for Back End Developers - vJUG24 2017
Front End Development for Back End Developers - vJUG24 2017Front End Development for Back End Developers - vJUG24 2017
Front End Development for Back End Developers - vJUG24 2017
 
VishalSinha_Resume_Ora
VishalSinha_Resume_OraVishalSinha_Resume_Ora
VishalSinha_Resume_Ora
 
Using HttpWatch Plug-in with Selenium Automation in Java
Using HttpWatch Plug-in with Selenium Automation in JavaUsing HttpWatch Plug-in with Selenium Automation in Java
Using HttpWatch Plug-in with Selenium Automation in Java
 
Selenium Testing Training in Bangalore
Selenium Testing Training in BangaloreSelenium Testing Training in Bangalore
Selenium Testing Training in Bangalore
 
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
 
Deploying applications to Cloud with Google App Engine
Deploying applications to Cloud with Google App EngineDeploying applications to Cloud with Google App Engine
Deploying applications to Cloud with Google App Engine
 
Java script unit testing
Java script unit testingJava script unit testing
Java script unit testing
 
Python Ireland Nov 2009 Talk - Appengine
Python Ireland Nov 2009 Talk - AppenginePython Ireland Nov 2009 Talk - Appengine
Python Ireland Nov 2009 Talk - Appengine
 

Dernier

"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 

Dernier (20)

"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 

ForwardJS 2017 - Fullstack end-to-end Test Automation with node.js

  • 1. Full-Stack End-to-End Test Automation with Node.js One year later ForwardJS 2017 Chris Clayman Mek Stittri
  • 2. 2 First things first Airware, we are a drone company. We build complete enterprise drone solutions; Cloud Platform, Ground Control Station, Drone Integration and etc We are Hiring! - http://www.airware.com/careers ● iOS Software Engineer ● Javascript Software Engineer Or just come talk to us :)
  • 3. 3 A Bit About Us The Automation team at Airware, we do drone stuffs. Continuous Deployment & Test Automation tools aka Quality Ops Chris Clayman @chrisclayman github.com/kidmillions Mek Stittri @mekdev github.com/mekdev
  • 4. Overheard at the Monday workshops "I don't write tests, testing sucks" Let's talk About Test Automation Let us give you a warm hug.
  • 5. Why Node.js for Test Automation QA, Automation engineers Frontend engineers Backend engineers Java Javascript Java Python Javascript Java Ruby Javascript Node.js Company A Company B Company C Node.js Javascript Node.js Airware - Node.js adoption, more and more company moving to node.js - Share code with the whole engineering team - Play to the engineering team’s strength True Full-Stack Delivery Team
  • 6. Functional tests that interacts with the webapp as a user would. Full-Stack End-to-End Automation Visual UI Interaction Http Restful API Javascript Unit tests Microservice Integration Unit tests DB & Data Schema tests Martin Fowler - Test Pyramid, Google Testing Blog 2014 Google Test Automation Conference Tools for tests ● Visual Diff Engine ● Selenium-Webdriver ● REST API Client Small Unit tests Big E2E tests Medium Integration tests z’ Test Pyramid Cost of test Amount of tests
  • 7. Client implementation that maps to your HTTP RESTful Backend API Simulating browser AJAX calls and acts like a user. Via GET / POST / PUT / DELETE requests and etc.. Request libraries: - requests - https://github.com/request/request - request-promise - https://github.com/request/request-promise - etc... REST API Client
  • 8. Anyone here use selenium for automation ? Industry standard for web browser automation Language-neutral coding interface: C#, JavaScript , Java, Python, Ruby Official Project - https://github.com/SeleniumHQ/selenium Selenium Webdriver $ npm i selenium-webdriver
  • 9. Visual Diff Engine Bitmap comparison tool for screenshot validation. Validates a given screenshot against a baseline image Available tools: - Applitools - https://applitools.com/ integrates with selenium JS - Sikuli, roll your own framework - http://www.sikuli.org/ Baseline Changes
  • 10. Timeline Q2 2015 The Early Age Rapid Prototyping Phase The Middle Age “The Promise Manager” Evaluating multiple test frameworks Test Runner - Mocha / Karma - Ava / Jest API - Http library - request - co-request - request-promise - Supertest / Chakram UI - Selenium bindings - Nightwatch - WebdriverIO - selenium-webdriver (WebdriverJS) Q3 2015 Q3 2016 - Present - ES6/ES2015 - Promises - ESLint - Went with Mocha - Picked selenium-webdriver aka WebDriverJs Built-in Promise Manager (synchronous like behavior) - Went with co-request Generator calls, easier (synchronous like behavior) - Applitools visual diff - ES7/2016+ - Async Await - Babel - ESLint + StandardJS - Flowtype (facebook) - selenium-webdriver - Switched to request lib Async / Await solves a lot of the previous problems, no more callbacks or thenables The Modern Age “Async/Await” and beyond Lessons Learnt
  • 11. We made mistakes so you don’t have to! Recipe for a Node/Selenium Framework
  • 12. - Representation of Pages (Page Objects) - Readable tests - Frontend testability - Robust backend API - Clients to interact with said API - De-async testing approach - Visual tests - Accurate and descriptive reporting Automation Framework Ingredients
  • 13. - Representation of a page or component. - We use class syntax - Abstract UI interaction implementation to a BasePage or UI utility outside of the pageobject - Map page objects 1-to-1 to pages and components Page Object Model (POM) const CHANGE_PASSWORD_BTN = 'button.change-passwd' class ProfilePage extends BasePage { clickChangePassword () { click(CHANGE_PASSWORD_BTN) } }
  • 14. Readable Tests clusterImageGallery.currentSelectedImageAnnotationIndicatorExistsInTrack() Great work, Chip! - Anyone should be able to read or write tests - Abstract low level webdriver implementation outside of page objects, e.g. Navigation utility - Long-as-hell method names are actually OK as long as they clarify the test
  • 15. - Testability is a product requirement - Cook data models into your elements - Stop Xpath in its tracks. Use CSS selectors Frontend Testability Xpath Selector //div[@class='example']//a CSS Selector div.example a
  • 16. Frontend Testability - Data attributes for testing framework - image name, image uuid - Clear and concise selectors (ideally separate from styling concerns) data attributes: image id, name Concise selectors - class .main-image - Image track .slick-track - Selection status .selected
  • 17. - UI tests should limit UI interaction to only the functionality being tested - Build a client to speak to your backend through HTTP (still act as an ‘outsider’ user) - Setup test data, simply navigate to it, and interact - If you can’t expose your backend, bootstrap test data beforehand Use the Backend API it('Validate Bob's profile', function () { const user = apiClient.getUser('bob') // if you know Bob's user id, // you can go straight to his profile driver.goToProfile(user.id) const title = profilePage.getTitle() assert.isEqual(title, 'Bob's Killer Profile') })
  • 18. The gordian knot: - Selenium actions and the WebDriver API are asynchronous - JavaScript is built for asynchronicity - Tests should run in a synchronous manner and in a wholly deterministic order De-asyncing Tests How to cleanly write async actions in a sync manner? ….sandwiches? It’s like we finish each other’s….
  • 19. - At first, we used the promise manager extensively - Heavily dependent on selenium-webdriver control flows The promise manager / control flow ● Implicitly synchronizes asynchronous actions ● Coordinates the scheduling and execution of all commands ● Maintains a queue of scheduled tasks and executes them in order De-asyncing Via Promise Manager driver.get('http://www.google.com/ncr'); driver.findElement({name: 'q'}).sendKeys('webdriver'); driver.findElement({name: 'btnGn'}).click(); driver.get('http://www.google.com/ncr') .then(function() { return driver.findElement({name: 'q'}); }) .then(function(q) { return q.sendKeys('webdriver'); }) .then(function() { return driver.findElement({name: 'btnG'}); }) .then(function(btnG) { return btnG.click(); });
  • 20. test.it('Verify data from both frontend and backend', function() { var apiClient = new ApiClient(); var projectFromBackend; // API Portion of the test var flow = webdriver.promise.controlFlow(); flow.execute(function *(){ yield webClient.login(USER001_EMAIL, USER_PASSWORD); var projects = yield apiClient.getProjects(); projectFromBackend = projectutil.getProjectByName(projects, QA_PROJECT); }); // UI Portion of the test var login = new LoginPage(driver); login.enterUserInfo(USER001_EMAIL, USER_PASSWORD); var topNav = new TopNav(driver); topNav.getProjects().then(function (projects){ Logger.debug('Projects from backend:', projectsFromBackend); Logger.debug('Projects from frontend:', projects); assert.equal(projectsFromBackend.size, projects.size); }); - Not Readable / flat - Not testrunner-agnostic - Non-standard API part of the test HTTP Requests Issues with Promise Manager Context switch to REST API calls UI Part of the test Selenium & Browser var test = require('selenium-webdriver/testing');
  • 21. JobsPage.prototype.getJobList = function () { this.waitForDisplayed(By.css('.job-table')); const jobNames = []; const defer = promise.defer(); const flow = promise.controlFlow(); const jobList = this.driver.findElement(By.css('.job-table')); // get entries flow.execute(() => { jobList.findElements(By.css('.show-pointer')).then((jobs) => { // Get text on all the elements jobs.forEach((job) => { let jobName; flow.execute(function () { job.findElement(By.css('.job-table-row-name')).then((element) => { element.getText().then((text) => { jobName = text; }); // look up more table cells... }); }).then(() => { jobNames.push({ jobName: jobName }); }); }); }); }).then(() => { // fulfill results defer.fulfill(jobNames); }); return defer.promise; }; Bad complexity + promise chaining =
  • 22. Async / Await function notAsync () { foo().then((bar) => { console.log(bar) }); } async function isAsync() { const bar = await foo(); console.log(bar) } Node > 7.6ES5 Given function foo() that returns a promise...
  • 23. C’mon gang, let’s write a test! https://github.com/airware/webdriver-mocha-async-await-example
  • 24. - When reporting, consider what information you need in order to be successful - Failures First - Flakiness vs. Failure - Assertion messaging - Screenshots - Video - Screenshots very useful if done right - Integrate them into test reports - Use them for visual testing (shoutout to Applitools) Reporting and Visual Testing
  • 25.
  • 26. Applitools - Automated Visual Testing
  • 27. "I don't write tests, testing sucks" "Test automation is easy with JavaScript " When You Talk About Test Automation Airware github repo code example: https://github.com/airware/webdriver-mocha-async-await-example
  • 28. ForwardJS Organizers Dave, Taylor, Tracy and team Special Thanks Saucelabs - browser CI infrastructure Feedback on selenium and node.js prototyping ● Neil Manvar ● Kristian Meier ● Adam Pilger ● Christian Bromann Applitools Automated Visual Diff Engine from Applitools ● Moshe Milman ● Matan Carmi ● Adam Carmi ● Ryan Peterson MochaJS Github #mochajs Test runner Selenium Webdriver Github Browser Automation WebdriverIO Github @webdriverio Easy to use Selenium API Mature Mobile APIs Appium Github @AppiumDevs Mobile & Native Apps Automation JavaScript Community and Open Source Projects. The world runs on OSS - Please help support these projects!
  • 30. Q & A