Please note that MAZ Systems is now happy to be part of Zype’s suite of online video solutions, and we’re currently in the process of updating our blog content. If you’re a current customer in need of support for your applications, please visit our help center or contact us for assistance.
Google app script can be a very useful tool when it comes to testing and automating a UI less application. This blog will help you to use Google App scripts to automate the API testing and its use cases.
GAS (Google App script) can be used with any of the API formats be it SOAP, REST or the GraphQL. The below-mentioned approach will make your testing much easier and scalable while using the GAS.
Use of Spreadsheet :
GAS provides a very handy support for other Google products and Google’s spreadsheets are one of them.
At one hand spreadsheet can be used to maintain the test data, On the other hand, this spreadsheet can be integrated with desired menu options like given in the image below.
To Perform this open a new spreadsheet and go to tools and click on script editor. A new GAS will open.
Paste the below code into the script file
var ui = SpreadsheetApp.getUi();
ui.createMenu('Test Menu').addItem("Run First Function", "functionName").addItem("Run Second Function", "secondFunction").addToUi();
Defining the test data :
Spreadsheets can be used for any type of testing framework. eg.
Test Data-driven framework
Keyword driven framework
A typical sheet with the test data looks like
In the case of keyword driven testing, any parameter can be defined in the test data that can be used as a key to call various use cases of the code.
Furthermore, the most useful function that GAS provides to be used for calling the APIs(REST, SOAP and GraphQL) is UrlFetchApp.fetch(endpoint, options)
This function returns the response of the API which can further be parsed in the desired format and can be used for validations of the use cases.