From 12f287638fc33398eaf0258077639b7b63a1218a Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Fri, 4 Jan 2019 21:57:11 +0200 Subject: [PATCH 1/8] Fixed remote_url and capabilites for Chrome --- .../keywords/webdrivertools.py | 2 ++ utest/test/keywords/test_webdrivercreator.py | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/SeleniumLibrary/keywords/webdrivertools.py b/src/SeleniumLibrary/keywords/webdrivertools.py index 684b4736c..bed2bcca0 100644 --- a/src/SeleniumLibrary/keywords/webdrivertools.py +++ b/src/SeleniumLibrary/keywords/webdrivertools.py @@ -87,6 +87,8 @@ def _string_to_dict(self, capabilities): def create_chrome(self, desired_capabilities, remote_url, options=None): if is_truthy(remote_url): + if not desired_capabilities: + desired_capabilities = {'desired_capabilities': webdriver.DesiredCapabilities.CHROME.copy()} return self._remote(desired_capabilities, remote_url, options=options) if SELENIUM_VERSION.major >= 3 and SELENIUM_VERSION.minor >= 8: return webdriver.Chrome(options=options, **desired_capabilities) diff --git a/utest/test/keywords/test_webdrivercreator.py b/utest/test/keywords/test_webdrivercreator.py index 0202c47b0..72b6a8e06 100644 --- a/utest/test/keywords/test_webdrivercreator.py +++ b/utest/test/keywords/test_webdrivercreator.py @@ -91,15 +91,28 @@ def test_chrome_with_desired_capabilities(self): driver = self.creator.create_chrome({'desired_capabilities': {'key': 'value'}}, None) self.assertEqual(driver, expected_webdriver) - def test_chrome_remote(self): + def test_chrome_remote_no_caps(self): url = 'http://localhost:4444/wd/hub' expected_webdriver = mock() + capabilities = webdriver.DesiredCapabilities.CHROME.copy() when(webdriver).Remote(command_executor=url, browser_profile=None, + desired_capabilities=capabilities, options=None).thenReturn(expected_webdriver) driver = self.creator.create_chrome({}, url) self.assertEqual(driver, expected_webdriver) + def test_chrome_remote_caps(self): + url = 'http://localhost:4444/wd/hub' + expected_webdriver = mock() + capabilities = {"browserName": "chrome"} + when(webdriver).Remote(command_executor=url, + browser_profile=None, + desired_capabilities=capabilities, + options=None).thenReturn(expected_webdriver) + driver = self.creator.create_chrome({'desired_capabilities': capabilities}, url) + self.assertEqual(driver, expected_webdriver) + def test_chrome_healdless(self): expected_webdriver = mock() options = mock() @@ -114,8 +127,10 @@ def test_chrome_healdless_with_grid(self): options = mock() when(webdriver).ChromeOptions().thenReturn(options) remote_url = 'localhost:4444' + capabilities = webdriver.DesiredCapabilities.CHROME.copy() when(webdriver).Remote(command_executor=remote_url, - options=options, browser_profile=None).thenReturn(expected_webdriver) + options=options, browser_profile=None, + desired_capabilities=capabilities).thenReturn(expected_webdriver) driver = self.creator.create_headless_chrome({}, remote_url) verify(options).set_headless() self.assertEqual(driver, expected_webdriver) From c94cb102cb932065f2a19df67ea75b664b3c6eda Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Fri, 4 Jan 2019 22:10:14 +0200 Subject: [PATCH 2/8] Fixed remote_url and capabilites for Firefox --- .../keywords/webdrivertools.py | 2 ++ utest/test/keywords/test_webdrivercreator.py | 33 ++++++++++++++++--- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/SeleniumLibrary/keywords/webdrivertools.py b/src/SeleniumLibrary/keywords/webdrivertools.py index bed2bcca0..6aef27a07 100644 --- a/src/SeleniumLibrary/keywords/webdrivertools.py +++ b/src/SeleniumLibrary/keywords/webdrivertools.py @@ -106,6 +106,8 @@ def create_firefox(self, desired_capabilities, remote_url, ff_profile_dir, options=None): profile = self._get_ff_profile(ff_profile_dir) if is_truthy(remote_url): + if not desired_capabilities: + desired_capabilities = {'desired_capabilities': webdriver.DesiredCapabilities.FIREFOX.copy()} return self._remote(desired_capabilities, remote_url, profile, options) desired_capabilities.update(self._geckodriver_log) diff --git a/utest/test/keywords/test_webdrivercreator.py b/utest/test/keywords/test_webdrivercreator.py index 72b6a8e06..f659b83a8 100644 --- a/utest/test/keywords/test_webdrivercreator.py +++ b/utest/test/keywords/test_webdrivercreator.py @@ -147,17 +147,30 @@ def test_firefox(self): self.assertEqual(driver, expected_webdriver) verify(webdriver).FirefoxProfile() - def test_firefox_remote(self): + def test_firefox_remote_no_caps(self): url = 'http://localhost:4444/wd/hub' profile = mock() when(webdriver).FirefoxProfile().thenReturn(profile) expected_webdriver = mock() + capabilities = webdriver.DesiredCapabilities.FIREFOX.copy() when(webdriver).Remote(command_executor=url, - browser_profile=profile, - options=None).thenReturn(expected_webdriver) + browser_profile=profile, options=None, + desired_capabilities=capabilities).thenReturn(expected_webdriver) driver = self.creator.create_firefox({}, url, None) self.assertEqual(driver, expected_webdriver) + def test_firefox_remote_caps(self): + url = 'http://localhost:4444/wd/hub' + profile = mock() + when(webdriver).FirefoxProfile().thenReturn(profile) + expected_webdriver = mock() + capabilities = {"browserName": "firefox"} + when(webdriver).Remote(command_executor=url, + browser_profile=profile, options=None, + desired_capabilities=capabilities).thenReturn(expected_webdriver) + driver = self.creator.create_firefox({'desired_capabilities': capabilities}, url, None) + self.assertEqual(driver, expected_webdriver) + def test_firefox_profile(self): expected_webdriver = mock() profile = mock() @@ -181,7 +194,7 @@ def test_firefox_headless(self): driver = self.creator.create_headless_firefox({}, None, None) self.assertEqual(driver, expected_webdriver) - def test_firefox_healdless_with_grid(self): + def test_firefox_healdless_with_grid_caps(self): expected_webdriver = mock() options = mock() when(webdriver).FirefoxOptions().thenReturn(options) @@ -194,12 +207,22 @@ def test_firefox_healdless_with_grid(self): driver = self.creator.create_headless_firefox({'capabilities': {'key': 'value'}}, remote_url, None) verify(options).set_headless() self.assertEqual(driver, expected_webdriver) + verify(options).set_headless() + def test_firefox_healdless_with_grid_no_caps(self): + expected_webdriver = mock() + options = mock() + when(webdriver).FirefoxOptions().thenReturn(options) + profile = mock() + when(webdriver).FirefoxProfile().thenReturn(profile) + remote_url = 'localhost:4444' + capabilities = webdriver.DesiredCapabilities.FIREFOX.copy() when(webdriver).Remote(command_executor=remote_url, options=options, + desired_capabilities=capabilities, browser_profile=profile, ).thenReturn(expected_webdriver) driver = self.creator.create_headless_firefox({}, remote_url, None) self.assertEqual(driver, expected_webdriver) - verify(options, times=2).set_headless() + verify(options).set_headless() def test_ie(self): expected_webdriver = mock() From 55b45f0a9bb44a44973d6b80431ea1a45a7e996c Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Fri, 4 Jan 2019 22:15:34 +0200 Subject: [PATCH 3/8] Fixed remote_url and capabilites for IE --- src/SeleniumLibrary/keywords/webdrivertools.py | 3 +++ utest/test/keywords/test_webdrivercreator.py | 17 ++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/SeleniumLibrary/keywords/webdrivertools.py b/src/SeleniumLibrary/keywords/webdrivertools.py index 6aef27a07..db71f94d0 100644 --- a/src/SeleniumLibrary/keywords/webdrivertools.py +++ b/src/SeleniumLibrary/keywords/webdrivertools.py @@ -140,6 +140,9 @@ def create_headless_firefox(self, desired_capabilities, remote_url, def create_ie(self, desired_capabilities, remote_url): if is_truthy(remote_url): + if not desired_capabilities: + ie = webdriver.DesiredCapabilities.INTERNETEXPLORER.copy() + desired_capabilities = {'desired_capabilities': ie} return self._remote(desired_capabilities, remote_url) return webdriver.Ie(**desired_capabilities) diff --git a/utest/test/keywords/test_webdrivercreator.py b/utest/test/keywords/test_webdrivercreator.py index f659b83a8..b8ebad7d6 100644 --- a/utest/test/keywords/test_webdrivercreator.py +++ b/utest/test/keywords/test_webdrivercreator.py @@ -234,15 +234,26 @@ def test_ie(self): driver = self.creator.create_ie({'capabilities': {'key': 'value'}}, None) self.assertEqual(driver, expected_webdriver) - def test_ie_remote(self): + def test_ie_remote_no_caps(self): url = 'http://localhost:4444/wd/hub' expected_webdriver = mock() - when(webdriver).Remote(command_executor=url, - browser_profile=None, + capabilities = webdriver.DesiredCapabilities.INTERNETEXPLORER.copy() + when(webdriver).Remote(command_executor=url, browser_profile=None, + desired_capabilities=capabilities, options=None).thenReturn(expected_webdriver) driver = self.creator.create_ie({}, url) self.assertEqual(driver, expected_webdriver) + def test_ie_remote_caps(self): + url = 'http://localhost:4444/wd/hub' + expected_webdriver = mock() + capabilities = {"browserName": "internet explorer"} + when(webdriver).Remote(command_executor=url, browser_profile=None, + desired_capabilities=capabilities, + options=None).thenReturn(expected_webdriver) + driver = self.creator.create_ie({'capabilities': capabilities}, url) + self.assertEqual(driver, expected_webdriver) + def test_edge(self): expected_webdriver = mock() when(webdriver).Edge().thenReturn(expected_webdriver) From acfc3c544b0950e33a2a64db94221d47d2003716 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Fri, 4 Jan 2019 22:19:23 +0200 Subject: [PATCH 4/8] Fixed remote_url and capabilites for EDGE --- src/SeleniumLibrary/keywords/webdrivertools.py | 3 +++ utest/test/keywords/test_webdrivercreator.py | 18 +++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/SeleniumLibrary/keywords/webdrivertools.py b/src/SeleniumLibrary/keywords/webdrivertools.py index db71f94d0..095a393ee 100644 --- a/src/SeleniumLibrary/keywords/webdrivertools.py +++ b/src/SeleniumLibrary/keywords/webdrivertools.py @@ -148,6 +148,9 @@ def create_ie(self, desired_capabilities, remote_url): def create_edge(self, desired_capabilities, remote_url): if is_truthy(remote_url): + if not desired_capabilities: + edge = webdriver.DesiredCapabilities.EDGE.copy() + desired_capabilities = {'desired_capabilities': edge} return self._remote(desired_capabilities, remote_url) return webdriver.Edge(**desired_capabilities) diff --git a/utest/test/keywords/test_webdrivercreator.py b/utest/test/keywords/test_webdrivercreator.py index b8ebad7d6..8dced100f 100644 --- a/utest/test/keywords/test_webdrivercreator.py +++ b/utest/test/keywords/test_webdrivercreator.py @@ -260,15 +260,27 @@ def test_edge(self): driver = self.creator.create_edge({}, None) self.assertEqual(driver, expected_webdriver) - def test_edge_remote(self): + def test_edge_remote_no_caps(self): url = 'http://localhost:4444/wd/hub' expected_webdriver = mock() - when(webdriver).Remote(command_executor=url, - browser_profile=None, + capabilities = webdriver.DesiredCapabilities.EDGE.copy() + when(webdriver).Remote(command_executor=url, browser_profile=None, + desired_capabilities=capabilities, options=None).thenReturn(expected_webdriver) driver = self.creator.create_edge({}, url) self.assertEqual(driver, expected_webdriver) + def test_edge_remote_caps(self): + url = 'http://localhost:4444/wd/hub' + expected_webdriver = mock() + capabilities = {"browserName": "MicrosoftEdge"} + when(webdriver).Remote(command_executor=url, browser_profile=None, + desired_capabilities=capabilities, + options=None).thenReturn(expected_webdriver) + driver = self.creator.create_edge({'capabilities': capabilities}, url) + self.assertEqual(driver, expected_webdriver) + + def test_opera(self): expected_webdriver = mock() when(webdriver).Opera().thenReturn(expected_webdriver) From 5f88fb52d80365634dae0c5029970277c0c699fd Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Fri, 4 Jan 2019 22:23:39 +0200 Subject: [PATCH 5/8] Fixed remote_url and capabilites for opera --- src/SeleniumLibrary/keywords/webdrivertools.py | 3 +++ utest/test/keywords/test_webdrivercreator.py | 17 ++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/SeleniumLibrary/keywords/webdrivertools.py b/src/SeleniumLibrary/keywords/webdrivertools.py index 095a393ee..ff1c87dc1 100644 --- a/src/SeleniumLibrary/keywords/webdrivertools.py +++ b/src/SeleniumLibrary/keywords/webdrivertools.py @@ -156,6 +156,9 @@ def create_edge(self, desired_capabilities, remote_url): def create_opera(self, desired_capabilities, remote_url): if is_truthy(remote_url): + if not desired_capabilities: + opera = webdriver.DesiredCapabilities.OPERA.copy() + desired_capabilities = {'desired_capabilities': opera} return self._remote(desired_capabilities, remote_url) return webdriver.Opera(**desired_capabilities) diff --git a/utest/test/keywords/test_webdrivercreator.py b/utest/test/keywords/test_webdrivercreator.py index 8dced100f..d93402733 100644 --- a/utest/test/keywords/test_webdrivercreator.py +++ b/utest/test/keywords/test_webdrivercreator.py @@ -287,15 +287,26 @@ def test_opera(self): driver = self.creator.create_opera({}, None) self.assertEqual(driver, expected_webdriver) - def test_opera_remote(self): + def test_opera_remote_no_caps(self): url = 'http://localhost:4444/wd/hub' expected_webdriver = mock() - when(webdriver).Remote(command_executor=url, - browser_profile=None, + capabilities = webdriver.DesiredCapabilities.OPERA.copy() + when(webdriver).Remote(command_executor=url, browser_profile=None, + desired_capabilities=capabilities, options=None).thenReturn(expected_webdriver) driver = self.creator.create_opera({}, url) self.assertEqual(driver, expected_webdriver) + def test_opera_remote_caps(self): + url = 'http://localhost:4444/wd/hub' + expected_webdriver = mock() + capabilities = {"browserName": "opera"} + when(webdriver).Remote(command_executor=url, browser_profile=None, + desired_capabilities=capabilities, + options=None).thenReturn(expected_webdriver) + driver = self.creator.create_opera({'desired_capabilities': capabilities}, url) + self.assertEqual(driver, expected_webdriver) + def test_safari(self): expected_webdriver = mock() when(webdriver).Safari().thenReturn(expected_webdriver) From b926c88b203988bfef702412a1ed29dca3a6bff6 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Fri, 4 Jan 2019 22:26:31 +0200 Subject: [PATCH 6/8] Fixed remote_url and capabilites for safari --- src/SeleniumLibrary/keywords/webdrivertools.py | 3 +++ utest/test/keywords/test_webdrivercreator.py | 17 ++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/SeleniumLibrary/keywords/webdrivertools.py b/src/SeleniumLibrary/keywords/webdrivertools.py index ff1c87dc1..055f97421 100644 --- a/src/SeleniumLibrary/keywords/webdrivertools.py +++ b/src/SeleniumLibrary/keywords/webdrivertools.py @@ -164,6 +164,9 @@ def create_opera(self, desired_capabilities, remote_url): def create_safari(self, desired_capabilities, remote_url): if is_truthy(remote_url): + if not desired_capabilities: + caps = webdriver.DesiredCapabilities.SAFARI.copy() + desired_capabilities = {'desired_capabilities': caps} return self._remote(desired_capabilities, remote_url) return webdriver.Safari(**desired_capabilities) diff --git a/utest/test/keywords/test_webdrivercreator.py b/utest/test/keywords/test_webdrivercreator.py index d93402733..af60dad0b 100644 --- a/utest/test/keywords/test_webdrivercreator.py +++ b/utest/test/keywords/test_webdrivercreator.py @@ -313,15 +313,26 @@ def test_safari(self): driver = self.creator.create_safari({}, None) self.assertEqual(driver, expected_webdriver) - def test_safari_remote(self): + def test_safari_remote_no_caps(self): url = 'http://localhost:4444/wd/hub' expected_webdriver = mock() - when(webdriver).Remote(command_executor=url, - browser_profile=None, + capabilities = webdriver.DesiredCapabilities.SAFARI.copy() + when(webdriver).Remote(command_executor=url, browser_profile=None, + desired_capabilities=capabilities, options=None).thenReturn(expected_webdriver) driver = self.creator.create_safari({}, url) self.assertEqual(driver, expected_webdriver) + def test_safari_remote_caps(self): + url = 'http://localhost:4444/wd/hub' + expected_webdriver = mock() + capabilities = {"browserName": "safari"} + when(webdriver).Remote(command_executor=url, browser_profile=None, + desired_capabilities=capabilities, + options=None).thenReturn(expected_webdriver) + driver = self.creator.create_safari({'desired_capabilities': capabilities}, url) + self.assertEqual(driver, expected_webdriver) + def test_phantomjs(self): expected_webdriver = mock() when(webdriver).PhantomJS().thenReturn(expected_webdriver) From fbe3df6d512a424d9e2e654b92923edf4626cc5d Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Fri, 4 Jan 2019 22:30:16 +0200 Subject: [PATCH 7/8] Fixed remote_url and capabilites for phantomjs --- src/SeleniumLibrary/keywords/webdrivertools.py | 3 +++ utest/test/keywords/test_webdrivercreator.py | 17 ++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/SeleniumLibrary/keywords/webdrivertools.py b/src/SeleniumLibrary/keywords/webdrivertools.py index 055f97421..f20d075e4 100644 --- a/src/SeleniumLibrary/keywords/webdrivertools.py +++ b/src/SeleniumLibrary/keywords/webdrivertools.py @@ -174,6 +174,9 @@ def create_phantomjs(self, desired_capabilities, remote_url): warnings.warn('SeleniumLibrary support for PhantomJS has been deprecated, ' 'please use headlesschrome or headlessfirefox instead.') if is_truthy(remote_url): + if not desired_capabilities: + caps = webdriver.DesiredCapabilities.PHANTOMJS.copy() + desired_capabilities = {'desired_capabilities': caps} return self._remote(desired_capabilities, remote_url) return webdriver.PhantomJS(**desired_capabilities) diff --git a/utest/test/keywords/test_webdrivercreator.py b/utest/test/keywords/test_webdrivercreator.py index af60dad0b..e4be64ea5 100644 --- a/utest/test/keywords/test_webdrivercreator.py +++ b/utest/test/keywords/test_webdrivercreator.py @@ -339,15 +339,26 @@ def test_phantomjs(self): driver = self.creator.create_phantomjs({}, None) self.assertEqual(driver, expected_webdriver) - def test_phantomjs_remote(self): + def test_phantomjs_remote_no_caps(self): url = 'http://localhost:4444/wd/hub' expected_webdriver = mock() - when(webdriver).Remote(command_executor=url, - browser_profile=None, + capabilities = webdriver.DesiredCapabilities.PHANTOMJS.copy() + when(webdriver).Remote(command_executor=url, browser_profile=None, + desired_capabilities=capabilities, options=None).thenReturn(expected_webdriver) driver = self.creator.create_phantomjs({}, url) self.assertEqual(driver, expected_webdriver) + def test_phantomjs_remote_caps(self): + url = 'http://localhost:4444/wd/hub' + expected_webdriver = mock() + capabilities = {"browserName": "phantomjs"} + when(webdriver).Remote(command_executor=url, browser_profile=None, + desired_capabilities=capabilities, + options=None).thenReturn(expected_webdriver) + driver = self.creator.create_phantomjs({'desired_capabilities': capabilities}, url) + self.assertEqual(driver, expected_webdriver) + def test_htmlunit(self): caps = webdriver.DesiredCapabilities.HTMLUNIT expected_webdriver = mock() From f04bf517923aea5e6b42b914d743e18acf0838d4 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Fri, 4 Jan 2019 22:32:35 +0200 Subject: [PATCH 8/8] Fixed remote_url and capabilites for htmlunit --- utest/test/keywords/test_webdrivercreator.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/utest/test/keywords/test_webdrivercreator.py b/utest/test/keywords/test_webdrivercreator.py index e4be64ea5..1996c97f7 100644 --- a/utest/test/keywords/test_webdrivercreator.py +++ b/utest/test/keywords/test_webdrivercreator.py @@ -359,7 +359,7 @@ def test_phantomjs_remote_caps(self): driver = self.creator.create_phantomjs({'desired_capabilities': capabilities}, url) self.assertEqual(driver, expected_webdriver) - def test_htmlunit(self): + def test_htmlunit_no_caps(self): caps = webdriver.DesiredCapabilities.HTMLUNIT expected_webdriver = mock() when(webdriver).Remote(command_executor='None', @@ -369,6 +369,16 @@ def test_htmlunit(self): driver = self.creator.create_htmlunit({}, None) self.assertEqual(driver, expected_webdriver) + def test_htmlunit_no_caps(self): + caps = {"browserName": "htmlunit"} + expected_webdriver = mock() + when(webdriver).Remote(command_executor='None', + desired_capabilities=caps, + browser_profile=None, + options=None).thenReturn(expected_webdriver) + driver = self.creator.create_htmlunit({'desired_capabilities': caps}, None) + self.assertEqual(driver, expected_webdriver) + def test_htmlunit_with_js(self): caps = webdriver.DesiredCapabilities.HTMLUNITWITHJS expected_webdriver = mock()