Skip to content

Commit c266cf4

Browse files
committed
Executable path for PhantomJS
1 parent b54e388 commit c266cf4

File tree

5 files changed

+29
-5
lines changed

5 files changed

+29
-5
lines changed

src/SeleniumLibrary/keywords/webdrivertools/webdrivertools.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ def create_safari(self, desired_capabilities, remote_url, options=None, service_
243243
executable_path = self._get_executable_path(webdriver.Safari)
244244
return webdriver.Safari(executable_path=executable_path, **desired_capabilities)
245245

246-
def create_phantomjs(self, desired_capabilities, remote_url, options=None, service_log_path=None):
246+
def create_phantomjs(self, desired_capabilities, remote_url, options=None, service_log_path=None,
247+
executable_path='phantomjs'):
247248
warnings.warn('SeleniumLibrary support for PhantomJS has been deprecated, '
248249
'please use headlesschrome or headlessfirefox instead.')
249250
if is_truthy(remote_url):
@@ -252,7 +253,10 @@ def create_phantomjs(self, desired_capabilities, remote_url, options=None, servi
252253
return self._remote(desired_capabilities, remote_url)
253254
if options:
254255
logger.warn('PhantomJS browser does not support Selenium options.')
255-
return webdriver.PhantomJS(service_log_path=service_log_path, **desired_capabilities)
256+
if is_falsy(executable_path):
257+
executable_path = self._get_executable_path(webdriver.PhantomJS)
258+
return webdriver.PhantomJS(service_log_path=service_log_path, executable_path=executable_path,
259+
**desired_capabilities)
256260

257261
def create_htmlunit(self, desired_capabilities, remote_url, options=None, service_log_path=None):
258262
if service_log_path or options:

utest/test/keywords/test_selenium_options_parser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,8 @@ def test_create_safari_no_options_support(creator):
388388
def test_create_phantomjs_no_options_support(creator):
389389
options = mock()
390390
expected_webdriver = mock()
391-
when(webdriver).PhantomJS(service_log_path=None).thenReturn(expected_webdriver)
391+
executable_path = 'phantomjs'
392+
when(webdriver).PhantomJS(service_log_path=None, executable_path=executable_path).thenReturn(expected_webdriver)
392393
driver = creator.create_phantomjs({}, None, options=options)
393394
assert driver == expected_webdriver
394395

utest/test/keywords/test_webdrivercreator.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,8 @@ def test_safari_no_broser_name(creator):
526526

527527
def test_phantomjs(creator):
528528
expected_webdriver = mock()
529-
when(webdriver).PhantomJS(service_log_path=None).thenReturn(expected_webdriver)
529+
executable_path = 'phantomjs'
530+
when(webdriver).PhantomJS(service_log_path=None, executable_path=executable_path).thenReturn(expected_webdriver)
530531
driver = creator.create_phantomjs({}, None)
531532
assert driver == expected_webdriver
532533

utest/test/keywords/test_webdrivercreator_executable_path.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,23 @@ def test_create_safari_executable_path_not_set(creator):
225225
assert driver == expected_webdriver
226226

227227

228+
def test_create_phantomjs_executable_path_set(creator):
229+
executable_path = '/path/to/phantomjs'
230+
expected_webdriver = mock()
231+
when(webdriver).PhantomJS(service_log_path=None, executable_path=executable_path).thenReturn(expected_webdriver)
232+
driver = creator.create_phantomjs({}, None, executable_path=executable_path)
233+
assert driver == expected_webdriver
234+
235+
236+
def test_create_phantomjs_executable_path_not_set(creator):
237+
executable_path = 'phantomjs'
238+
expected_webdriver = mock()
239+
when(creator)._get_executable_path(ANY).thenReturn(executable_path)
240+
when(webdriver).PhantomJS(service_log_path=None, executable_path=executable_path).thenReturn(expected_webdriver)
241+
driver = creator.create_phantomjs({}, None, executable_path=None)
242+
assert driver == expected_webdriver
243+
244+
228245
def mock_file_detector(creator):
229246
file_detector = mock()
230247
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
@@ -168,6 +168,7 @@ def test_create_safari_no_support_for_service_log_path(creator):
168168
def test_create_phantomjs_with_service_log_path_real_path(creator):
169169
log_file = os.path.join(creator.output_dir, 'ie-1.log')
170170
expected_webdriver = mock()
171-
when(webdriver).PhantomJS(service_log_path=log_file).thenReturn(expected_webdriver)
171+
executable_path = 'phantomjs'
172+
when(webdriver).PhantomJS(service_log_path=log_file, executable_path=executable_path).thenReturn(expected_webdriver)
172173
driver = creator.creator.create_phantomjs({}, None, service_log_path=log_file)
173174
assert driver == expected_webdriver

0 commit comments

Comments
 (0)