How to test Google API in JMeter?

Application Programming Interface (API) is a set of protocols, routines, and tools for building software applications. Source: Wikipedia. E.g. you are building a website where you would like to integrate Login module with the social media accounts such as Facebook, Twitter, Google Plus, and LinkedIn. What you have to do is, grab the Login APIs from your social media accounts and embed it in your site. Now, your website visitor can sign-up and login using their social accounts.

Here is the link to integrate Facebook Login to the app or website https://developers.facebook.com/docs/facebook-login Similarly there are numerous APIs available for Like, Follow, Share, Page, Comments etc.

Sample Login Page
Sample Login Page

In this article, you are going to learn how to test Google APIs in JMeter. I feel that learning web services testing using JMeter is quite easier than HP LoadRunner. JMeter user interface expedites the process of designing the test plan and time-to-go for execution is lesser than any other tool.

Prerequisites

Google has vast line of APIs for each of its products. You can check all the APIs in this link https://developers.google.com/products/ To get Google API, all you need is valid Gmail account. APIs are free up to some extent. APIs are available at https://console.developers.google.com where you can create projects under one umbrella.

How to create a project in Google Developers Console?

How to enable APIs in Google Developers Console?

In this blog post, you are going to learn how to test Google URL Shortener, Google Web Fonts, and Google Maps Time Zone. Once the project is created, you need to enable respective APIs for testing.

  • Click on APIs link which is beneath APIs & auth.
  • Click on the API link e.g. URL Shortener API
  • Click on Enable API

Similarly you have to repeat it for Google Web Fonts, and Google Maps Time Zone. Or, you can create individual project for Google Web Fonts, and Google Maps Time Zone.

Enable API
Enable API

How to create an API key?

Inside the project, click on Credentials where you can create OAuth and Public API Access. It is always highly recommended to use API key for your requests.

Create API Key
Create API Key

Based on the APIs that you are going to use for your project, you can create OAuth or Public Access Key. E.g. if your project is going to get users data, you need to use OAuth or if your project doesn’t need any of the user’s information, you can have only Public API Access key. In this example, we are not going to get any users info, so Public API access key is just enough.

Click on Create new Key and select Browser key to create.

How to test Google API in JMeter?

All is set. Now you are going to learn how to test Google URL Shortener, Google Web Fonts, and Google Maps Time Zone APIs using JSON request in JMeter. Launch JMeter and design the above flow with the following elements.

JMeter Test Plan
JMeter Test Plan
  • Loop Controllers
  • HTTP Request Samplers
  • HTTP Header Manager
  • View Results Tree Listener

I always use Loop Controllers just to categorize the HTTP requests.

Google URL Shortener

Google URL Shortener enables users to shorten the URL and it helps to track the clicks. Shortened URL will have the goo.gl. Google URL Shortener uses POST method with the content-type as application/json and the post data is {“longUrl”: “http://www.qainsights.com/”}

Enter below details in the HTTP request replace the value YOUR_API_KEY with your API access key and click on Run.

URL Shortener HTTP Request
URL Shortener HTTP Request

Google returns the shortened URL for www.QAInsights.com as shown below.

{
 "kind": "urlshortener#url",
 "id": "http://goo.gl/G0aGlb",
 "longUrl": "http://www.qainsights.com/"
}

Similarly enter below details for Google Web Fonts and Google Maps Time Zone APIs. Google Web Fonts uses GET method whereas Google Maps Time Zone uses POST method.

Google Web Fonts HTTP Request
Google Web Fonts HTTP Request
Google Maps Time Zone HTTP Request
Google Maps Time Zone HTTP Request

Below are the respective response from Google.

Google Web Fonts response

{
 "kind": "webfonts#webfontList",
 "items": [
  {
   "kind": "webfonts#webfont",
   "family": "ABeeZee",
   "category": "sans-serif",
   "variants": [
    "regular",
    "italic"
   ],
   "subsets": [
    "latin"
   ],
   "version": "v4",
   "lastModified": "2015-04-06",
   "files": {
    "regular": "http://fonts.gstatic.com/s/abeezee/v4/mE5BOusdfsdfsfZKGln_Ex0uYKpIaw.ttf",
    "italic": "http://fonts.gstatic.com/s/abeezee/v4/kpplLydfsdfnmYgP0YtlJA3atRw.ttf"
   }

And so on.

Note: Google Web Fonts response is too high. By default, JMeter will not show everything. You will get below message in the response. By changing the JMeter properties, you can enable JMeter to show complete response.

Response too large to be displayed. Size: 311903 > Max: 204800, Start of message:

Google Maps Time Zone response

{
   "dstOffset" : 0,
   "rawOffset" : -28800,
   "status" : "OK",
   "timeZoneId" : "America/Los_Angeles",
   "timeZoneName" : "Pacific Standard Time"
}

Conclusion

Testing the Google APIs using JMeter is pretty simple, all you need is valid API key, method, URL, and JSON requests. Once the unit testing is done, you can design the workload model. Google allows you to send 1,000,000 requests per day for URL shortener.

If you need any help learning JMeter, you can join my course or you can see my detailed presentation

If you like my article, please do share in your favorite social media. Please do not forget to subscribe to my weekly newsletter, it is FREE.

About the Author

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Hamster - Launch JMeter Recent Test Plans SwiftlyDownload for free
+
Share via
Copy link