Skip to content

Commit

Permalink
Add new config property to install chrome extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
rgonalo committed Jan 13, 2023
1 parent d6b8cf5 commit d6a0fc7
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.rst
@@ -1,11 +1,15 @@
Toolium Changelog
=================

v2.6.4
v2.7.0
------

*Release date: In development*

- Allow to add extensions to chrome options from properties file

New config section [ChromeExtensions] with extensions file paths, e.g. 'firebug: resources/firebug-lite.crx'

v2.6.3
------

Expand Down
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
2.6.4.dev0
2.7.0.dev0
12 changes: 12 additions & 0 deletions docs/browser_configuration.rst
Expand Up @@ -251,6 +251,18 @@ For example, to use a predefined chrome profile::
[ChromeArguments]
user-data-dir: C:\Users\USERNAME\AppData\Local\Google\Chrome\User Data

**ChromeExtensions section**

Chrome plugins can also be installed adding their file paths to *[ChromeExtensions]* configuration section.

For example, the following configuration install firebug lite extension in Chrome::

[Driver]
type: chrome

[ChromeExtensions]
firebug: resources/firebug-lite.crx

**ChromeMobileEmulation section**

Another examples showing how to use
Expand Down
16 changes: 15 additions & 1 deletion toolium/config_driver.py
Expand Up @@ -337,10 +337,11 @@ def _create_chrome_options(self):
if chrome_binary is not None:
options.binary_location = chrome_binary

# Add Chrome preferences, mobile emulation options and chrome arguments
# Add Chrome preferences, arguments, extensions and mobile emulation options
self._add_chrome_options(options, 'prefs')
self._add_chrome_options(options, 'mobileEmulation')
self._add_chrome_arguments(options)
self._add_chrome_extensions(options)

return options

Expand Down Expand Up @@ -375,6 +376,19 @@ def _add_chrome_arguments(self, options):
except NoSectionError:
pass

def _add_chrome_extensions(self, options):
"""Add Chrome extensions from properties file
:param options: chrome options object
"""
# Add Chrome extensions
try:
for pref, pref_value in dict(self.config.items('ChromeExtensions')).items():
self.logger.debug("Added chrome extension: %s = %s", pref, pref_value)
options.add_extension(pref_value)
except NoSectionError:
pass

def _add_chrome_options_to_capabilities(self, capabilities):
"""Add Chrome options to capabilities
Expand Down
3 changes: 3 additions & 0 deletions toolium/test/test_config_driver.py
Expand Up @@ -660,6 +660,8 @@ def test_create_chrome_options(webdriver_mock, config, utils):
config.set('ChromeMobileEmulation', 'deviceName', 'Google Nexus 5')
config.add_section('ChromeArguments')
config.set('ChromeArguments', 'lang', 'es')
config.add_section('ChromeExtensions')
config.set('ChromeExtensions', 'firebug', 'resources/firebug-lite.crx')
config_driver = ConfigDriver(config, utils)

config_driver._create_chrome_options()
Expand All @@ -669,6 +671,7 @@ def test_create_chrome_options(webdriver_mock, config, utils):
mock.call('mobileEmulation', {'deviceName': 'Google Nexus 5'})]
)
webdriver_mock.ChromeOptions().add_argument.assert_called_once_with('lang=es')
webdriver_mock.ChromeOptions().add_extension.assert_called_once_with('resources/firebug-lite.crx')


@mock.patch('toolium.config_driver.webdriver')
Expand Down

0 comments on commit d6a0fc7

Please sign in to comment.