web api test automation using frisby & node.js

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

Upload: chi-lang-le-vu-tran

Post on 22-Jan-2018

133 views

Category:

Technology


0 download

TRANSCRIPT

WEB API TEST AUTOMATION

FRISBY – NODE.JS

Bao Nguyen – Quang ToSHIFT ASIA

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

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

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

5

Web API Test

API – Overview

6

API – Overview

7

API

Web Service

SOAP REST

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

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

API – Hierarchy of Needs

10

apiux.com

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

Web API Test Checkpoints

• Status code

• Returned value

• Schema

• Response time

12

API Test Tools

• Scriptless tools

13

• Scripting tools/frameworks

14

Frisby

Frisby – Overview

• REST API testing framework built on Node.js

• Simple

• Fast

• Continuous Integration

• http://frisbyjs.com/

• npm install --save-dev frisby

15

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.

Frisby – Methods

• HTTP methods

– Post()

– Get()

– Put()

– Patch()

– Delete()

17

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

Frisby – Demo

• POST

• GET

• PUT

• DELETE

19

Frisby – Challenges

• Documentation

Lack of more detailed examples

• Poor debugging info

20

Frisby – Challenges

• Asynchronous

• Demo

21

Test API 1 API 2Request 1

Response 1

Request 2

Response 2

Response values transferred

Frisby – Challenges

• Solution = Callback

• Demo

22

Frisby – Challenges

• Another concern with Callback

• Demo

23

Frisby – Challenges

24

Frisby – Challenges

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

25

26

A Case Study from SHIFT ASIA

SHIFT ASIA – Methodology

27

Requirements User Stories

Test Cases

Test Scripts

Test Designer

Test Engineer

Tester

Tester

#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

SHIFT ASIA – Case Study

29

Yaml to JSON

JSON to Spec

Run

Tester

© 2014 HCMC Software Testing Club

THANK YOU