Getting Started with the Automation API: Part 1 - Overview

 3r33434. 3r3-31. 3r33414.
Translation Article 3r3416. Shashi Kumar Raja
3r33417. 3r33412.  3r33434. 3r33414. So, let's say you want to do automation of the API, but every time you type
in the search bar in Google. best api automation tool
, you see so many references to dozens of top tools that you get confused and decide that you will definitely do this
tomorrow. 3r33417. 3r33412.  3r33434. 3r33414. Getting Started with the Automation API: Part 1 - Overview 3r31616. 3r33412.  3r33434. 3r33414. Let's start by understanding what we need if we want to customize (hopefully tomorrow) 3r333339. API automation platform
. Hold this thought for a second I said, stop thinking
I know that your boss doesn't give a penny for any paid tools
. Look, I read your thoughts, do not think out loud
3r33412.  3r33434. 3r33414. 3r33412.  3r33434.
3r33354. 1. where the hell should I start writing tests? 3r33357. 3r33412.  3r33434. 3r33360. 3r33412.  3r33434. 3r33414. You will need something that will provide you with sets of rules and guidelines for writing tests, and also allow you to do this by giving you access to several tools and techniques. I hear the bell ringing, no !!! Well, I know what will make the bell ring. 3r33417. 3r33412.  3r33434. 3r33414.
Have you ever heard of 3r3358. TESTNG
, 3r360. JUNIT
, [leech=HTTP://MOCHA.ORG/] MOCHA [/leech] , [leech=HTTPS://DOCS.PYTEST.ORG/EN/LATEST/] PYTEST [/leech] , [leech=HTTP://ROBOTFRAMEWORK.ORG/] ROBOT [/leech] !? Yes, they are all test automation environments. 3r33333. 3r33417. 3r33412.  3r33434. 3r33414. You need to find a suitable testing environment based on your requirements: which existing technology stack does your company use? What automation do you want to do? Which language is more convenient for you, etc. You will find an automation environment in most popular languages ​​that will allow you to write
modular, functional and other
API test types. 3r33417. 3r33412.  3r33434. 3r33414. To learn more about the test environment, refer to the 2nd part of the series, where I introduced 3r3793 in detail. Mocha
and Pytest . 3r33417. 3r33412.  3r33434.
3r33354. 2. How am I going to make API calls in a test environment? 3r33357. 3r33412.  3r33434. 3r33360. 3r33412.  3r33434. 3r33414. Most of these platforms support API calls, including the 333339 query library. HTTP request library
Because the REST API uses the HTTP protocol for communication. 3r33417. 3r33412.  3r33434. 3r33414. Some frameworks such as mocha , give you the freedom to use a library of HTTP requests of your choice, for example 3r3103. superagent
. 3r33417. 3r33412.  3r33434.
request
.post ('/api /pet')
.send ({name: 'Manny', species: 'cat'}) //sends a JSON post body
.set ('X-api-key', 'foobar')
.set ('accept', 'json')
.end ((err, res) => {3r3343429. //Calling the end function will send the request
}); 3r33434.

3r33412.  3r33434. 3r33414. They give you easy support for GET, PUT, POST, DELETE and all other methods. You can transfer headers, cache, request parameters, you called it - you got it 3r3417. 3r33412.  3r33434.
3r33354. 3. Cool, but some of my APIs give JSON, and others give XML in response, how can I deal with this? 3r33357. 3r33412.  3r33434. 3r33360. 3r33412.  3r33434. 3r33414. Most of these HTTP request libraries will allow you to send and receive data in the format
JSON, XML, CSV, Text, Image, form-data, encoded-data
with several supported authorization standards. 3r33417. 3r33412.  3r33434. 3r33414. They also allow you to process the HTTP response status code and check whether we received the required response status code or not. 3r33417. 3r33412.  3r33434.
 3r33434. 3r3402. Informational Response Codes (1xx)
 3r33434. 100 - Continue
 3r33434. 101 - Switching Protocols
 3r33434. 102 - Processing 3r3405.  3r33434. 3r3407. 3r33412.  3r33434.
 3r33434. 3r3402. Success Response Codes (2xx)
 3r33434. 200 - OK 206 - Partial Content
 3r33434. 201 - Created 207 - Multi-status
 3r33434. 202 - Accepted 208 - Already Reported
 3r33434. 203 - Non-authoritative Info 226 - IM Used 3r33412.  3r33434. 204 - No Content 250 - Low Storage Space 3r33434.  3r33434. 205 - Reset Content
 3r33434. 3r3407. 3r33412.  3r33434.
 3r33434. 3r3402. Redirection Response Codes (3xx)
 3r33434. 300 - Multiple Choices 304 - Not Modified 3r33412.  3r33434. 301 - Moved Permanently 305 - Use Proxy
 3r33434. 302 - Found 307 - Temporary Redirect 3r33412.  3r33434. 303 - See Other 308 - Permanent Redirect
 3r33434. 3r3407. 3r33412.  3r33434.
 3r33434. 3r3402. Client Error Response Codes (4xx)
 3r33434. 400 - Multiple Choices 410 - Not Modified 3r3412.  3r33434. 401 - Moved Permanently 411 - Use Proxy
 3r33434. 402 - Found 412 - Temporary Redirect 3r33412.  3r33434. 403 - See Other 413 - Permanent Redirect
 3r33434. 404 - Multiple Choices 414 - Not Modified 3r3412.  3r33434. 405 - Moved Permanently 415 - Use Proxy
 3r33434. 406 - Found 416 - Temporary Redirect 3r33434.  3r33434. 407 - See Other 417 - Permanent Redirect
 3r33434. 408 - Found 418 - Temporary Redirect 3r33412.  3r33434. 409 - See Other
 3r33434. 3r3407. 3r33412.  3r33434.
 3r33434. 3r3402. Server Error Response Codes (5xx)
 3r33434. 500 - Internal Server Error 508 - Loop Detected 3r31234.  3r33434. 501 - Not Implemented 509 - Bandwidth Limited
 3r33434. 502 - Bad Gateway 510 - Not Extended 3r33412.  3r33434. 503 - Service Unavailable 511 - Network Auth Requried
 3r33434. 504 - Gateway Timeout 550 - Permission Denied
 3r33434. 505 - HTTP Ver Not Supported 551 - Option Not Supported
 3r33434. 506 - Variant Also Negotiates 598 - Nework Read Timeout Error
 3r33434. 507 - Insufficient Storage 599 - Network Connect Timeout Error
 3r33434. 3r3407. 3r33412.  3r33434.
3r33354. 4. Good, but how will I process the test data? 3r33357. 3r33412.  3r33434. 3r33360. 3r33412.  3r33434. 3r33414. It depends on where you get the test data. These test frameworks allow you to use all the features of the language in which they are based -
3r33412.  3r33434. 3r33414. a.
Database:
You can easily create database connections to read data. 3r33417. 3r33412.  3r33434. 3r33414. b.
External file:
You can read external text, JSON, CSV or any other files. 3r33417. 3r33412.  3r33434. 3r33414. c.
Random dаta:
You can use libraries like faker , for generating random test data on the fly. 3r33417. 3r33412.  3r33434.
var faker = require ('faker'); 3r33434. 3r33434. var randomName = faker.name.findName (); //Rowan Nikolaus
var randomEmail = faker.internet.email (); //[email protected]
var randomCard = faker.helpers.createCard (); //random contact card containing many properties
3r33414. d. Data from the API response: Many times during testing you will need to send the response of one API as request data to another. You can do this using hooks .You will get features like Before, Before each, After, After each , which, as the name implies, is performed before /after any or all tests. Call API1 before API? and pass its response to API2. Just to the right !!! ️ 3r33417. 3r33412.  3r33434.
3r33354. 5. Processing the test data and executing the API calls seems simple, but how am I going to check the API responses? 3r33357. 3r33412.  3r33434. 3r33360. 3r33412.  3r33434. 3r33414. To check the answers you need a library called 3r33339. Assertion library . Many test environments come bundled with assertion libraries, which gives you the opportunity to write asserts in plain English, such as syntax. They also allow you to check 3r3308. JSON schema your answer. 3r33417. 3r33412.  3r33434. 3r33414. In mocha, you can use any library of statements, for example, chai 3r31616. . 3r33417. 3r33412.  3r33434.
    response.status.should.equal (200)
foo.should.be.a ('string'); 3r33434. foo.should.have.lengthOf (3); 3r33434. tea.should.have.property ('flavors')
.with.lengthOf (3); 3r33434.

3r33354. 6. Fabulous !!! There was a trifle, after all this testing, to somehow show my boss what I did and where I found problems? 3r33357. 3r33412.  3r33434. 3r33360. 3r33412.  3r33434. 3r33414. Most of these frameworks will provide you with 3r333339. basic HTML report
about the test run, which you can download and share. If you need more beautiful reports with graphs and charts, you can use several open source reporting tools, such as 3r33341. allure
or mochawesome . 3r33417. 3r33412.  3r33434. 3r33414. 3r33354.
7. Only if I could get some kind of template with these things to start automating the API now
3r33357. 3r33412.  3r33434. 3r33360. 3r33412.  3r33434. 3r33414.
What I told you, you called it, you got 3r33333. 3r33417. 3r33412.  3r33434. 3r33414. This is the template that I created for automate the API using mocha in node.js . 3r33417. 3r33412.  3r33434. 3r33414. It includes
3r33412.  3r33434.
 3r33434. 3r3402. Test-framework (mocha),
 3r33434. 3r3402. HTTP request library (supertest), 3r3405.  3r33434. 3r3402. Assertion library (chai),
 3r33434. 3r3402. Reporter (allure), 3r3405.  3r33434. 3r3402. logger (winston), 3r3405.  3r33434. 3r3402. Random data generator (faker), 3r3405.  3r33434. 3r3402. Eslint support and
 3r33434. 3r3402. 3r3403. naughty string validation integrated
. All you need to do is clone /download it and you are ready to go. 3r3405.  3r33434. 3r3407. 3r33412.  3r33434. 3r33414. If you need a template in another language, I can prepare it for tomorrow. 3r33417. 3r33412.  3r33434. 3r33414. If you liked this article you can clap your hands , it might encourage me to write more
3r33434. 3r33434. 3r33434. 3r33434. 3r33434. ! function (e) {function t (t, n) {if (! (n in e)) {for (var r, a = e.document, i = a.scripts, o = i.length; o-- ;) if (-1! == i[o].src.indexOf (t)) {r = i[o]; break} if (! r) {r = a.createElement ("script"), r.type = "text /jаvascript", r.async =! ? r.defer =! ? r.src = t, r.charset = "UTF-8"; var d = function () {var e = a.getElementsByTagName ("script")[0]; e.parentNode.insertBefore (r, e)}; "[object Opera]" == e.opera? a.addEventListener? a.addEventListener ("DOMContentLoaded", d,! 1): e.attachEvent ("onload", d ): d ()}}} t ("//mediator.mail.ru/script/2820404/"""_mediator") () (); 3r33434. 3r33434. 3r33434. 3r33434. 3r33434. 3r33434. 3r33434.
+ 0 -

Add comment