What is API testing and how to do it?

What is API testing and how to do it?

What is API testing and how to do it? The concept of API’s pre-dates even the advent of personal computing and Web, it’s been around since the 1960s. Without APIs, the digital experiences that we experience every day wouldn’t be possible. API’s...

What is API testing and how to do it?
The concept of API’s pre-dates even the advent of personal computing and Web, it’s been around since the 1960s. Without APIs, the digital experiences that we experience every day wouldn’t be possible. API’s are responsible for everything from driving information-rich marketing campaigns to checking the weather on a mobile app. These API’s are tested before they are put to use and we call the process ‘API Testing’. In this article, we will explore ‘What is API Testing?’ in detail. If you are new to software testing, be sure to also read the Beginners’ Guide for Software Testing.

Let’s take a look at topics covered in this article:
What is an API?
What is API Testing?
Why should we do API Testing?
How to Perform API Testing?
Types of API Testing
List of Popular API Testing Tools
Challenges of API Testing
What is an API?
API is the acronym for Application Programming Interface, which is a software intermediary that allows two applications to talk to each other.
Suppose you’re looking for a bedroom through an internet travel booking website. mistreatment the site’s on-line type, you may fill the mandatory info just like the town you wish to remain in, arrival and check-out dates, variety of guests, and variety of rooms. Then you click “search.”. however what’s occurring between coming into your info to receiving your edifice choices? Apis, that’s what! the location aggregates info from many various hotels. once you click “search,” the location then interacts with every hotel’s API, that delivers results for obtainable rooms that meet your criteria. and every one this happens in seconds attributable to associate API, that acts sort of a courier that runs back and forth between applications, databases, and devices.
But, if associate API doesn’t work expeditiously and effectively, it’ll ne’er be adopted, regardless if it’s free or not. To avoid that, API’s area unit tested before they’re place to use.
What is API Testing?
API testing could be a form of code testing wherever application programming interfaces (APIs) area unit tested to work out if they meet expectations for practicality, reasonableness, performance, and security.

In straightforward terms, API testing is meant to reveal bugs, inconsistencies or deviations from the expected behavior of associate API. Commonly, applications have 3 separate layers:
• Presentation Layer or interface
• Business Layer or application interface for business logic process
• Database Layer for modeling and manipulating knowledge
API testing is performed at the foremost vital layer of code design, the Business Layer. it’s within the business layer, business logic process is applied, and every one transactions between User Interface(UI) and info happen. So, ensuring that, API offers complete supposed practicality permits for simple future growth of the wares. a lot of reasons on why API testing is vital area unit mentioned next during this ‘What is API Testing?’ article.
Why ought to we tend to do API Testing?
API testing is a very important activity that testing groups ought to specialise in. It offers variety of benefits over different kinds of testing

Get more info at Selenium online training and selenium Certification coaching
Language Independent: knowledge is changed via XML and JSON, thus any language may be used for automation, freelance from the languages wont to develop the appliance.
GUI Independent: API testing may be done to see the core practicality of the appliance to reveal little errors and to judge a build’s strength. Also, we will take a look at the Apis while not a interface.
Improved take a look at Coverage: Most API’s have options, that permit a take a look ater to make machine-controlled testswith high test coverage as well as positive and negative cases. we will seldom notice take a look at cases that can’t be machine-controlled.

• ctor-led Sessions
• Real-life Case Studies
• Assignments
• Lifetime Access
Explore info
Reduce Testing Cost: With API testing we will notice minor bugs before the interface testing. Usually, these minor bugs can become larger throughout interface testing. thus finding those bugs whereas activity API testing are going to be value effective.
Enables quicker Releases: The take a look at cases that take regarding 8–10 hrs once corporal punishment UI regression testing take solely regarding 1–2 hrs with API testing. this permits firms to unharness builds quicker with API testing.
So, API testing could be a extremely vital section of the testing method.
however however is API testing carried out? Is there a particular procedure?
How to Perform API Testing?
Listed below square measure the steps that you simply will follow to perform API testing:

API Specification Review
The first step is documenting the API testing needs. what’s the aim of the API? what’s the work flow of the application? that integrations square measure supported by the API? What square measure the options of the API? Documenting of these API testing needs is that the very first thing you would like to try and do. this can assist you in designing API tests throughout the testing method.
Setting Up check setting
Next step is putting in a testing setting, with the specified set of parameters round the API. This involves configuring the info and server for the appliance needs.
Integrating Application knowledge
In this step, you would like to mix your application knowledge with the API tests to make sure that the API functions evidently against all potential input configurations.
Deciding sort of API check
After you’ve created the testing boundaries and needs, you would like to choose what you would like to check your API for. There square measure differing types of API tests like practicality testing, validation testing, load testing, security testing, end-to-end testing, fuzz testing and lots of additional. additional concerning API testing varieties within the next session of this text.
Software Testing coaching
Text Execution & news
Once you have got selected what to check the API for, consequent step clearly is to make check cases around that needs and execute them. A basic guideline is to spot the foremost common parameters associate degreed conditions that an finish developer can use once vocation the Apis and check these situations extensively. so document the check results for any use.
Well, you’ll follow the higher than steps to with success check Apis. one in every of the vital steps whereas activity API checks is to choose what quite test you would like to perform. For that, you must bear in mind of the kinds of API testing. Let’s check them out next during this ‘What is API Testing’ article.
Types of API Testing
In API testing, the subsequent styles of testing is conducted:
• Functionality Testing — to examine if the API works and will specifically what it’s alleged to do
• Reliability Testing — to examine if API is systematically connected to and result in consistent results
• Validation Testing — Helps verify the aspects of product, behavior, associate degreed potency of an API
• Load Testing — Is performed to make sure the performance of API underneath each traditional and at peak conditions
• UI Testing — It involves testing the programme for the API and different integral elements
• Security Testing — to check that the API is secure against all potential external threats
• Penetration Testing — To observe vulnerabilities of associate degree application from associate degree attackers perspective
• Fuzz Testing — to check the API in terms of the boundaries to arrange for the “worst case scenarios”
Well, these square measure the foremost oft performed API check varieties. By activity these tests what square measure you attempting to check for? what’s going to you find?
You are checking for:
• Duplicate or missing practicality
• Improper electronic communication
• Error handling mechanism is incompatible
• Multi-threaded problems
• Security, performance & security problems
• Reliability problems
Since API Testing is gaining quality, we’ve got several tools accessible for an equivalent. This ‘What is API Testing?’ article lists some common API testing tools for your reference.
API Testing Tools
For with success activity API testing, you may would like a tool to structure and manage your check cases. Here square measure a number of the highest API testing tools that may be used for Rest API and Soap API:
SoapUI: it’s the foremost wide common ASCII text file tool for API testing. With SopaUI you’ll perform useful testing, performance testing, security testing, and data-driven testing. it’ll give you with the reports for testing and can permit you to export the info.
Postman: With over four million users worldwide it’s one in every of the foremost common API testing tools. It runs on mack, Windows, UNIX system & Chrome Apps. permits you to line up all the headers and cookies your API expects, so check the response.
Katalon Studio: it’s a strong and comprehensive automation tool for API, Web, and mobile testing. Provides straightforward preparation by as well as all frameworks, ALM integrations, and plugins in one package. Also, supports each SOAP and REST requests,also supports numerous styles of commands and parameterization functionalities.
Tricentis Tosca: it’s a model based mostly check API automation testing tool from Tricentis however conjointly supports API testing. It supports a large array of protocols as well as HTTP(s) JMS, SOAP, REST, IBM MQ, NET TCP, etc.
REST-assured: it’s associate degree ASCII text file Java Domain-specific language (DSL) tool that creates testing REST service straightforward. Supports XML and JSON requests. This tool simplifies things by eliminating the necessity to use boiler-plate code to check and validate complicated responses.
Apart from these common tools, there are tools like Apache JMeter, HttpMaster, Parasoft, HP QTP, Karate DSL, and lots of others. although these tools create API testing straightforward, you would possibly still bump into some challenges whereas activity API testing.
Challenges of API Testing
• There isn’t any GUI, which is able to create it troublesome for testers to administer input values
• Test case management is troublesome since a checker may need to affect countless test cases
• The tester should possess experience within the programming language(s) that square measure targeted by the API
• Time-consuming, needs tons of your time and resources to develop tools and style tests
• Improper documentation can create it troublesome for a check designer to know the aim of API calls
• Proper decision sequencing is needed as this might result in inadequate coverage in testing
• Exception handling functions ought to be tested completely
If you found this “What is API Testing?” article relevant, check out the live-online Selenium online training Hyderabad by onlineitgru, a trusted online learning company with a network of more than 250,000 satisfied learners spread across the globe.
Got a question for us? Please mention it in the comments section of this ‘What is API Testing?” article and we will get back to you.

Selenium WebDriver With Python 3.x - Novice To Ninja

Selenium WebDriver With Python 3.x - Novice To Ninja

Selenium WebDriver With Python 3.x - Novice To Ninja

Description
Best Selenium WebDriver With Python Programming Language Course - Complete Framework Implementation From Scratch

This course includes a wide range of topics from Selenium WebDriver Basics and Advanced, Python Programming Concepts, Unittest And Pytest Framework, Automation Framework Design (Page Objects, Data Driven, Reading CSV Files), Logging Infrastructure, Cross-Browser Testing, Interview Preparation. All materials including code files.

You achieve two targets with one single course

Complete Python Programming Language
Selenium WebDriver Automation
Why Python Programming Language?

Python Programming Language is the fastest growing programming language within both the fields, development and testing. QA industry is rapidly progressing to move on with Python Programming Language for all the automation needs because of the flexibility it offers.

One stop place to become an Expert in Web Automation Framework related technologies from scratch

We start from Beginners level and go through Advance level. This is a single course for everything you need to know related to Web UI Automation.

To read more:

How to build a JSON API with Python

How to build a JSON API with Python

The JSON API specification is a powerful way for enabling communication between client and server. It specifies the structure of the requests and responses sent between the two, using the JSON format. The [JSON API...

The JSON API specification is a powerful way for enabling communication between client and server. It specifies the structure of the requests and responses sent between the two, using the JSON format.

The JSON API specification is a powerful way for enabling communication between client and server. It specifies the structure of the requests and responses sent between the two, using the JSON format.

As a data format, JSON has the advantages of being lightweight and readable. This makes it very easy to work with quickly and productively. The specification is designed to minimise the number of requests and the amount of data that needs sending between client and server.

Here, you can learn how to create a basic JSON API using Python and Flask. Then, the rest of the article will show you how to try out some of the features the JSON API specification has to offer.

Flask is a Python library that provides a 'micro-framework' for web development. It is great for rapid development as it comes with a simple-yet-extensible core functionality.

A really basic example of how to send a JSON-like response using Flask is shown below:

from flask import Flask

app = Flask(__name__)

@app.route('/')
def example():
   return '{"name":"Bob"}'

if __name__ == '__main__':
    app.run()

This article will use two add-ons for Flask:

The big picture

The end goal is to create an API that allows client-side interaction with an underlying database. There will be a couple of layers between the database and the client - a data abstraction layer and a resource manager layer.

Here's an overview of the steps involved:

  1. Define a database using Flask-SQLAlchemy
  2. Create a data abstraction with Marshmallow-JSONAPI
  3. Create resource managers with Flask-REST-JSONAPI
  4. Create URL endpoints and start the server with Flask

This example will use a simple schema describing modern artists and their relationships to different artworks.

Install everything

Before getting started, you'll need to set up the project. This involves creating a workspace and virtual environment, installing the modules required, and creating the main Python and database files for the project.

From the command line create a new directory and navigate inside.

$ mkdir flask-jsonapi-demo
$ cd flask-jsonapi-demo/

It is good practice to create virtual environments for each of your Python projects. You can skip this step, but it is strongly recommended.

$ python -m venv .venv
$ source .venv/bin/activate

Once your virtual environment has been created and activated, you can install the modules needed for this project.

$ pip install flask-rest-jsonapi flask-sqlalchemy

Everything you'll need will be installed as the requirements for these two extensions. This includes Flask itself, and SQLAlchemy.

The next step is to create a Python file and database for the project.

$ touch application.py artists.db

Create the database schema

Here, you will start modifying application.py to define and create the database schema for the project.

Open application.py in your preferred text editor. Begin by importing some modules. For clarity, modules will be imported as you go.

Next, create an object called app as an instance of the Flask class.

After that, use SQLAlchemy to connect to the database file you created. The final step is to define and create a table called artists.

from flask import Flask
from flask_sqlalchemy import SQLAlchemy

# Create a new Flask application
app = Flask(__name__)

# Set up SQLAlchemy
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////artists.db'
db = SQLAlchemy(app)

# Define a class for the Artist table
class Artist(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String)
    birth_year = db.Column(db.Integer)
    genre = db.Column(db.String)

# Create the table
db.create_all()

Creating an abstraction layer

The next step uses the Marshmallow-JSONAPI module to create a logical data abstraction over the tables just defined.

The reason to create this abstraction layer is simple. It gives you more control over how your underlying data is exposed via the API. Think of this layer as a lens through which the API client can view the underlying data clearly, and only the bits they need to see.

In the code below, the data abstraction layer is defined as a class which inherits from Marshmallow-JSONAPI's Schema class. It will provide access via the API to both single records and multiple records from the artists table.

Inside this block, the Meta class defines some metadata. Specifically, the name of the URL endpoint for interacting with single records will be artist_one, where each artist will be identified by a URL parameter <id>. The name of the endpoint for interacting with many records will be artist_many.

The remaining attributes defined relate to the columns in the artists table. Here, you can control further how each is exposed via the API.

For example, when making POST requests to add new artists to the database, you can make sure the name field is mandatory by setting required=True.

And if for any reason you didn't want the birth_year field to be returned when making GET requests, you can specify so by setting load_only=True.

from marshmallow_jsonapi.flask import Schema
from marshmallow_jsonapi import fields

# Create data abstraction layer
class ArtistSchema(Schema):
    class Meta:
        type_ = 'artist'
        self_view = 'artist_one'
        self_view_kwargs = {'id': '<id>'}
        self_view_many = 'artist_many'

    id = fields.Integer()
    name = fields.Str(required=True)
    birth_year = fields.Integer(load_only=True)
    genre = fields.Str()

Create resource managers and URL endpoints

The final piece of the puzzle is to create a resource manager and corresponding endpoint for each of the routes /artists and /artists/id.

Each resource manager is defined as a class that inherits from the Flask-REST-JSONAPI classes ResourceList and ResourceDetail.

Here they take two attributes. schema is used to indicate the data abstraction layer the resource manager uses, and data_layer indicates the session and data model that will be used for the data layer.

Next, define api as an instance of Flask-REST-JSONAPI's Api class, and create the routes for the API with api.route(). This method takes three arguments - the data abstraction layer class, the endpoint name, and the URL path.

The last step is to write a main loop to launch the app in debug mode when the script is run directly. Debug mode is great for development, but it is not suitable for running in production.

# Create resource managers and endpoints

from flask_rest_jsonapi import Api, ResourceDetail, ResourceList

class ArtistMany(ResourceList):
    schema = ArtistSchema
    data_layer = {'session': db.session,
                  'model': Artist}

class ArtistOne(ResourceDetail):
    schema = ArtistSchema
    data_layer = {'session': db.session,
                  'model': Artist}

api = Api(app)
api.route(ArtistMany, 'artist_many', '/artists')
api.route(ArtistOne, 'artist_one', '/artists/<int:id>')

# main loop to run app in debug mode
if __name__ == '__main__':
    app.run(debug=True)

Make GET and POST requests

Now you can start using the API to make HTTP requests. This could be from a web browser, or from a command line tool like curl, or from within another program (e.g., a Python script using the Requests library).

To launch the server, run the application.py script with:

$ python application.py

In your browser, navigate to http://localhost:5000/artists.  You will see a JSON output of all the records in the database so far. Except, there are none.

To start adding records to the database, you can make a POST request. One way of doing this is from the command line using curl. Alternatively, you could use a tool like Insomnia, or perhaps code up a simple HTML user interface that posts data using a form.

With curl, from the command line:

curl -i -X POST -H 'Content-Type: application/json' -d '{"data":{"type":"artist", "attributes":{"name":"Salvador Dali", "birth_year":1904, "genre":"Surrealism"}}}' http://localhost:5000/artists

Now if you navigate to http://localhost:5000/artists, you will see the record you just added. If you were to add more records, they would all show here as well, as this URL path calls the artists_many endpoint.

To view just a single artist by their id number, you can navigate to the relevant URL. For example, to see the first artist, try http://localhost:5000/artists/1.

Filtering and sorting

One of the neat features of the JSON API specification is the ability to return the response in more useful ways by defining some parameters in the URL. For instance, you can sort the results according to a chosen field, or filter based on some criteria.

Flask-REST-JSONAPI comes with this built in.

To sort artists in order of birth year, just navigate to http://localhost:5000/artists?sort=birth_year. In a web application, this would save you from needing to sort results on the client side, which could be costly in terms of performance and therefore impact the user experience.

Filtering is also easy. You append to the URL the criteria you wish to filter on, contained in square brackets. There are three pieces of information to include:

  • "name" - the field you are filtering by (e.g., birth_year)
  • "op" - the filter operation ("equal to", "greater than", "less than" etc.)
  • "val" - the value to filter against (e.g., 1900)

For example, the URL below retrieves artists whose birth year is greater than 1900:

http://localhost:5000/artists?filter=[{"name":"birth_year","op":"gt","val":1900}]

This functionality makes it much easier to retrieve only relevant information when calling the API. This is valuable for improving performance, especially when retrieving potentially large volumes of data over a slow connection.

Pagination

Another feature of the JSON API specification that aids performance is pagination. This is when large responses are sent over several "pages", rather than all in one go. You can control the page size and the number of the page you request in the URL.

So, for example, you could receive 100 results over 10 pages instead of loading all 100 in one go. The first page would contain results 1-10, the second page would contain results 11-20, and so on.

To specify the number of results you want to receive per page, you can add the parameter ?page[size]=X to the URL, where X is the number of results. Flask-REST-JSONAPI uses 30 as the default page size.

To request a given page number, you can add the parameter ?page[number]=X, where is the page number. You can combine both parameters as shown below:

http://localhost:5000/artists?page[size]=2&page[number]=2

This URL sets the page size to two results per page, and asks for the second page of results. This would return the third and fourth results from the overall response.

Relationships

Almost always, data in one table will be related to data stored in another. For instance, if you have a table of artists, chances are you might also want a table of artworks. Each artwork is related to the artist who created it.

The JSON API specification allows you to work with relational data easily, and the Flask-REST-JSONAPI lets you take advantage of this. Here, this will be demonstrated by adding an artworks table to the database, and including relationships between artist and artwork.

To implement the artworks example, it will be necessary to make a few changes to the code in application.py.

First, make a couple of extra imports, then create a new table which relates each artwork to an artist:

from marshmallow_jsonapi.flask import Relationship
from flask_rest_jsonapi import ResourceRelationship

# Define the Artwork table
class Artwork(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String)
    artist_id = db.Column(db.Integer, 
        db.ForeignKey('artist.id'))
    artist = db.relationship('Artist',
        backref=db.backref('artworks'))

Next, rewrite the abstraction layer:

# Create data abstraction 
class ArtistSchema(Schema):
    class Meta:
        type_ = 'artist'
        self_view = 'artist_one'
        self_view_kwargs = {'id': '<id>'}
        self_view_many = 'artist_many'

    id = fields.Integer()
    name = fields.Str(required=True)
    birth_year = fields.Integer(load_only=True)
    genre = fields.Str()
    artworks = Relationship(self_view = 'artist_artworks',
        self_view_kwargs = {'id': '<id>'},
        related_view = 'artwork_many',
        many = True,
        schema = 'ArtworkSchema',
        type_ = 'artwork')

class ArtworkSchema(Schema):
    class Meta:
        type_ = 'artwork'
        self_view = 'artwork_one'
        self_view_kwargs = {'id': '<id>'}
        self_view_many = 'artwork_many'

    id = fields.Integer()
    title = fields.Str(required=True)
    artist_id = fields.Integer(required=True)

This defines an abstraction layer for the artwork table, and adds a relationship between artist and artwork to the ArtistSchema class.

Next, define new resource managers for accessing artworks many at once and one at a time, and also for accessing the relationships between artist and artwork.

class ArtworkMany(ResourceList):
    schema = ArtworkSchema
    data_layer = {'session': db.session,
                  'model': Artwork}

class ArtworkOne(ResourceDetail):
    schema = ArtworkSchema
    data_layer = {'session': db.session,
                  'model': Artwork}

class ArtistArtwork(ResourceRelationship):
    schema = ArtistSchema
    data_layer = {'session': db.session,
                  'model': Artist}

Finally, add some new endpoints:

api.route(ArtworkOne, 'artwork_one', '/artworks/<int:id>')
api.route(ArtworkMany, 'artwork_many', '/artworks')
api.route(ArtistArtwork, 'artist_artworks',
    '/artists/<int:id>/relationships/artworks')

Run application.py and trying posting some data from the command line via curl:

curl -i -X POST -H 'Content-Type: application/json' -d '{"data":{"type":"artwork", "attributes":{"title":"The Persistance of Memory", "artist_id":1}}}' http://localhost:5000/artworks

This will create an artwork related to the artist with id=1.

In the browser, navigate to http://localhost:5000/artists/1/relationships/artworks. This should show the artworks related to the artist with id=1. This saves you from writing a more complex URL with parameters to filter artworks by their artist_id field. You can quickly list all the relationships between a given artist and their artworks.

Another feature is the ability to include related results in the response to calling the artists_one endpoint:

http://localhost:5000/artists/1?include=artworks

This will return the usual response for the artists endpoint, and also results for each of that artist's artworks.

Sparse Fields

One last feature worth mentioning - sparse fields. When working with large data resources with many complex relationships, the response sizes can blow up real fast. It is helpful to only retrieve the fields you are interested in.

The JSON API specification lets you do this by adding a fields parameter to the URL. For example URL below gets the response for a given artist and their related artworks. However, instead of returning all the fields for the given artwork, it returns only the title.

http://localhost:5000/artists/1?include=artworks&fields[artwork]=title

This is again very helpful for improving performance, especially over slow connections. As a general rule, you should only make requests to and from the server with the minimal amount of data required.

Final remarks

The JSON API specification is a very useful framework for sending data between server and client in a clean, flexible format. This article has provided an overview of what you can do with it, with a worked example in Python using the Flask-REST-JSONAPI library.

So what will you do next? There are many possibilities. The example in this article has been a simple proof-of-concept, with just two tables and a single relationship between them. You can develop an application as sophisticated as you like, and create a powerful API to interact with it using all the tools provided here.

Thanks for reading, and keep coding in Python!

Selenium Webdriver Automation with Python Programming for Beginners

Selenium Webdriver Automation with Python Programming for Beginners

Selenium Webdriver Automation with Python Programming for Beginners. Implement of Python Selenium Frameworks from scratch. Learn Selenium Webdriver Automation with Python from scratch. Selenium with Python Full Course For Beginners. Learn Pytest tutorial for Beginners

Selenium Webdriver Automation with Python Programming for Beginners. Implement of Python Selenium Frameworks from scratch. Learn Selenium Webdriver Automation with Python from scratch. Selenium with Python Full Course For Beginners. Learn Pytest tutorial for Beginners