API Testing And Automation

API Testing Tools and Automation 101: The Essential Guide

API stands for Application Programming Interface. Typically API is used to facilitate the interaction between two different applications by using any means of communication. When APIs are used over web networks, we term them as ‘Web Services’. In recent times APIs have become the backbone of programming. As in an application, writing APIs to communicate with database, or with another module has become a common practice now and that is why as a tester we must test the APIs to for maximum test coverage.

As a part of integration testing, API automation can help to accelerate the testing and increase efficiency. As most of the companies are using RESTful microservices/APIs at business layer, API testing has become critical component of test plan for any release.

In simplest terms, API is a service which helps two different applications to communicate with each other. Mostly APIs are used to abstract the business logic and direct database access to any application.

Logically we can segregate the entire system into three layers-

  1. Presentation Layer – This is user interface(GUI) which is open to end users. QA performs functional testing at this layer.
  2. Business Layer- This is Application user interface where the logic is written. In technical terms this is where code/algorithm resides. APIs come into picture at this layer.
  3. DataBase Layer- Where application data is present.
 

In other words the API is the brain of our connected world. It is the set of tools, protocols, standards and code that glues our digital world together. Because of their dynamic nature and capabilities they provide, APIs allow companies to become more agile, things to go mobile, and everything to work together in a streamlined, integrated way.Therefore, API testing is testing APIs at service level and the at the integration level.

Testing Strategy for APIs-

While testing APIs, tester should concentrate on using software to make API calls in order to receive an output before observing and logging the system’s response. Most importantly, tests that the API returns a correct response or output under varying conditions. This output is typically one of these three:

  • A Pass or Fail status
  • Data or information
  • A call to another API

However there also could be no output at all or something completely unpredicted occurs. This makes the tester’s role crucial to the application development process.And because APIs are the central hub of data for many applications, data-driven testing for APIs can help increase test coverage and accuracy.

In testing the API directly, specifying pass/fail scenarios is slightly more challenging. However in comparing the API data in the response or in comparing the behavior after the API call in another API would help you setup definitive validation scenarios.

API testing is one of the most challenging parts of the whole chain of software testing and QA testing because it works to assure that our digital lives run in an increasingly seamless and efficient manner. While developers tend to test only the functionalities they are working on, testers are in charge of testing both individual functionalities and a series or chain of functionalities, discovering how they work together from end to end.

Types of API Testing-

First identify what type of tests you need to perform on API. Like testers do different type of testing for features of their product, same goes with APIs. Commonly testing of APIs include-

Unit Testing– To test the functionality of individual operation. For eg- Google provides geocoding API,  to get the longitude and latitude of any location. This usually takes address as input and returns lat longs. Now for unit testing of this API, tester may pass different location and verify result.

Functional Testing- This type of testing mainly focuses on functionality of API. This would include test cases to verify HTTP response codes, validation of response, error codes in case API return any error etc.

Load Testing- This type of test is necessary in cases where API is dealing with huge data and chances of application to be used by no.of users at the same time. This increases the API hits at the same time and it may crash and not able to take that load.

Security Testing- Security testing is particularly critical as API are used to create a link between two different applications. The core purpose of using an API is to abstract or hide the application’s database from other. This may include the testcases like authorization checks, session management etc.

Interoperability Testing- This is to test that API is accessible to the applications where it should be. This applies to SOAP APIs.

WS compliance Testing- API is tested to ensure standards such as WS-Addressing, WS-Discovery, WS-Federation, WS-Policy, WS-Security, and WS-Trust are properly implemented and utilized

Penetration Testing- This is to find the vulnerability of API from external sources.

Web services/ API Protocols-

If we talk about web services there are mainly two type of services or we can say  protocols-

REST –  REST stands for REpresentational State Transfer which is new on the block as compared to SOAP which means it must overcome all the problems with SOAP. REST is a lightweight protocol which uses URL for all the needed information. It uses four HTTP methods to perform task-

  1. Get- To get the information. For example getting longitude and latitude in case of location mapping API.
  2. Post- To insert some data in resource.
  3. Put- To update the resource.
  4. Delete- To delete from resource.

REST is more used now a days due to its simple and light-weight architecture.

SOAP API- Stands for Simple Object Access Protocol. It uses XML for message exchanging. All the information which is required to perform this task is given in its WSDL which is Web Service Description Language. SOAP is heavy weight due to its extensive used standards and XML. The main advantages of SOAP over Rest is that it has built in error handling and it can be used with other protocols like SMTP.

Tools for API testing and Automation

There are several tools to test the APIs. When a tester get to test API, they must ask for its document, whether it is a REST or SOAP API or its not-web based API there should always be a document where the details should be written. To approach API testing-

  1. Ask for Doc
  2. Write functional or service level cases first
  3. Write integration tests
  4. When API is stable enough and passes most of the above tests, perform security, performance and load testing.
  • A typical API doc has all the information related to the API like its request format, response, error codes, resource, mandatory parameters, optional parameters, headers etc. The doc can be maintained in various tools like swagger which is open source, Dapperdox, ReDoc etc.
  • After that try to write service level cases for API. For example if an API takes n parameters to get the response in which m are mandatory params and others are optional, then one test case should be to try different combinations of parameters and verify the response. Another testcase might verify the headers and try to run API without passing authentication and verify the error code.
  • Next comes the step of integration test, where you need to test the API and all its dependent APIs or functions. This also includes testing API response, the data it should return to another API or method and what happens if this API fails.
  • Once the API is stable and functional testing is almost done, tester can perform load, security and performance testing.

API Automation

We often need to automate the testcases which are repeatedly executed. For eg- Regression cases. Similarly in case of API testing, there might be some cases which we need to execute before every release and those cases can be automated.

There are many tools for API automation which are quite popular-

  1. SOUP UI
  2. Katalon studio
  3. Postman
  4. Jmeter
  5. RestAssured
  6. CloudQA TruAPI

SOUP UI- It’s very popular tool for API testing.You can do functional, load, security and compliance tests on your API using SoapUI.

Katalon Studio- Built on the top of Selenium and Appium, Katalon Studio is a free and powerful automated testing tool for Web testing, API testing, and Mobile testing.

Postman- Postman is free and helps you be more efficient while working with APIs. It has all the capabilities to develop and test APIs.

Jmeter- Though Jmeter is mostly used for performance and load testing, it can also be used for API functional testing to a good extent.

RestAssured-  Rest-Assured is a Java based library that is used to test RESTful Web Services.The library can be included in the existing framework and call its methods directly for fetching response in json format and then perform required actions.

I am taking an example to explain the steps followed for basic API functional testing, here I am using TruAPI tool provided by CloudQA which is new and gaining popularity-

Step1-To run API request you need to first select the Method Type and paste URL of the API. Press Send button to send the request to API or press Add API Test button to save the request-


 

Try this sample Method Type and API URL

  • Method Type: GET
  • APIURL: https://um5fdww2pj.execute-api.us-east-1.amazonaws.com/dev/todos 


Step2-Information for API request:

  • Most of the API require additional inputs to perform the request such as parameters, Headers, Body(JSON), and so on.
  • To add parameters of the request you can select the respective Parameters tab and press the Add Parameter buttons to add the required information.
Local Image

Step3-Sending an API request with authentication:

  • In case your hosted API needs an authentication, you can go to the Authorization tab and select the BasicAuth from the dropdown list (Default it is set as Noauth) and then input the Username and Password. You are now ready to send authenticated requests.
Local Image
  • Every API response consists of different values like status code, body, headers, and the time to complete the API request. Below image shows how API response received is portrayed.

Adding Assertions:

  • In automation process, it is important that you verify your output using an assertion. To add an assertion in the API Runner, go to the Assertions tab. You can add one or more assertions here.
  • Follow these steps to add assertions:
    • Choose the response type
    • Choose the assertion’s condition
    • Input the value to be checked
  • You are done adding the assertion
Local Image
Local Image

Variables:

  • Variables tab is useful to store the values that are received as a response from an API request sent. To save responses go to the Variables tab and follow these steps:
    • Add Variable
    • Give a name to the variable for better understanding of the team
    • Input the JSON Path of the value to be stored from the response body
    • To use the stored value in the variable as expected assertion you can use __name of the variable__ in any other API request. 
Local Image

View or execute a saved API request:

  • When you are in API Runner page use View Saved Tests button to view the saved tests
  • Select one or more API saved tests and run the selected tests by default the tests shows the last executed run status information
  • Results will show up the API execution history
Local Image

This is a single API execution and automation. For real world scenarios, we often need to create API suit consisting all the regression test cases and run this as a part of regression testing. In agile, it’s crucial to have a suit ready so that it can be integrated with CI and CD.

CloudQA comes with a  very rich documentation about the tool, all the tools provided by CloudQA are aligned with the idea of “Codeless automation” and very easy to use for manual testers.

Link for documentation- https://doc.cloudqa.io/TruAPI.html

LIKE THIS POST SHARE IT WITH YOUR FRIENDS

Share on facebook
Share on google
Share on twitter
Share on linkedin
Share on email

Enterprises use TruAPI testing and monitoring solutions.

Talk to our experts about your API testing needs

Enterprises use TruAPI testing and monitoring solutions.

Talk to our experts about your API testing needs
API Testing, API Testing Automation

Why is it Critical to Check Security during API Testing?

The $13.7 billion acquisition of the Whole Foods Market by Amazon is shaping a dynamic platform that channels diverse services and processes. By leveraging Cloud and APIs, Amazon is offering technologies and process innovations beyond the confines of the organizations. Digital connectivity and new age technology trends is amplifying the significance of Application Program Interfaces (APIs) – intensifying the need for API Testing. A well-programmed API helps build a program smoothly by developing the building blocks for the programmer to weave together.

APIs comprise a set of routines, protocols, and tools for developing software applications. APIs are also used for GUI; some of the popular API examples are Google Maps API, YouTube APIs, Twitter APIs, and Amazon Product Advertising API. These APIs mainly help developers to integrate various functionalities within the websites or applications. For instance, Google Maps API facilitates developers to embed Google Maps on webpages.

API Testing, API Testing Automation

Implications of API spill for businesses

Practically, if you intend to extend any kind of innovative services or facilities to your customers, APIs are indispensable.Whether it is extending an ecommerce platform to your merchants, or offering a range of activities across a single integrated platform; APIs make it feasible. They facilitate easier interface with the target audience by enabling connectivity and supporting developers to work on new products and enhance customer experience.

The financial services industry holds massive amount of customer data. APIs support them to extend new tools to their business partners and employees to streamline operations and data. At an enterprises level, APIs are used within enterprise applications to obtain details about customers/partners.

However, very less thought is given to the security around the API. This could incur risks.

The surface for API attacks is pretty large, where the applications are segmented into micro-services with a large number of interfaces. This can expose the applications to external attacks, leading to leak of sensitive data.The risk is valid for any and every application – financial services, banking, or ecommerce. Exposure of business-critical or customer-sensitive data is a major concern for enterprises and business today.

In this way, Hackers, internal threats, and bad bots can pose a threat to your API security on every single day. In 2013, Snapchat’s API was hacked by an Australian hacker group and published. This exposed the user’s phone numbers, display names, usernames, and private accounts. The API exposure and publication could even get handy for someone to create the Snapchat clone and gather information of millions of users.

Why is API Security Testing so critical?

APIs can drastically reduce the time required for developing new applications and the developed applications will perform in a consistent manner. Hence, testing APIs helps skip maintaining the API code, which reduces costs.

In an application, when compared with other components, API is the weakest link for a hacker to dig in for data breach. API Security Testing ensures that the API is safe from vulnerabilities. In case of an individual application it might just affect the application, however, if an API is hacked, it can affect every application dependent on that API. API hack of an application can create havoc at an organizational level and lead to major losses for your organization.

Thus, ensuring the security of these applications is critical and functional tests would not suffice. Various scenarios need to be simulated to weigh the attacks across diverse scenarios. This will help diminish the impact of external forces on the API. It is a tricky situation and the tester needs to think out-of-the-box situations and simulate them to test the APIs. It is equally important to understand the kind of security problems to address while testing the security aspect.

Moreover, the key advantage of API testing is ability to access the application without a user interface. It helps expose the minute errors that can lead to issues during GUI Testing. When the core is accessed, it helps testing alongside development, encouraging communication, and ensuring better collaboration.

What are the Best Practices for API Security Testing?

With the dominance of Digital Technologies and the threats associated with it, there is no chance that you can ignore your APIs. However, most of the times while building an application security takes a back-seat. API Security Testing should take a much stronger and strategic approach.

So, how should organizations go about testing API vulnerabilities?

Following are some best practices that can be considered while testing vulnerabilities.

  • Firstly, it is essential to check the expected output. The input to the API should be checked and anything outside the range should be declined. This will keep a check on the directions received by the API, which is the fundamental premise for testing and building a robust API.
  • While freezing the API requirements, along with performance and functionalities, even Security Testing should be considered equally important and at par.
  • The API can be tested within the team with probable scenarios and the behavior across situations must be gauged for any possible security breaches.
  • The most effective way to prevent issues are to test them at inception. So, the testing has to start with the project’s beginning and not to be left till the end just before it goes into production.
  • Solutions or testing platforms within the team can be used to test the applications for vulnerabilities, performance, and usability. This can save the costs as well. Additionally, freely available tools can also be used to test the API.

In Conclusion

API Testing cannot take a single or a defined route. With the growing cyber-attacks and spread of unknown bugs almost every day, applications have to be tested for any possible threats. New age approaches such as Agile and DevOps are implemented to test continuously and keep a constant check on the bugs.

The most critical aspect to safeguard today is Data. API security testing is critical in the application development process. It will help keep the application safe from online attacks in any possible form. Enterprises should take up Security Testing for API to check the feeds coming in and analyzing the resulting behavior.

Safe and secure applications will sustain in the challenging marketplace. Functionalities can be enhanced, but security cannot be risked.

This blog post is in collaboration with Cigniti Technologies, an Independent Software Testing company.

LIKE THIS POST SHARE IT WITH YOUR FRIENDS

Share on facebook
Share on google
Share on twitter
Share on linkedin
Share on email
Improve Selenium Productivity

Bigger, Better And Faster - Your Favorite Testing Software Just Leveled Up!

Improve Selenium Productivity Selenium Test Automation

Bigger, Better And Faster – Your Favorite Testing Software Just Leveled Up!

CloudQA is committed to offering its clients the most advanced and the most efficient technologies. We spend a lot of time and effort in R&D, and try to bring the most stable and effective strategies to the market. We know the value of your time and money, and don’t skimp about features and capabilities. Keeping that in mind, we’ve been working our butts off to bring you even better features in your favorite testing software.

Now, using CloudQA, you can customize your execution by recording steps updates! We’ve given you a lot of control over this, and you can now define the speed of execution steps on the basis o your application being tested, and set element wait time at the application level in your app preferences. Besides that, you can now begin your testing before the UI is developed, saving everyone a lot of time, and hastening your software development process.

You can test “get”, “post”, and “delete” HTTP requests easily, as per your requirements. You can also save the API test case, and even reuse them when you need it next. You can also add assertions to confirm the response of the API, and view the response in both raw and JSON formats. Additionally, you can add parameters and headers based on the API you are currently using.

Finally, CloudQA has made monitoring your web application so much easier, it’s child’s play! You can check your URL every 5 minutes (free of cost, we might add) and upload all your URLs in a .csv file. You can test your website’s performance, and view up and down times of your website in both heat map and graph formats. Finally, we’ve also made sharing reports with your team members much easier with shareable links that improve team communication efficiency!

Phew! That’s been a lot of work. But, as they say, no rest for the wicked! We earnestly hope you like all these new updates we’ve rolled out for you. Get in touch if you have any queries about these or any other features of the site, and we’d be more than happy to help (In fact, get in touch with us anyway, we love feedback and communication!).  In the meantime, we’ll be over here working on getting you even more awesome new features and updates that will help you get your work done faster, more easily, and more efficiently!

For now – that’s all, folks!

If you want to learn more about being more productive with Test Automation, contact us at CloudQA (info@cloudqa.io)