Integrating google sheets API with katalon studio using a service account

25.09.2023 | by Ralph Van Der Horst

Integrating Google Sheets API with Katalon Studio Using a Service Account

Introduction

I revambed a repsonse I made in one of the katalon forum back in those days :-). For one of my customers I made a keyword api with a service account which could read and write to a google sheets.

In automated testing, Katalon Studio is being recognized as a comprehensive and robust platform, enabling the integration of various services for enhancing testing workflows. In this tutorial, we are demonstrating how you can seamlessly integrate Google Sheets API with Katalon Studio using a service account. This integration is very beneficial for testers who want to use spreadsheet data in their test cases.

Prerequisites

  1. Google Cloud Account: You are needing a Google Cloud account for accessing the Google Sheets API and for creating a service account.
  2. Katalon Studio: Ensure that Katalon Studio is installed and set up on your system.

Step 1: Enable Google Sheets API

  1. Go to the Google Cloud Console.
  2. Select or create a new project.
  3. Go to ‘API & Services’ -> ‘Dashboard’.
  4. Enable the Google Sheets API for your project.
  5. Create credentials for a service account and download the JSON key file. note: you need to be admin to setup service account, so align with your admin

Step 2: Share Google Sheet with Service Account

Share your Google Sheet with the email address associated with the service account and give the necessary permissions.

Step 3: Set up Katalon Studio

  1. Open Katalon Studio and make a new project.
  2. Go to Project -> Settings -> External Libraries, and add the Google Sheets API client library JAR files to your project. The library can be downloaded from the Google Sheets API Java Client page. (via graddle or maven)

Step 4: Create a Custom Keyword in Katalon Studio

Make a new package within Keywords, then inside the package, create a new keyword. Here is an example implementation of the keyword for reading data from Google Sheets:

package com.katalon.keyword;

// Import needed libraries

public class GoogleSheetReader {

    private static final String APPLICATION_NAME = "Google Sheets API Java Quickstart";
    private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();

    @Keyword
    def readSheetData(String spreadsheetId, String range) {
        // Implementation to read data from Google Sheets
    }
}

Step 5: Utilize the Custom Keyword in a Test Case

Make a new test case and use the CustomKeywords class to call the readSheetData keyword, passing the Spreadsheet ID and Range as parameters.

Will create a repo as an example shortly(somewhere this week)

by Ralph Van Der Horst

arrow right
back to blog

share this article