Автоматизация тестирования API для начинающих

Preview:

Citation preview

1

Automation of web service testing for the beginners

FEBRYARY 26, 2017

2

Andrei Stasevich

Experience • M.Sc. of engineering with more then 5 years

experience • Main IT specialization: Test Automation• Technology: Java, Selenium• COMAQA.by community activistAndrei Stasevich

EPAM Systems Software Test

Automation Engineer

3

AGENDA

Introduction to API1

What is web service2

SOAP and REST5

Examples6

Ways of communication3

Web Service testing4

4

INTRODUCTION TO API

Application programming interface (API) - a set of clearly defined methods of communication between various software components.

• Web service

• Libraries

• Operation system API

• Graphical/sound interfaces

5

API is like User Interface - just with different users in mind.

INTRODUCTION TO API

6

AGENDA

Introduction to API1

What is web service2

SOAP and REST5

Examples6

Ways of communication3

Web Service testing4

7

WHAT IS WEB SERVICE?

Web service - software system designed to support interoperable machine-to-machine interaction over a network.

• It accessible over the Internet or private networks.

• Is not tied to any one operating system or programming language.

• Used for direct application-to-application interaction.

• Uses XML (JSON) messages for interaction.

Every Web Service is an API but not every API is a Web Service

8

WHAT IS WEB SERVICE?

• The client bundles the information into a message (request).• Client and server establish connection and sent message as the body

of an HTTP request.• Service processes the received information.• Service packages the response, and sends it back to the client

program. • The client program unpacks the request to obtain the result.

9

WHAT IS WEB SERVICE?

• Establishing TCP connection.• Client sends version of the TLS protocol, the list

of supported ciphersuites, and other TLS options.

• The server picks the TLS protocol version, decides on a ciphersuite, attaches its certificate.

• The client initiates key exchange, which is used to establish the symmetric key.

• The server returns an encrypted Finished message back to the client.

• The client decrypts the message and if all is well, then the tunnel is established.

10

WHAT IS WEB SERVICE?center=NYzoom=13size=640x640maptype=road

GET https://maps.googleapis.com/maps/api/staticmap?center=NY&zoom=13&size=640x640&maptype=roadmap&key=AIzaSyDH7iC

centerzoomsizemaptypekey…

HTTP/1.1 200 OKContent-Type: image/png

11

AGENDA

Introduction to API1

What is web service2

SOAP and REST5

Examples6

Ways of communication3

Web Service testing4

12

WAYS OF COMMUNICATION

XML is a markup language that defines a set of rules for encoding documents in a format that is both human-readable and machine-readable. XML is a language-independent data format.

JSON is an open-standard format that uses human-readable text to transmit data objects consisting of attribute–value pairs. JSON is a language-independent data format.

13

WAYS OF COMMUNICATION

XML (Extensible Markup Language) is a markup language that defines a set of rules for encoding documents in a format that is both human-readable and machine-readable.XML was designed to describe dataXML is about carrying information – within TAGs

Tags are not predefined – make your own onesXML document does not DO anything so to say

• It is just information wrapped in tags• Custom code needed for interpretation

XML is a software - and hardware-independent tool • Used to store and transport information

14

WAYS OF COMMUNICATION

An XML element can contain: • Other elements• Any given text• Attributes • Mix of the previouos

Comments may appear anywhere• An example of a valid comment: <!–- the comment itself

-->

15

WAYS OF COMMUNICATION

JSON is an open-standard format that uses human-readable text to transmit data objects consisting of attribute–value pairs. JSON is a language-independent data format.

JSON is a syntax for storing and exchanging data • An easier-to-use alternative to XML

The JSON format is well fitted for Java and JavaScript• Very lightweight • Easy to process for services

16

WAYS OF COMMUNICATION

JSON's basic data types are:• Number• String• Boolean• Array• Object• null

• Square brackets hold arrays

JSON syntax is a subset of the JavaScript syntax:

• Data is in „name:value” pairs

• Data is separated by commas• Curly braces hold objects

• Interestingly, there are no comments in JSON

17

18

AGENDA

Introduction to API1

What is web service2

SOAP and REST5

Examples6

Ways of communication3

Web Service testing4

19

WEB SERVICE TESTING

Happy paths•Using the provided method calls•Analyzing the returned data •Trying out different parameters•Response validation

20

Web Service testing

Unhappy paths•Using wrong URIs •Invalid or missing parameters•See how the server responds to those•Client or server side errors

21

AGENDA

Introduction to API1

What is web service2

SOAP and REST5

Examples6

Ways of communication3

Web Service testing4

22

SOAP

SOAP (Simple Object Access Protocol) is a protocol specification for exchanging structured information in XML format.

SOA web-services:• Service provider: creates a web service and provides its information to the service broker. • Service broker UDDI: makes the information regarding the web service available to any

potential requester.• Service requester: locates entries in the broker registry using various find

operations and then binds to the service provider in order to invoke one of its web services.

Rules for communication are defined in WSDL file(Web Services Description Language):

• How one system can request data from another system.• Specific parameters.• The structure of the data. • Error messages.

23

WSDL

<binding> - поддерживаемые протоколы.<message> - сообщения Web-службы (запрос, ответ).<portType> — все доступные методы.<service> — URI службы.<types> — используемые типы данных.

24

SOAP

SOAP provides the envelope for sending Web Services messages over the HTTP/SMTP.

The SOAP envelope contains two parts:

• SOAP Header (optional): providing information on authentication, encoding of data, or how a recipient of a SOAP message should process the message.

• SOAP Body: contains the message. These messages can be defined using the WSDL specification.

25

SOAP

26

REST

Representational State Transfer (REST) is a style of architecture based on a set of principles that describe how networked resources are defined and addressed. • Client-Server

• Stateless

• Cacheable

• Layered system

• Code on demand

• Uniform interface

27

REST

REST-compliant Web services allow requesting systems to access and manipulate textual representations of Web resources using a uniform and predefined set of stateless operations. "Web resources" were first defined  as documents or files identified by their URLs.

POST http://www.example.com/customers

GET http://www.example.com/customers/33245DELETE http://www.example.com/customers/33245

PUT http://www.example.com/customers/33245

28

AGENDA

Introduction to API1

What is web service2

SOAP and REST5

Examples6

Ways of communication3

Web Service testing4

29

Test• Test NG, Junit, RestAssured

Service• Java

HTTP client• Apache, Retrofit

TEST FRAMEWORK

Test

ServiceLayer

HTTP client

30

TEST

31

SERVISE

32

HTTP CLIENT

33

TEST

34

THANKYOU

35

CONTACT ME

Andrei_Stasevich@epam.com

Andrei.Stasevich@gmail.com

https://www.linkedin.com/in/andrei-stasevich/

Recommended