Skip to content

Commit b54e388

Browse files
committed
Executable path for Safari
1 parent 00799d4 commit b54e388

File tree

5 files changed

+28
-5
lines changed

5 files changed

+28
-5
lines changed

src/SeleniumLibrary/keywords/webdrivertools/webdrivertools.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,14 +231,17 @@ def create_opera(self, desired_capabilities, remote_url, options=None, service_l
231231
return webdriver.Opera(options=options, service_log_path=service_log_path, executable_path=executable_path,
232232
**desired_capabilities)
233233

234-
def create_safari(self, desired_capabilities, remote_url, options=None, service_log_path=None):
234+
def create_safari(self, desired_capabilities, remote_url, options=None, service_log_path=None,
235+
executable_path='/usr/bin/safaridriver'):
235236
if is_truthy(remote_url):
236237
defaul_caps = webdriver.DesiredCapabilities.SAFARI.copy()
237238
desired_capabilities = self._remote_capabilities_resolver(desired_capabilities, defaul_caps)
238239
return self._remote(desired_capabilities, remote_url)
239240
if options or service_log_path:
240241
logger.warn('Safari browser does not support Selenium options or service_log_path.')
241-
return webdriver.Safari(**desired_capabilities)
242+
if is_falsy(executable_path):
243+
executable_path = self._get_executable_path(webdriver.Safari)
244+
return webdriver.Safari(executable_path=executable_path, **desired_capabilities)
242245

243246
def create_phantomjs(self, desired_capabilities, remote_url, options=None, service_log_path=None):
244247
warnings.warn('SeleniumLibrary support for PhantomJS has been deprecated, '

utest/test/keywords/test_selenium_options_parser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,8 @@ def test_create_opera_with_options_and_remote_url(creator):
379379
def test_create_safari_no_options_support(creator):
380380
options = mock()
381381
expected_webdriver = mock()
382-
when(webdriver).Safari().thenReturn(expected_webdriver)
382+
executable_path = '/usr/bin/safaridriver'
383+
when(webdriver).Safari(executable_path=executable_path).thenReturn(expected_webdriver)
383384
driver = creator.create_safari({}, None, options=options)
384385
assert driver == expected_webdriver
385386

utest/test/keywords/test_webdrivercreator.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,8 @@ def test_opera_no_browser_name(creator):
483483

484484
def test_safari(creator):
485485
expected_webdriver = mock()
486-
when(webdriver).Safari().thenReturn(expected_webdriver)
486+
executable_path = '/usr/bin/safaridriver'
487+
when(webdriver).Safari(executable_path=executable_path).thenReturn(expected_webdriver)
487488
driver = creator.create_safari({}, None)
488489
assert driver == expected_webdriver
489490

utest/test/keywords/test_webdrivercreator_executable_path.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,23 @@ def test_create_opera_executable_path_not_set(creator):
208208
assert driver == expected_webdriver
209209

210210

211+
def test_create_safari_executable_path_set(creator):
212+
executable_path = '/path/to/safaridriver'
213+
expected_webdriver = mock()
214+
when(webdriver).Safari(executable_path=executable_path).thenReturn(expected_webdriver)
215+
driver = creator.create_safari({}, None, executable_path=executable_path)
216+
assert driver == expected_webdriver
217+
218+
219+
def test_create_safari_executable_path_not_set(creator):
220+
executable_path = '/usr/bin/safaridriver'
221+
expected_webdriver = mock()
222+
when(creator)._get_executable_path(ANY).thenReturn(executable_path)
223+
when(webdriver).Safari(executable_path=executable_path).thenReturn(expected_webdriver)
224+
driver = creator.create_safari({}, None, executable_path=None)
225+
assert driver == expected_webdriver
226+
227+
211228
def mock_file_detector(creator):
212229
file_detector = mock()
213230
when(creator)._get_sl_file_detector().thenReturn(file_detector)

utest/test/keywords/test_webdrivercreator_service_log_path.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ def test_create_opera_with_service_log_path_real_path(creator):
159159
def test_create_safari_no_support_for_service_log_path(creator):
160160
log_file = os.path.join(creator.output_dir, 'ie-1.log')
161161
expected_webdriver = mock()
162-
when(webdriver).Safari().thenReturn(expected_webdriver)
162+
executable_path = '/usr/bin/safaridriver'
163+
when(webdriver).Safari(executable_path=executable_path).thenReturn(expected_webdriver)
163164
driver = creator.creator.create_safari({}, None, service_log_path=log_file)
164165
assert driver == expected_webdriver
165166

0 commit comments

Comments
 (0)