Skip to content

Commit 57be0dc

Browse files
authored
Firefox profile dir (robotframework#1401)
Support for FirefoxProfile instance for Open Browser keyword
1 parent de3d1aa commit 57be0dc

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

src/SeleniumLibrary/keywords/browsermanagement.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ def open_browser(self, url, browser='firefox', alias=None,
115115
Optional ``ff_profile_dir`` is the path to the Firefox profile
116116
directory if you wish to overwrite the default profile Selenium
117117
uses. Notice that prior to SeleniumLibrary 3.0, the library
118-
contained its own profile that was used by default.
118+
contained its own profile that was used by default. The
119+
``ff_profile_dir`` can also be instance of the
120+
[https://seleniumhq.github.io/selenium/docs/api/py/webdriver_firefox/selenium.webdriver.firefox.firefox_profile.html?highlight=firefoxprofile#selenium.webdriver.firefox.firefox_profile.FirefoxProfile|selenium.webdriver.FirefoxProfile].
119121
120122
Optional ``service_log_path`` argument defines the name of the
121123
file where to write the browser driver logs. If the
@@ -149,7 +151,9 @@ def open_browser(self, url, browser='firefox', alias=None,
149151
150152
Using ``alias`` to decide, is the new browser opened is new
151153
in SeleniumLibrary 4.0. Also the ``service_log_path`` is new
152-
in SeleniumLibrary 4.0.
154+
in SeleniumLibrary 4.0. Support for ``ff_profile_dir`` accepting
155+
instance of the `selenium.webdriver.FirefoxProfile` is new in
156+
SeleniumLibrary 4.0.
153157
"""
154158
index = self.drivers.get_index(alias)
155159
if index:

src/SeleniumLibrary/keywords/webdrivertools.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from robot.api import logger
2121
from robot.utils import ConnectionCache
2222
from selenium import webdriver
23+
from selenium.webdriver import FirefoxProfile
2324

2425
from SeleniumLibrary.utils import is_falsy, is_truthy, is_noney
2526

@@ -122,6 +123,8 @@ def create_firefox(self, desired_capabilities, remote_url, ff_profile_dir, optio
122123
**desired_capabilities)
123124

124125
def _get_ff_profile(self, ff_profile_dir):
126+
if isinstance(ff_profile_dir, FirefoxProfile):
127+
return ff_profile_dir
125128
if is_falsy(ff_profile_dir):
126129
return webdriver.FirefoxProfile()
127130
return webdriver.FirefoxProfile(ff_profile_dir)

utest/test/keywords/test_webdrivercreator.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,24 @@ def test_firefox(self):
186186
self.assertEqual(driver, expected_webdriver)
187187
verify(webdriver).FirefoxProfile()
188188

189+
def test_get_ff_profile_real_path(self):
190+
profile_path = '/path/to/profile'
191+
profile_mock = mock()
192+
when(webdriver).FirefoxProfile(profile_path).thenReturn(profile_mock)
193+
profile = self.creator._get_ff_profile(profile_path)
194+
self.assertEqual(profile, profile_mock)
195+
196+
def test_get_ff_profile_no_path(self):
197+
profile_mock = mock()
198+
when(webdriver).FirefoxProfile().thenReturn(profile_mock)
199+
profile = self.creator._get_ff_profile(None)
200+
self.assertEqual(profile, profile_mock)
201+
202+
def test_get_ff_profile_instance_FirefoxProfile(self):
203+
input_profile = webdriver.FirefoxProfile()
204+
profile = self.creator._get_ff_profile(input_profile)
205+
self.assertEqual(profile, input_profile)
206+
189207
def test_firefox_remote_no_caps(self):
190208
url = 'http://localhost:4444/wd/hub'
191209
profile = mock()

0 commit comments

Comments
 (0)