Skip to content

Commit 63c21cc

Browse files
committed
End to end implementation
1 parent 56c0501 commit 63c21cc

File tree

9 files changed

+68
-26
lines changed

9 files changed

+68
-26
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
*** Settings ***
2+
Suite Teardown Close All Browsers
3+
Library ../resources/testlibs/get_selenium_options.py
4+
Resource resource.robot
5+
Documentation Creating test which would work on all browser is not possible. When testing with other
6+
... browser than Chrome it is OK that these test will fail. SeleniumLibrary CI is run with Chrome only
7+
... and therefore there is tests for Chrome only.
8+
... Also it is hard to create where chromedriver location would suite in all os and enviroments, therefore
9+
... there is a test which tests error scenario and other scenarios needed manual or unit level tests
10+
11+
*** Test Cases ***
12+
Chrome Browser With executable_path Argument
13+
Run Keyword And Expect Error
14+
... WebDriverException: Message: 'exist' executable needs to be in PATH.*
15+
... Open Browser ${FRONT PAGE} ${BROWSER} remote_url=${REMOTE_URL}
16+
... desired_capabilities=${DESIRED_CAPABILITIES} executable_path=/does/not/exist

src/SeleniumLibrary/keywords/browsermanagement.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class BrowserManagementKeywords(LibraryComponent):
3333
def __init__(self, ctx):
3434
LibraryComponent.__init__(self, ctx)
3535
self._window_manager = WindowManager(ctx)
36+
self._webdriver_creator = WebDriverCreator(self.log_dir)
3637

3738
@keyword
3839
def close_all_browsers(self):
@@ -58,7 +59,8 @@ def close_browser(self):
5859
@keyword
5960
def open_browser(self, url=None, browser='firefox', alias=None,
6061
remote_url=False, desired_capabilities=None,
61-
ff_profile_dir=None, options=None, service_log_path=None):
62+
ff_profile_dir=None, options=None, service_log_path=None,
63+
executable_path=None):
6264
"""Opens a new browser instance to the optional ``url``.
6365
6466
The ``browser`` argument specifies which browser to use. The
@@ -275,19 +277,20 @@ def open_browser(self, url=None, browser='firefox', alias=None,
275277
return index
276278
return self._make_new_browser(url, browser, alias, remote_url,
277279
desired_capabilities, ff_profile_dir,
278-
options, service_log_path)
280+
options, service_log_path, executable_path)
279281

280282
def _make_new_browser(self, url=None, browser='firefox', alias=None,
281283
remote_url=False, desired_capabilities=None,
282-
ff_profile_dir=None, options=None, service_log_path=None):
284+
ff_profile_dir=None, options=None, service_log_path=None,
285+
executable_path=None):
283286
if is_truthy(remote_url):
284287
self.info("Opening browser '%s' to base url '%s' through "
285288
"remote server at '%s'." % (browser, url, remote_url))
286289
else:
287290
self.info("Opening browser '%s' to base url '%s'." % (browser, url))
288291
driver = self._make_driver(browser, desired_capabilities,
289292
ff_profile_dir, remote_url,
290-
options, service_log_path)
293+
options, service_log_path, executable_path)
291294
driver = self._wrap_event_firing_webdriver(driver)
292295
index = self.ctx.register_driver(driver, alias)
293296
if is_truthy(url):
@@ -656,10 +659,10 @@ def set_browser_implicit_wait(self, value):
656659
self.driver.implicitly_wait(timestr_to_secs(value))
657660

658661
def _make_driver(self, browser, desired_capabilities=None, profile_dir=None,
659-
remote=None, options=None, service_log_path=None):
660-
driver = WebDriverCreator(self.log_dir).create_driver(
661-
browser=browser, desired_capabilities=desired_capabilities, remote_url=remote,
662-
profile_dir=profile_dir, options=options, service_log_path=service_log_path)
662+
remote=None, options=None, service_log_path=None, executable_path=None):
663+
driver = self._webdriver_creator.create_driver(
664+
browser=browser, desired_capabilities=desired_capabilities, remote_url=remote, profile_dir=profile_dir,
665+
options=options, service_log_path=service_log_path, executable_path=executable_path)
663666
driver.set_script_timeout(self.ctx.timeout)
664667
driver.implicitly_wait(self.ctx.implicit_wait)
665668
if self.ctx.speed:

src/SeleniumLibrary/keywords/webdrivertools/webdrivertools.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def __init__(self, log_dir):
6262

6363
def create_driver(self, browser, desired_capabilities, remote_url, profile_dir=None,
6464
options=None, service_log_path=None, executable_path=None):
65+
executable_path = None if is_falsy(executable_path) else executable_path
6566
browser = self._normalise_browser_name(browser)
6667
creation_method = self._get_creator_method(browser)
6768
desired_capabilities = self._parse_capabilities(desired_capabilities, browser)
@@ -72,10 +73,10 @@ def create_driver(self, browser, desired_capabilities, remote_url, profile_dir=N
7273
self._create_directory(service_log_path)
7374
if (creation_method == self.create_firefox
7475
or creation_method == self.create_headless_firefox):
75-
return creation_method(desired_capabilities, remote_url, profile_dir,
76-
options=options, service_log_path=service_log_path)
76+
return creation_method(desired_capabilities, remote_url, profile_dir, options=options,
77+
service_log_path=service_log_path, executable_path=executable_path)
7778
return creation_method(desired_capabilities, remote_url, options=options,
78-
service_log_path=service_log_path)
79+
service_log_path=service_log_path, executable_path=executable_path)
7980

8081
def _get_creator_method(self, browser):
8182
if browser in self.browser_names:

utest/test/keywords/test_browsermanagement.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import unittest
22

3-
from mockito import when, mock, verify, verifyNoMoreInteractions, unstub
3+
from mockito import when, mock, verify, verifyNoMoreInteractions, unstub, ANY
44
from selenium import webdriver
55

66
from SeleniumLibrary.keywords import BrowserManagementKeywords
@@ -89,8 +89,10 @@ def test_open_browser_speed(self):
8989
ctx.event_firing_webdriver = None
9090
ctx.speed = 5.0
9191
browser = mock()
92-
when(webdriver).Chrome(options=None, service_log_path=None, executable_path='chromedriver').thenReturn(browser)
92+
executable_path = 'chromedriver'
93+
when(webdriver).Chrome(options=None, service_log_path=None, executable_path=executable_path).thenReturn(browser)
9394
bm = BrowserManagementKeywords(ctx)
95+
when(bm._webdriver_creator)._get_executable_path(ANY).thenReturn(executable_path)
9496
bm.open_browser('http://robotframework.org/', 'chrome')
9597
self.assertEqual(browser._speed, 5.0)
9698
unstub()
@@ -101,8 +103,10 @@ def test_create_webdriver_speed(self):
101103
ctx.event_firing_webdriver = None
102104
ctx.speed = 0.0
103105
browser = mock()
104-
when(webdriver).Chrome(options=None, service_log_path=None, executable_path='chromedriver').thenReturn(browser)
106+
executable_path = 'chromedriver'
107+
when(webdriver).Chrome(options=None, service_log_path=None, executable_path=executable_path).thenReturn(browser)
105108
bm = BrowserManagementKeywords(ctx)
109+
when(bm._webdriver_creator)._get_executable_path(ANY).thenReturn(executable_path)
106110
bm.open_browser('http://robotframework.org/', 'chrome')
107111
verify(browser, times=0).__call__('_speed')
108112
unstub()

utest/test/keywords/test_keyword_arguments_browsermanagement.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@ def test_open_browser(self):
2222
url = 'https://github.com/robotframework'
2323
remote_url = '"http://localhost:4444/wd/hub"'
2424
browser = mock()
25-
when(self.brorser)._make_driver('firefox', None,
26-
None, False, None, None).thenReturn(browser)
25+
when(self.brorser)._make_driver('firefox', None, None, False, None, None, None).thenReturn(browser)
2726
alias = self.brorser.open_browser(url)
2827
self.assertEqual(alias, None)
2928

30-
when(self.brorser)._make_driver('firefox', None,
31-
None, remote_url, None, None).thenReturn(browser)
29+
when(self.brorser)._make_driver('firefox', None, None, remote_url, None, None, None).thenReturn(browser)
3230
alias = self.brorser.open_browser(url, alias='None',
3331
remote_url=remote_url)
3432
self.assertEqual(alias, None)
@@ -46,8 +44,7 @@ def test_same_alias(self):
4644

4745
def test_open_browser_no_get(self):
4846
browser = mock()
49-
when(self.brorser)._make_driver('firefox', None,
50-
None, False, None, None).thenReturn(browser)
47+
when(self.brorser)._make_driver('firefox', None, None, False, None, None, None).thenReturn(browser)
5148
self.brorser.open_browser()
5249
verify(browser, times=0).get(ANY)
5350

utest/test/keywords/test_selenium_options_parser.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,10 @@ def test_create_driver_chrome(creator):
450450
options = mock()
451451
expected_webdriver = mock()
452452
when(creator.selenium_options).create('chrome', str_options).thenReturn(options)
453+
executable_path = 'chromedriver'
454+
when(creator)._get_executable_path(ANY).thenReturn(executable_path)
453455
when(webdriver).Chrome(service_log_path=None, options=options,
454-
executable_path='chromedriver').thenReturn(expected_webdriver)
456+
executable_path=executable_path).thenReturn(expected_webdriver)
455457
driver = creator.create_driver('Chrome', desired_capabilities={}, remote_url=None,
456458
options=str_options)
457459
assert driver == expected_webdriver
@@ -465,7 +467,9 @@ def test_create_driver_firefox(creator, output_dir):
465467
when(webdriver).FirefoxProfile().thenReturn(profile)
466468
expected_webdriver = mock()
467469
when(creator.selenium_options).create('firefox', str_options).thenReturn(options)
468-
when(webdriver).Firefox(options=options, firefox_profile=profile, executable_path='geckodriver',
470+
executable_path = 'geckodriver'
471+
when(creator)._get_executable_path(ANY).thenReturn(executable_path)
472+
when(webdriver).Firefox(options=options, firefox_profile=profile, executable_path=executable_path,
469473
service_log_path=log_file).thenReturn(expected_webdriver)
470474
driver = creator.create_driver('FireFox', desired_capabilities={}, remote_url=None,
471475
options=str_options)

utest/test/keywords/test_webdrivercreator.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -680,8 +680,10 @@ def test_iphone_no_browser_name(creator):
680680

681681
def test_create_driver_chrome(creator):
682682
expected_webdriver = mock()
683+
executable_path = 'chromedriver'
684+
when(creator)._get_executable_path(ANY).thenReturn(executable_path)
683685
when(webdriver).Chrome(options=None, service_log_path=None,
684-
executable_path='chromedriver').thenReturn(expected_webdriver)
686+
executable_path=executable_path).thenReturn(expected_webdriver)
685687
for browser in ['chrome', 'googlechrome', 'gc']:
686688
driver = creator.create_driver(browser, None, None)
687689
assert driver == expected_webdriver
@@ -692,7 +694,9 @@ def test_create_driver_firefox(creator):
692694
profile = mock()
693695
when(webdriver).FirefoxProfile().thenReturn(profile)
694696
log_file = get_geckodriver_log()
695-
when(webdriver).Firefox(options=None, service_log_path=log_file, executable_path='geckodriver',
697+
executable_path = 'geckodriver'
698+
when(creator)._get_executable_path(ANY).thenReturn(executable_path)
699+
when(webdriver).Firefox(options=None, service_log_path=log_file, executable_path=executable_path,
696700
firefox_profile=profile).thenReturn(expected_webdriver)
697701
for browser in ['ff', 'firefox']:
698702
driver = creator.create_driver(browser, None, None, None)
@@ -701,8 +705,10 @@ def test_create_driver_firefox(creator):
701705

702706
def test_create_driver_ie(creator):
703707
expected_webdriver = mock()
708+
executable_path = 'IEDriverServer.exe'
709+
when(creator)._get_executable_path(ANY).thenReturn(executable_path)
704710
when(webdriver).Ie(options=None, service_log_path=None,
705-
executable_path='IEDriverServer.exe').thenReturn(expected_webdriver)
711+
executable_path=executable_path).thenReturn(expected_webdriver)
706712
for browser in ['ie', 'Internet Explorer']:
707713
driver = creator.create_driver(browser, None, None)
708714
assert driver == expected_webdriver

utest/test/keywords/test_webdrivercreator_executable_path.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from mockito import mock, unstub, when, ANY
77
from selenium import webdriver
88

9+
from SeleniumLibrary import BrowserManagementKeywords
910
from SeleniumLibrary.keywords import WebDriverCreator
1011

1112

@@ -294,6 +295,14 @@ def test_create_iphone_executable_path_set(creator):
294295
assert driver == expected_webdriver
295296

296297

298+
def test_open_browser_executable_path_set(creator):
299+
expected_webdriver = mock()
300+
when(webdriver).Chrome(options=None, service_log_path=None,
301+
executable_path='/path/to/chromedriver').thenReturn(expected_webdriver)
302+
driver = creator.create_driver('Chrome', {}, None, executable_path='/path/to/chromedriver')
303+
assert driver == expected_webdriver
304+
305+
297306
def mock_file_detector(creator):
298307
file_detector = mock()
299308
when(creator)._get_sl_file_detector().thenReturn(file_detector)

utest/test/keywords/test_webdrivercreator_service_log_path.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,10 @@ def test_create_firefox_from_create_driver(creator):
120120
when(webdriver).FirefoxProfile().thenReturn(profile)
121121
options = mock()
122122
when(webdriver).FirefoxOptions().thenReturn(options)
123+
executable_path = 'geckodriver'
124+
when(creator.creator)._get_executable_path(ANY).thenReturn(executable_path)
123125
when(webdriver).Firefox(options=None, firefox_profile=profile, service_log_path=log_file,
124-
executable_path='geckodriver').thenReturn(expected_webdriver)
126+
executable_path=executable_path).thenReturn(expected_webdriver)
125127
driver = creator.creator.create_driver('firefox ', {}, remote_url=None, profile_dir=None,
126128
service_log_path=log_file)
127129
assert driver == expected_webdriver

0 commit comments

Comments
 (0)