Eng. Walter Lijo
lijowalter@gmail.com
API testing using Chakram.
15 y 16 de mayo, 2017
www.testinguy.org
#testinguy |@testinguy
What we are going to use ...
o Chakram
o http://dareid.github.io/chakram/
o Mocha
o https://mochajs.org/
o Chai
o http://chaijs.com/
o Mochawesome
o https://github.com/adamgruber/mochawesome
What is Chakram?
o Chakram is a REST API testing framework offering a BDD testing style and fully
exploiting promises
o This framework allows us to:
o Make HTTP Assertions
o Exploit Promises
o Use BDD + Hooks
o Extensibility
o Community support
What do we need?
o Project for MeetUp
o https://github.com/woolter/RestAPITesting
o ~/Documents $ git clone https://github.com/woolter/RestAPITesting.git
o ~/Documents $ cd RestAPITesting
o ~/Documents/RestAPITesting $ git checkout exercise
o Spring boot rest api example
o http://websystique.com/spring-boot/spring-boot-rest-api-example/
Step 1 - Getting Started
With the next few commands we can set up or project from scratch.
~/projectFolder $ npm install -g mocha
~/projectFolder $ npm init
~/projectFolder $ npm install --save-dev chakram
~/projectFolder $ npm install --save-dev mochawesome
~/projectFolder $ mkdir data
~/projectFolder $ mkdir test
To start our Spring boot rest api example
~/RestAPITesting/SpringBootRestApiExample $ mvn spring-boot:run
Step 2 - Get
o Create endpoint.json on data folder
o Create ddt.json on data folder
o Create 1_Get.js on test folder with this:
o Create variables for validation
https://jsonschema.net/#/editor
o Create function for all users and user by id
{
"user":"SpringBootRestApi/api/user/",
"userById":"SpringBootRestApi/api/user/{id}"
}
{
"environment":
{
"protocol":"http://",
"hostname":"localhost",
"port":":8080/"
}
}
let chakram = require('chakram');
let expect = chakram.expect;
endPoint = require('../data/endPoint.json');
ddt = require('../data/ddt.json');
"http://user:password@site
-----------------------------------------------------------
"login":"/j_spring_security_check?j_usernam
e={userName}&j_password={password}",
return chakram.get(request, {jar: cookie})
Step 2 - Get (continue)
o Basic test: get all users
o New test: get user by id
o Execute test
~/projectFolder/test $ mocha 1_Get.js
describe("Get", function () {
it("All User", function () {
return chakram.get(allUser())
.then(function (response) {
expect(response).to.have.schema(schemaGetAll);
expect(response.response.statusCode).to.equal(200);
})
});
});
it("User by ID", function () {
let userID = userById(1);
return chakram.get(userID)
.then(function (response) {
expect(response).to.have.schema(schemaGetById);
})
});
Step 3 - Post
o Create 2_Post.js on test folder with this:
o Add schema to create user
o Add variable for validation
o Add function for
o Create user
o Get user by Id
o Create test case to create user with existing user name
let chakram = require('chakram');
let expect = chakram.expect;
endPoint = require('../data/endPoint.json');
ddt = require('../data/ddt.json');
let bodyCreateUser = {
name: "",
age: "",
salary: ""
};
o Add data to ddt.json
"userData":{
"name":"yourName",
"age":35,
"salary":123456
}
it("Create a User with an existing name", function () {
bodyCreateUser.name = ddt.userData.name;
bodyCreateUser.age = ddt.userData.age;
bodyCreateUser.salary = ddt.userData.salary;
return chakram.post(createUser(), bodyCreateUser)
.then(function (response) {
expect(response.response.statusCode).to.equal(409);
expect(response.response.body.errorMessage).to.equal("Unable to
create. A User with name "+ddt.userData.name+" already" +
" exist.");
})
});
o Execute test
~/projectFolder/test $ mocha 2_Post.js
Step 4 - Put
o Create 3_Put.js on test folder with this:
o Add schema for update user
o Add function for
o Get user by Id
o Create test case to update age
let chakram = require('chakram');
let expect = chakram.expect;
endPoint = require('../data/endPoint.json');
ddt = require('../data/ddt.json');
let bodyCreteUser = {
name: "",
age: "",
salary: ""
};
it("Update Age", function () {
bodyCreateUser.name = userIdInformation.name;
bodyCreateUser.age = ddt.userData.ageUpdate;
bodyCreateUser.salary = userIdInformation.salary;
return chakram.put(userById(userIdToSearch),bodyCreateUser)
.then(function (response) {
expect(response.body.id).to.equal(userIdToSearch);
expect(response.body.name).to.equal(userIdInformation.name);
expect(response.body.age).to.equal(ddt.userData.ageUpdate);
expect(response.body.salary).to.equal(userIdInformation.salary);
})
});
o Execute test
~/projectFolder/test $ mocha 3_Put.js
Step 5 - Delete
o Create 4_Delete.js on test folder with:
o Required deferences
o Function to:
o Delete all user
o Delete user by Id
o Test case:
o Delete by Id
o Delete all
let chakram = require('chakram');
let expect = chakram.expect;
endPoint = require('../data/endPoint.json');
ddt = require('../data/ddt.json');ringBootRestApi/api/user/{id}"
function deleteAllUser() {
let users = ddt.environment.protocol + ddt.environment.hostname +
ddt.environment.port + endPoint.user;
return users;
}
function deleteUserById(id) {
let usersID = ddt.environment.protocol + ddt.environment.hostname +
ddt.environment.port + endPoint.userById;
usersID = usersID.replace("{id}", id);
return usersID;
}
describe("Delete", function () {
it("Delete by Id", function () {
let userID = deleteUserById(ddt.userData.deleteId);
return chakram.delete(userID)
.then(function (response) {
expect(response.response.statusCode).to.equal(204);
return chakram.get(userID)
.then(function (response) {
expect(response.response.body.errorMessage).to.equal("User
with id " + ddt.userData.deleteId + " not found");
})
})
});
});
it("All User", function () {
return chakram.delete(deleteAllUser())
.then(function (response) {
expect(response.response.statusCode).to.equal(204);
return chakram.get(deleteAllUser())
.then(function (response) {
expect(response.response.statusCode).to.equal(204);
console.log(response);
})
})
});
o Execute test
~/projectFolder/test $ mocha 4_Delete.js
Step 6 - Execute all test case
o Execute test
~/projectFolder $ mocha --recursive testCaseFolder/ --reporter mochawesome
Useful
o JavaScript function:
JSON.stringify();
o Schema validation:
http://json-schema.org/latest/json-schema-validation.html
o Json schema creator
https://jsonschema.net/#/editor
o MeetUp
https://www.meetup.com/es/TestingAR/
o Slack
https://wt-iesmite-gmail_com-0.run.webtask.io/testingar-signup
o Twitter
@TestingARMeetup
Ing. Walter Lijo
lijowalter@gmail.com
¿PREGUNTAS?
¡MUCHAS GRACIAS!
15 y 16 de mayo, 2017
www.testinguy.org
#testinguy |@testinguy

More Related Content

PDF
Introduction to Meteor at ChaDev Lunch
PPT
Praktik Pengembangan Konten E-Learning HTML5 Sederhana
PDF
[Hatsune Miku] Shoot Frieza with Amazon Kinesis ! [EN]
PDF
Bkbiet day2 & 3
PDF
Security Challenges in Node.js
PDF
Groovy And Grails JUG Padova
PDF
Fun Teaching MongoDB New Tricks
PDF
Getting Started With #Drools 6 Slides - JBUG Denmark
Introduction to Meteor at ChaDev Lunch
Praktik Pengembangan Konten E-Learning HTML5 Sederhana
[Hatsune Miku] Shoot Frieza with Amazon Kinesis ! [EN]
Bkbiet day2 & 3
Security Challenges in Node.js
Groovy And Grails JUG Padova
Fun Teaching MongoDB New Tricks
Getting Started With #Drools 6 Slides - JBUG Denmark

What's hot (20)

PDF
NoSQL Injections in Node.js - The case of MongoDB
PPTX
Gradle basics
PPTX
GC Tuning & Troubleshooting Crash Course
PDF
JavaScript & HTML5 - Brave New World
PDF
Drools, jBPM OptaPlanner presentation
PPTX
Mongo db updatedocumentusecases
PDF
Upgrading Grails 1.x to 2
PDF
JJUG CCC 2011 Spring
PDF
Creating Applications with WebGL and Three.js
PPT
Enhance Web Performance
PDF
mDevCamp - The Best from Google IO
KEY
Lazy Loading Because I'm Lazy
DOC
Qtp script to connect access database
PDF
MongoDB Indexing Constraints and Creative Schemas
PDF
HTML,CSS Next
PDF
AWS 9월 웨비나 | AWS Lambda@Edge를 통한 엣지 컴퓨팅 서비스
PPT
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
PDF
Operational transformation
PDF
JavaScript Abstraction
NoSQL Injections in Node.js - The case of MongoDB
Gradle basics
GC Tuning & Troubleshooting Crash Course
JavaScript & HTML5 - Brave New World
Drools, jBPM OptaPlanner presentation
Mongo db updatedocumentusecases
Upgrading Grails 1.x to 2
JJUG CCC 2011 Spring
Creating Applications with WebGL and Three.js
Enhance Web Performance
mDevCamp - The Best from Google IO
Lazy Loading Because I'm Lazy
Qtp script to connect access database
MongoDB Indexing Constraints and Creative Schemas
HTML,CSS Next
AWS 9월 웨비나 | AWS Lambda@Edge를 통한 엣지 컴퓨팅 서비스
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
Operational transformation
JavaScript Abstraction
Ad

Similar to Taller evento TestingUY 2017 - API Testing utilizando Chakram (20)

PDF
Intro To JavaScript Unit Testing - Ran Mizrahi
PDF
Testing in JavaScript
PDF
5 levels of api test automation
PDF
Quality and reliability: more types of testing
PPTX
How do I write Testable Javascript so I can Test my CF API on Server and Client
PPTX
Introduction to bdd
PDF
Xitrum @ Scala Matsuri Tokyo 2014
PDF
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
PDF
How do I Write Testable Javascript so I can Test my CF API on Server and Client
PDF
Next-Level API Automation Testing Techniques – Part 2
PDF
Testing Java Code Effectively
PDF
Intro to JavaScript Testing
PDF
API Days Australia - Automatic Testing of (RESTful) API Documentation
PDF
World-Class Testing Development Pipeline for Android
PDF
Unit testing with mocha
PDF
API Days Paris - Automatic Testing of (RESTful) API Documentation
PDF
Testing in android
PPTX
Full Stack Unit Testing
PDF
Karate - powerful and simple framework for REST API automation testing
PPTX
Nodejs do teste de unidade ao de integração
Intro To JavaScript Unit Testing - Ran Mizrahi
Testing in JavaScript
5 levels of api test automation
Quality and reliability: more types of testing
How do I write Testable Javascript so I can Test my CF API on Server and Client
Introduction to bdd
Xitrum @ Scala Matsuri Tokyo 2014
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
How do I Write Testable Javascript so I can Test my CF API on Server and Client
Next-Level API Automation Testing Techniques – Part 2
Testing Java Code Effectively
Intro to JavaScript Testing
API Days Australia - Automatic Testing of (RESTful) API Documentation
World-Class Testing Development Pipeline for Android
Unit testing with mocha
API Days Paris - Automatic Testing of (RESTful) API Documentation
Testing in android
Full Stack Unit Testing
Karate - powerful and simple framework for REST API automation testing
Nodejs do teste de unidade ao de integração
Ad

More from TestingUy (20)

PDF
Webinar TestingUy - Cuando el testing no es opcional
PDF
Webinar TestingUy - Usando Principios del Testing de Software en Tiempos de C...
PDF
Webinar TestingUy - Sesgos cognitivos en las pruebas. El lado más humano de...
PDF
Webinar TestingUy - Thinking outside the box: Cognitive bias and testing
PDF
TestingPy meetup - Invitación TestingUy 2020
PDF
Meetup TestingUy 2019 - Plataforma de integración y testing continuo
PDF
Meetup TestingUy 2019 - May the automation be with you
PDF
Meetup TestingUy 2019 - De árboles, de bosques y de selvas ¿qué visión tengo ...
PDF
Meetup TestingUy 2019 - En clave de protocolo con apache JMeter
PDF
Meetup TestingUy 2019 - Si Tony Stark fuera Tester
PDF
Meetup TestingUy 2019 - ¿Test cases? ¿Son siempre necesarios?
PDF
Charla TestingUy 2019 - ¿Podemos hacer que la seguridad sea usable?
PDF
Charla TestingUy 2019 - Testers as Test Consultants: How to learn the skills?
PDF
Charla TestingUy 2019 - Ready Tester One? Go!
PDF
Charla TestingUy 2019 - Patterns Para Enseñar Testing a Personas que No Desar...
PDF
Charla TestingUy 2019 - Contract Testing con Pact
PDF
Charla TestingUy 2019 - Testing de chatbots
PDF
Charla TestingUy 2019 - Cypress.io - Automatización al siguiente nivel
PDF
Charla testingUy 2019 - ¿De dónde venimos y qué se nos viene? - Evolución de ...
PDF
Charla TestingUy 2019 - Pruebas de rendimiento, experiencias en la plataforma...
Webinar TestingUy - Cuando el testing no es opcional
Webinar TestingUy - Usando Principios del Testing de Software en Tiempos de C...
Webinar TestingUy - Sesgos cognitivos en las pruebas. El lado más humano de...
Webinar TestingUy - Thinking outside the box: Cognitive bias and testing
TestingPy meetup - Invitación TestingUy 2020
Meetup TestingUy 2019 - Plataforma de integración y testing continuo
Meetup TestingUy 2019 - May the automation be with you
Meetup TestingUy 2019 - De árboles, de bosques y de selvas ¿qué visión tengo ...
Meetup TestingUy 2019 - En clave de protocolo con apache JMeter
Meetup TestingUy 2019 - Si Tony Stark fuera Tester
Meetup TestingUy 2019 - ¿Test cases? ¿Son siempre necesarios?
Charla TestingUy 2019 - ¿Podemos hacer que la seguridad sea usable?
Charla TestingUy 2019 - Testers as Test Consultants: How to learn the skills?
Charla TestingUy 2019 - Ready Tester One? Go!
Charla TestingUy 2019 - Patterns Para Enseñar Testing a Personas que No Desar...
Charla TestingUy 2019 - Contract Testing con Pact
Charla TestingUy 2019 - Testing de chatbots
Charla TestingUy 2019 - Cypress.io - Automatización al siguiente nivel
Charla testingUy 2019 - ¿De dónde venimos y qué se nos viene? - Evolución de ...
Charla TestingUy 2019 - Pruebas de rendimiento, experiencias en la plataforma...

Recently uploaded (20)

PDF
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
PPTX
O2C Customer Invoices to Receipt V15A.pptx
DOCX
search engine optimization ppt fir known well about this
PDF
A review of recent deep learning applications in wood surface defect identifi...
PDF
STKI Israel Market Study 2025 version august
PDF
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
PPT
Module 1.ppt Iot fundamentals and Architecture
PPTX
observCloud-Native Containerability and monitoring.pptx
PDF
Getting Started with Data Integration: FME Form 101
PDF
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
PDF
A novel scalable deep ensemble learning framework for big data classification...
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PDF
NewMind AI Weekly Chronicles – August ’25 Week III
PDF
Taming the Chaos: How to Turn Unstructured Data into Decisions
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
CloudStack 4.21: First Look Webinar slides
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PDF
DP Operators-handbook-extract for the Mautical Institute
PDF
Enhancing emotion recognition model for a student engagement use case through...
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
O2C Customer Invoices to Receipt V15A.pptx
search engine optimization ppt fir known well about this
A review of recent deep learning applications in wood surface defect identifi...
STKI Israel Market Study 2025 version august
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
Module 1.ppt Iot fundamentals and Architecture
observCloud-Native Containerability and monitoring.pptx
Getting Started with Data Integration: FME Form 101
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
A novel scalable deep ensemble learning framework for big data classification...
Final SEM Unit 1 for mit wpu at pune .pptx
NewMind AI Weekly Chronicles – August ’25 Week III
Taming the Chaos: How to Turn Unstructured Data into Decisions
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
CloudStack 4.21: First Look Webinar slides
A comparative study of natural language inference in Swahili using monolingua...
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
DP Operators-handbook-extract for the Mautical Institute
Enhancing emotion recognition model for a student engagement use case through...

Taller evento TestingUY 2017 - API Testing utilizando Chakram

  • 1. Eng. Walter Lijo lijowalter@gmail.com API testing using Chakram. 15 y 16 de mayo, 2017 www.testinguy.org #testinguy |@testinguy
  • 2. What we are going to use ... o Chakram o http://dareid.github.io/chakram/ o Mocha o https://mochajs.org/ o Chai o http://chaijs.com/ o Mochawesome o https://github.com/adamgruber/mochawesome
  • 3. What is Chakram? o Chakram is a REST API testing framework offering a BDD testing style and fully exploiting promises o This framework allows us to: o Make HTTP Assertions o Exploit Promises o Use BDD + Hooks o Extensibility o Community support
  • 4. What do we need? o Project for MeetUp o https://github.com/woolter/RestAPITesting o ~/Documents $ git clone https://github.com/woolter/RestAPITesting.git o ~/Documents $ cd RestAPITesting o ~/Documents/RestAPITesting $ git checkout exercise o Spring boot rest api example o http://websystique.com/spring-boot/spring-boot-rest-api-example/
  • 5. Step 1 - Getting Started With the next few commands we can set up or project from scratch. ~/projectFolder $ npm install -g mocha ~/projectFolder $ npm init ~/projectFolder $ npm install --save-dev chakram ~/projectFolder $ npm install --save-dev mochawesome ~/projectFolder $ mkdir data ~/projectFolder $ mkdir test To start our Spring boot rest api example ~/RestAPITesting/SpringBootRestApiExample $ mvn spring-boot:run
  • 6. Step 2 - Get o Create endpoint.json on data folder o Create ddt.json on data folder o Create 1_Get.js on test folder with this: o Create variables for validation https://jsonschema.net/#/editor o Create function for all users and user by id { "user":"SpringBootRestApi/api/user/", "userById":"SpringBootRestApi/api/user/{id}" } { "environment": { "protocol":"http://", "hostname":"localhost", "port":":8080/" } } let chakram = require('chakram'); let expect = chakram.expect; endPoint = require('../data/endPoint.json'); ddt = require('../data/ddt.json'); "http://user:password@site ----------------------------------------------------------- "login":"/j_spring_security_check?j_usernam e={userName}&j_password={password}", return chakram.get(request, {jar: cookie})
  • 7. Step 2 - Get (continue) o Basic test: get all users o New test: get user by id o Execute test ~/projectFolder/test $ mocha 1_Get.js describe("Get", function () { it("All User", function () { return chakram.get(allUser()) .then(function (response) { expect(response).to.have.schema(schemaGetAll); expect(response.response.statusCode).to.equal(200); }) }); }); it("User by ID", function () { let userID = userById(1); return chakram.get(userID) .then(function (response) { expect(response).to.have.schema(schemaGetById); }) });
  • 8. Step 3 - Post o Create 2_Post.js on test folder with this: o Add schema to create user o Add variable for validation o Add function for o Create user o Get user by Id o Create test case to create user with existing user name let chakram = require('chakram'); let expect = chakram.expect; endPoint = require('../data/endPoint.json'); ddt = require('../data/ddt.json'); let bodyCreateUser = { name: "", age: "", salary: "" }; o Add data to ddt.json "userData":{ "name":"yourName", "age":35, "salary":123456 } it("Create a User with an existing name", function () { bodyCreateUser.name = ddt.userData.name; bodyCreateUser.age = ddt.userData.age; bodyCreateUser.salary = ddt.userData.salary; return chakram.post(createUser(), bodyCreateUser) .then(function (response) { expect(response.response.statusCode).to.equal(409); expect(response.response.body.errorMessage).to.equal("Unable to create. A User with name "+ddt.userData.name+" already" + " exist."); }) }); o Execute test ~/projectFolder/test $ mocha 2_Post.js
  • 9. Step 4 - Put o Create 3_Put.js on test folder with this: o Add schema for update user o Add function for o Get user by Id o Create test case to update age let chakram = require('chakram'); let expect = chakram.expect; endPoint = require('../data/endPoint.json'); ddt = require('../data/ddt.json'); let bodyCreteUser = { name: "", age: "", salary: "" }; it("Update Age", function () { bodyCreateUser.name = userIdInformation.name; bodyCreateUser.age = ddt.userData.ageUpdate; bodyCreateUser.salary = userIdInformation.salary; return chakram.put(userById(userIdToSearch),bodyCreateUser) .then(function (response) { expect(response.body.id).to.equal(userIdToSearch); expect(response.body.name).to.equal(userIdInformation.name); expect(response.body.age).to.equal(ddt.userData.ageUpdate); expect(response.body.salary).to.equal(userIdInformation.salary); }) }); o Execute test ~/projectFolder/test $ mocha 3_Put.js
  • 10. Step 5 - Delete o Create 4_Delete.js on test folder with: o Required deferences o Function to: o Delete all user o Delete user by Id o Test case: o Delete by Id o Delete all let chakram = require('chakram'); let expect = chakram.expect; endPoint = require('../data/endPoint.json'); ddt = require('../data/ddt.json');ringBootRestApi/api/user/{id}" function deleteAllUser() { let users = ddt.environment.protocol + ddt.environment.hostname + ddt.environment.port + endPoint.user; return users; } function deleteUserById(id) { let usersID = ddt.environment.protocol + ddt.environment.hostname + ddt.environment.port + endPoint.userById; usersID = usersID.replace("{id}", id); return usersID; } describe("Delete", function () { it("Delete by Id", function () { let userID = deleteUserById(ddt.userData.deleteId); return chakram.delete(userID) .then(function (response) { expect(response.response.statusCode).to.equal(204); return chakram.get(userID) .then(function (response) { expect(response.response.body.errorMessage).to.equal("User with id " + ddt.userData.deleteId + " not found"); }) }) }); }); it("All User", function () { return chakram.delete(deleteAllUser()) .then(function (response) { expect(response.response.statusCode).to.equal(204); return chakram.get(deleteAllUser()) .then(function (response) { expect(response.response.statusCode).to.equal(204); console.log(response); }) }) }); o Execute test ~/projectFolder/test $ mocha 4_Delete.js
  • 11. Step 6 - Execute all test case o Execute test ~/projectFolder $ mocha --recursive testCaseFolder/ --reporter mochawesome
  • 12. Useful o JavaScript function: JSON.stringify(); o Schema validation: http://json-schema.org/latest/json-schema-validation.html o Json schema creator https://jsonschema.net/#/editor
  • 14. Ing. Walter Lijo lijowalter@gmail.com ¿PREGUNTAS? ¡MUCHAS GRACIAS! 15 y 16 de mayo, 2017 www.testinguy.org #testinguy |@testinguy