[KShare] How to add Chrome extensions using Selenium on Katalon Studio?

Hi Community members, :wave:

Today, we are back with another article to help you add various Chrome extensions and integrating them with Katalon Studio using Selenium scripts to streamline your testing experiences with Studio. Read more below :point_down:

When it comes to testing web applications with Chrome extensions using Selenium and Katalon Studio, the traditional approach involves setting up a custom Chrome profile with the required extensions. However, there are scenarios, like working in restricted environments, where using custom profiles may not be possible.

:information_source: In such cases, Selenium can be leveraged to dynamically add Chrome extensions directly within your test scripts. You can use Selenium to add the extension at the beginning of your test scripts (before the driver.get method) by using options.addExtensions(new File("/path/to/extension.crx"));

:white_check_mark: Solution

To do that, first, you will need to create a .crx of your extension by following these steps:

  • Go to chrome://extensions/

  • Turn on developer mode

  • Select the desired extension details

  • Copy extension ID (such as eningockdidmgiojffjmkdblpjocbhgh)

  • Open the Chrome extensions folder on your local machine:

    • For Windows: C:\Users\Administrator\AppData\Local\Google\Chrome\UserData\Default\Extensions
    • For Mac: /Users/<<username>>/Library/Application Support/Google/Chrome/Default/Extensions
  • Search the extension folder by the ID value you have copied

  • Copy this folder to the Desktop

  • Back to this Chrome Extensions on the web, select Pack Extension and browser to this Desktop folder

Then, You will get a .crx file created in the folder.

To create some Selenium scripts to add this extension, please see my custom scripts below:

import org.openqa.selenium.chrome.ChromeDriver

import org.openqa.selenium.chrome.ChromeOptions

import org.openqa.selenium.remote.DesiredCapabilities

import com.kms.katalon.core.webui.driver.DriverFactory

import org.openqa.selenium.WebDriver

// Copy the path to Chromedriver

String pathToChromeDriver = '/Applications/Katalon Studio 8.6.0.app/Contents/Eclipse/configuration/resources/drivers/chromedriver_mac/chromedriver'

System.setProperty('webdriver.chrome.driver', pathToChromeDriver)

 //This class is used for customizing the Chrome session

ChromeOptions options = new ChromeOptions() 

options.addExtensions(new File("/Users/thi.thai/Desktop/eningockdidmgiojffjmkdblpjocbhgh/4.1.1_0.crx"))

 DesiredCapabilities caps = new DesiredCapabilities()

 caps.setCapability(ChromeOptions.CAPABILITY, options)

 WebDriver driver = new ChromeDriver(caps)

 DriverFactory.changeWebDriver(driver)

 //Maximize window

driver.manage().window().maximize()

 WebUI.navigateToUrl("https://google.com")

After that, you can execute the test with any browser, and it should then be added to your extensions.

Reference


If you find this article helpful, then don’t forget to give us a big like :+1: or a heart :heart:. That would mean a lot for us to continue sharing with you these KShare articles!

You can also share this article by following the instructions in the comment below. :point_down:

3 Likes

Thank you very much the Product Support team (@support.squad) and Caryln (@thi.thai) for another helpful article!

Caryln profile pic
Caryln (@thi.thai) - Product Support Specialist at Katalon
Caryln enjoys offering supporting and assisting our clients with technical issues and questions, as well as sharing her knowledge and experiences with the wider Katalon Community. She is always available to assist users if they have questions or concerns with Katalon products, and she strives to make sure our users have a positive testing experience.
2 Likes

Follow the steps below to share this thread on your social media platform:

  1. Scroll down to the bottom of the post, and click the Share button :link: Share
  2. In the modal that appear, choose the appropriate social media platform. Or, if your platform of choice is not present, simply copy the link.

Screen Recording 2023-11-20 at 16.09.06