Integrating Selenium with Google Drive

Integrating Selenium with Google Drive

Listen on the go!

New-age technologies have extensively impacted our routine activities and quite positively. Today there are sophisticated and advanced gadgets available to further ease human efforts. While the emerging technologies continue to transform our lives, testing their performance for desired outcome is indispensable.

Test Automation holds numerous advantages to enhance the testing processes and achieve maximum test coverage. Google Drive integration is a case in point. We shall further discuss and understand the various advantages of using Google Drive.

When you integrate with the User Interface (UI) of Google Drive, users can create and open files stored on the drive within the application. This process is applicable across all the Google Drive Web applications. The Google Drive platform provides a bunch of APIs along with client libraries, language-specific examples, and documentation to help you develop apps that can integrate with Google Drive for automation.

sel-logo

Why is using Google Drive for Test Automation recommended?

  • You can create an external file that stores the test data (Input data and Expected Data) as centralized and shared repository.
  • You can populate the test data into Automation Test Script, so that several API’s can be used to read the test data.
  • The total number of scripts required to cover all the possible combinations of test scenarios is very less. Thus, lesser amount of code is required to test a complete set of scenarios.
  • You get increased flexibility and maintainability of automation test scripts, which also offers a clean and
    user-friendly interface.
  • Any change in the test data matrix would not hamper the test script code.
  • It provides effective communication and sharing, so that it is easier for manual and automation test teams to execute the scripts on Cloud with required set of data.
  • Check-in or check-out from the project framework is not required to refactor the test data.
  • High re-usability can be achieved, as tests can be reused across multiple test cases by altering the test data values.

Challenges of using Google Drive for Test Automation

  • In order to avoid script-processing errors due to incorrect data-file format or content, Notepad or Microsoft Excel has to be used to create and maintain the data files.
  • While developing and executing automation test scripts, technical skills are required to refactor the test data sheet within the Automation framework.

Prerequisites for Integration

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

Google Drive Configuration

    1. Login into your Gmail account like xx@gmail.com and navigate to the Access Link https://console.developers.google.com in other tab.
    2. Click on “Google API Console” under Developer Consoles section at bottom of the page or navigate to link – https://console.developers.google.com/apis/library
    3. Click on “Drive API” under Google Apps APIs section.

Google Apps APIs

    1. Create/Select a project in the Google Developers Console and enable the Google API. Click Continue, then Go to credentials.

Google API 4

    1. At the top of the page, select the OAuth consent screen tab. Select an Email address, enter a Product name if not already set, and click Save.

Image credentials - 5

6. Select the Credentials tab, click Create Credentials and select OAuth client ID.

selenium-image-6
7. Now to create Client Id, click on ‘Configure consent screen’.

selenium-7th
8. Select the application type other, enter the name “client Demo”, and click Create.

9. Now dialog will appear which shows your “OAuth Client Id and Client Secret”. Click OK to dismiss the resulting dialog.

selenium-9

10. Select the client name checkbox and click the file download (Download JSON) button to the right of the client ID.

selenium-10
11. Move the downloaded file to your working directory and rename it client_secret.json.

selenium-11

12. Now click on “Create credentials” drop down button and select “Service Account Key”.

selenium-12
13. Select “Service Account – Compute Engine default service account” and key type “P12”. Click Create.

14. Click Close to dismiss the resulting dialog.

selenium-14
15. Move the downloaded file – *.P12 to your working directory.

selenium-15

16. Open Google Drive from your Gmail account.

17. Create a new Google spreadsheet and save it as testSheet.

18. Click Share and share the spreadsheet with your Client Id (xxx-developer.gsserviceaccount.com) which you  created above.

19. Modify the Access Link setting – “Anyone with the link can edit”

20. Click Save.

Java Source Code for Integration

Here is a sample code in Java for accessing the Google Drive for any user. To use the same, first download the following jars or add maven dependencies.

Jar Files

code-1

 

code-2

code-3

code-4

code-5

code-6

 

code-7code-8code-9code-10code-11code-12code-13code-14

Conclusion

Google Drive is the most user-friendly storage option, where all test data can be loaded (For e.g. on Gmail, Google Docs, and spreadsheets), and accessed from all remote locations. Google provides both free and paid-for storage services. These provide multiple storage capacity options for your files and folders, where users can store backup local files and sync in files and folders across multiple computers.

It is recommended to utilize Google Drive services for Quality Assurance (QA) practices and further also integrate with Automation tools like Selenium.

Selenium is one of the most popular Automation testing suites. It is designed to test functional aspects of Web applications across a wide range of browsers and platforms. Considering it is an Open-Source platform, it is easy to integrate Google Drive with Selenium. Additionally, credentials of Google account can be shared with all authorized team members for effective execution of tests on the Cloud.

Ashish Jain technical lead at Cigniti TechnologiesAbout the Author: Ashish Jain, Technical Lead at Cigniti technologies, brings with him rich experience in the field of automation for web and mobile-based applications. He has extensive expertise in both functional as well as performance automation. He also holds expertise across various automation tools and technologies and has been involved in designing Testing solutions for various clients in Energy Utilities, Donation and fitness-based domains.