Skip to content
Smart Data

Informational

How to Integrate Google Sheets with Selenium

Jay Brown

Business Development3 min read

Integrating Google Sheets with Selenium, with screenshots of the Google Sheets API console, Java code and a test data sheet

Microsoft Excel is easily one of the most versatile and essential software in Test Automation framework to manage the test data and track the status back. But because Excel is mainly used on individual computers, it is challenging for users to access their documents from anywhere or to collaborate with their team in real time. Emailing files back and forth can get confusing and no one is sure which version is the right one.

Google Sheets is cloud-based spreadsheet software is the best alternatives available if you are working on the Data-driven framework.

In this article, we going to use Google spreadsheets as the data source to read the data from Selenium and pass on to a website.

Some of the key advantages of using Google Sheets:

  • Easy to use
  • Built for collaboration
  • Built-in Version Control
  • Better visibility
  • Access to your test data from any computer

Pre-Requisites:

  • Java 1.7 or greater
  • Access to the internet and a web browser
  • A Google account with Google Drive enabled

Configure the google drive, OAuth account, Service account, Shared google sheet

  1. Login to your Gmail account and open the URL https://console.developers.google.com/
  2. Create a new project.

Google Cloud console New Project form, the first step in setting up the Sheets API

3. Then after you need to enable google sheets API library

  • Navigate to Library
  • Search for API “Google sheets API”
  • Enable “Google sheets API”

Google Sheets API page in the Google Cloud console, with the API enabled

4. After successful Google Sheets API enabled, the screen looks like this.

Google Sheets API overview page showing traffic and API details

5. Create OAuth Client ID, create Credentials → OAuth client ID

6. Fill the details and complete the OAuth client ID.

Credentials wizard asking which API you are using and what data you will access

7. After creating OAuth key, it will display the Client ID and click the OK button. Then after the download the JSON file (Download JSON) button to the right of the client ID.

Credentials page listing the OAuth 2.0 client ID and the service account

8. Rename the Jason file to json and copy to project directory.

9. Then after create Service account from create Credentials à Service account.

Create service account form with name, ID and description fields

10. Create a Google sheet with login credentials to pass on to a website. Copy the document ID from the URL: https://docs.google.com/spreadsheets/d/<document ID>/edit#gid=0

Test Data Google Sheet with Username and Password columns

11. Share the file with service account (xxx-developer.gsserviceaccount.com) which you have created above and give editor access.

Sheet sharing dialog adding the service account as an editor

Google Sheets integration with Selenium

So far, we have configured the google drive, OAuth account, Service account, Shared google sheet. It’s time for the integration.

Download the following libraries and add them to your java project.

Code Snippet for reading the data from Google Sheet:

Java TestGoogleSheet class with Google Sheets API imports and credential setup

Code Snippet for passing the data to a web application:

Java LoginVerification class that reads sheet rows and drives Chrome with Selenium

Written by Jay BrownAll posts
AI Enablement GuideA guide from Smart Data

Go further

Not sure your data is ready for AI?

The guide covers data maturity, use cases by readiness level and industry perspectives, so you can see where your platform stands before you pick a model.

Your privacy choices

Choose what this browser shares with us. The site works the same either way. Privacy policy