Top Banner
WEB API TEST AUTOMATION FRISBY NODE.JS Bao Nguyen Quang To SHIFT ASIA
30

Web API Test Automation using Frisby & Node.js

Jan 22, 2018

Download

Technology

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Web API Test Automation using Frisby  & Node.js

WEB API TEST AUTOMATION

FRISBY – NODE.JS

Bao Nguyen – Quang ToSHIFT ASIA

Page 2: Web API Test Automation using Frisby  & Node.js

Agenda

• Introduction

• This session discusses:– Web API Test

– Frisby

– A case study from SHIFT ASIA

• Technology discussed:– Node.js

– REST APIs with JSON

• Code download available at:– https://bitbucket.org/ShiftAsia/api_test

2

Page 3: Web API Test Automation using Frisby  & Node.js

Bao Nguyen

• R&D Manager at SHIFT ASIA

• Full-stack developer

Quang To

• Test Engineer at SHIFT ASIA

• Experience in various aspects of Testing

3

Introduction

Page 4: Web API Test Automation using Frisby  & Node.js

Objectives

Upon completion of the meetup, audiences should be able to:

• Understand Web APIs

• Differentiate SOAP from REST Web APIs

• Learn well-known API Test tools

• Develop API Test Automation using Frisby and Node.js

4

Page 5: Web API Test Automation using Frisby  & Node.js

5

Web API Test

Page 6: Web API Test Automation using Frisby  & Node.js

API – Overview

6

Page 7: Web API Test Automation using Frisby  & Node.js

API – Overview

7

API

Web Service

SOAP REST

Page 8: Web API Test Automation using Frisby  & Node.js

SOAP

• Simple Object Access Protocol

• Standardized protocol

• Rely heavily on XML

• Use WSDL (Web Service Definition Language) as a contract between the provider and the consumer of the service

REST

• REpresentational State Transfer

• Architectural style

• JSON is preferred

• Use HTTP standard verbs, such as: GET, POST, PUT, DELETE

8

SOAP vs. REST

Page 9: Web API Test Automation using Frisby  & Node.js

Why API Test?

• System complexity increased

Multi-tiered model with private APIs making up the middleware

• A huge demand of public APIs

• Getting feedback as soon as possible

9

Page 10: Web API Test Automation using Frisby  & Node.js

API – Hierarchy of Needs

10

apiux.com

Page 11: Web API Test Automation using Frisby  & Node.js

Web REST API Call

11

1Request

Url + Verb

2Response

Status code + Header + Body

http://swapi.co/api/people/1/

allow →GET, HEAD, OPTIONScontent-type →application/jsonvary →Accept

{"name": "Luke Skywalker",“height": "172",“mass": “77",“hair_color": “blond“,…}

HTTP status →200 OK

Page 12: Web API Test Automation using Frisby  & Node.js

Web API Test Checkpoints

• Status code

• Returned value

• Schema

• Response time

12

Page 13: Web API Test Automation using Frisby  & Node.js

API Test Tools

• Scriptless tools

13

• Scripting tools/frameworks

Page 14: Web API Test Automation using Frisby  & Node.js

14

Frisby

Page 15: Web API Test Automation using Frisby  & Node.js

Frisby – Overview

• REST API testing framework built on Node.js

• Simple

• Fast

• Continuous Integration

• http://frisbyjs.com/

• npm install --save-dev frisby

15

Page 16: Web API Test Automation using Frisby  & Node.js

API Verbs

16

HTTP Verb CRUDEntire Collection

(e.g. /users)Specific Item

(e.g. /users/{id})

POST Create 201 (Created) 404 (Not Found), 409 (Conflict) if resource already exists.

GET Read 200 (OK) 200 (OK), single user. 404 (Not Found), if ID not found or invalid.

PUT Update/Replace 404 (Not Found) 200 (OK) or 204 (No Content). 404 (Not Found), if ID not found or invalid.

PATCH Update/Modify 404 (Not Found) 200 (OK) or 204 (No Content). 404 (Not Found), if ID not found or invalid.

DELETE Delete 404 (Not Found) 200 (OK). 404 (Not Found), if ID not found or invalid.

Page 17: Web API Test Automation using Frisby  & Node.js

Frisby – Methods

• HTTP methods

– Post()

– Get()

– Put()

– Patch()

– Delete()

17

Page 18: Web API Test Automation using Frisby  & Node.js

Frisby – Methods

• Expectations

– expectStatus()

– expectHeader()

– expectHeaderContains()

– expectHeaderToMatch()

– expectJSON()

– expectBodyContains()

– expectJSONTypes()

– expectJSONLength()

– expectMaxResponseTime()

18

Status code

Returned value

Returned value

Returned value

Returned value

Returned value

Schema

Schema

Response time

Page 19: Web API Test Automation using Frisby  & Node.js

Frisby – Demo

• POST

• GET

• PUT

• DELETE

19

Page 20: Web API Test Automation using Frisby  & Node.js

Frisby – Challenges

• Documentation

Lack of more detailed examples

• Poor debugging info

20

Page 21: Web API Test Automation using Frisby  & Node.js

Frisby – Challenges

• Asynchronous

• Demo

21

Test API 1 API 2Request 1

Response 1

Request 2

Response 2

Response values transferred

Page 22: Web API Test Automation using Frisby  & Node.js

Frisby – Challenges

• Solution = Callback

• Demo

22

Page 23: Web API Test Automation using Frisby  & Node.js

Frisby – Challenges

• Another concern with Callback

• Demo

23

Page 24: Web API Test Automation using Frisby  & Node.js

Frisby – Challenges

24

Page 25: Web API Test Automation using Frisby  & Node.js

Frisby – Challenges

• Solution = async• npm install --save async• Demo

25

Page 26: Web API Test Automation using Frisby  & Node.js

26

A Case Study from SHIFT ASIA

Page 27: Web API Test Automation using Frisby  & Node.js

SHIFT ASIA – Methodology

27

Requirements User Stories

Test Cases

Test Scripts

Test Designer

Test Engineer

Tester

Tester

Page 28: Web API Test Automation using Frisby  & Node.js

#AutomateBuild#AutomateTestExecution

#AutomateReporting

SHIFT ASIA – Case Study

28

TEST SCRIPTTester#TestDevelopment

SCRIPT GENERATIONTest Engineer#Utility#Helpers

HARD-CORETest Architect#StandardStructure#NamingConvention#Settings#Modules Node.js

FrisbyJasmine-node

shelljs

Helper modules

Test in Yaml Data in Yaml

Yaml to JSON files

Run API tests

Page 29: Web API Test Automation using Frisby  & Node.js

SHIFT ASIA – Case Study

29

Yaml to JSON

JSON to Spec

Run

Tester

Page 30: Web API Test Automation using Frisby  & Node.js

© 2014 HCMC Software Testing Club

THANK YOU