Skip to content

Commit

Permalink
Merge pull request #1854 from emanlove/fix-remote-options-edge-safari…
Browse files Browse the repository at this point in the history
…-1844

Fix remote options edge safari 1844
  • Loading branch information
emanlove authored Aug 25, 2023
2 parents f3643ef + 2b0aace commit 4003462
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 368 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ ${event_firing_or_none} ${NONE}
Open Browser To Start Page
[Tags] NoGrid
[Documentation]
... LOG 1:37 DEBUG Wrapping driver to event_firing_webdriver.
... LOG 1:39 INFO Got driver also from SeleniumLibrary.
... LOG 1:20 DEBUG Wrapping driver to event_firing_webdriver.
... LOG 1:22 INFO Got driver also from SeleniumLibrary.
Open Browser ${FRONT PAGE} ${BROWSER} remote_url=${REMOTE_URL}
... desired_capabilities=${DESIRED_CAPABILITIES}

Expand Down
5 changes: 2 additions & 3 deletions atest/acceptance/create_webdriver.robot
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Library Collections
Create Webdriver Creates Functioning WebDriver
[Documentation]
... LOG 1:1 INFO REGEXP: Creating an instance of the \\w+ WebDriver.
... LOG 1:25 DEBUG REGEXP: Created \\w+ WebDriver instance with session id (\\w|-)+.
... LOG 1:8 DEBUG REGEXP: Created \\w+ WebDriver instance with session id (\\w|-)+.
[Tags] Known Issue Internet Explorer Known Issue Safari
[Setup] Set Driver Variables
Create Webdriver ${DRIVER_NAME} kwargs=${KWARGS}
Expand Down Expand Up @@ -42,8 +42,7 @@ Set Driver Variables
Set Test Variable ${DRIVER_NAME} ${name}
${dc names}= Create Dictionary ff=FIREFOX firefox=FIREFOX ie=INTERNETEXPLORER
... internetexplorer=INTERNETEXPLORER googlechrome=CHROME gc=CHROME
... chrome=CHROME htmlunit=HTMLUNIT htmlunitwithjs=HTMLUNITWITHJS
... safari=SAFARI headlessfirefox=FIREFOX headlesschrome=CHROME
... chrome=CHROME safari=SAFARI headlessfirefox=FIREFOX headlesschrome=CHROME
${dc name}= Get From Dictionary ${dc names} ${BROWSER.lower().replace(' ', '')}
${caps}= Evaluate selenium.webdriver.DesiredCapabilities.${dc name}
... modules=selenium, selenium.webdriver
Expand Down
1 change: 1 addition & 0 deletions atest/acceptance/keywords/location.robot
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ Wait Until Location Is Not Fails With Timeout

Wait Until Location Is Not Fails With Message
[Setup] Go To Page "javascript/wait_location.html"
Sleep 1s # Make sure you don't check too soon
${orig_timeout}= Set Selenium Timeout 2 s
Run Keyword And Expect Error
... my_message
Expand Down
4 changes: 2 additions & 2 deletions atest/acceptance/keywords/page_load_timeout.robot
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ Test Teardown Close Browser And Reset Page Load Timeout
*** Test Cases ***
Should Open Browser With Default Page Load Timeout
[Documentation] Verify that 'Open Browser' changes the page load timeout.
... LOG 1.1.1:33 DEBUG REGEXP: POST http://localhost:\\d{2,5}/session/[a-f0-9-]+/timeouts {"pageLoad": 300000}
... LOG 1.1.1:35 DEBUG STARTS: Remote response: status=200
... LOG 1.1.1:16 DEBUG REGEXP: POST http://localhost:\\d{2,5}/session/[a-f0-9-]+/timeouts {"pageLoad": 300000}
... LOG 1.1.1:18 DEBUG STARTS: Remote response: status=200
Open Browser To Start Page

Should Run Into Timeout Exception
Expand Down
8 changes: 4 additions & 4 deletions atest/acceptance/keywords/screenshots_embed.robot
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ Capture Page Screenshot Override EMBED
[Setup] Remove .png Files
Set Screenshot Directory EMBED
${file}= Capture Page Screenshot override-embed-screenshot.png
Should Be Equal ${file} ${OUTPUTDIR}/override-embed-screenshot.png
File Should Exist ${OUTPUTDIR}/override-embed-screenshot.png
File Should Not Exist ${EXECDIR}/*.png
File Should Not Exist ${EXECDIR}/EMBED/*.png
Should Be Equal ${file} ${OUTPUTDIR}${/}override-embed-screenshot.png
File Should Exist ${OUTPUTDIR}${/}override-embed-screenshot.png
File Should Not Exist ${EXECDIR}${/}*.png
File Should Not Exist ${EXECDIR}${/}EMBED${/}*.png

*** Keywords ***
Remove .png Files
Expand Down
24 changes: 12 additions & 12 deletions atest/acceptance/multiple_browsers_options.robot
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,32 @@ Documentation Creating test which would work on all browser is not possible.
*** Test Cases ***
Chrome Browser With Selenium Options As String
[Documentation]
... LOG 1:20 DEBUG GLOB: *"goog:chromeOptions"*
... LOG 1:20 DEBUG GLOB: *args": ["--disable-dev-shm-usage"?*
... LOG 1:3 DEBUG GLOB: *"goog:chromeOptions"*
... LOG 1:3 DEBUG GLOB: *args": ["--disable-dev-shm-usage"?*
Open Browser ${FRONT PAGE} ${BROWSER} remote_url=${REMOTE_URL}
... desired_capabilities=${DESIRED_CAPABILITIES} options=add_argument("--disable-dev-shm-usage")

Chrome Browser With Selenium Options As String With Attirbute As True
[Documentation]
... LOG 1:20 DEBUG GLOB: *"goog:chromeOptions"*
... LOG 1:20 DEBUG GLOB: *args": ["--disable-dev-shm-usage"?*
... LOG 1:20 DEBUG GLOB: *"--headless"*
... LOG 1:3 DEBUG GLOB: *"goog:chromeOptions"*
... LOG 1:3 DEBUG GLOB: *args": ["--disable-dev-shm-usage"?*
... LOG 1:3 DEBUG GLOB: *"--headless"*
Open Browser ${FRONT PAGE} ${BROWSER} remote_url=${REMOTE_URL}
... desired_capabilities=${DESIRED_CAPABILITIES} options=add_argument ( "--disable-dev-shm-usage" ) ; headless = True

Chrome Browser With Selenium Options With Complex Object
[Tags] NoGrid
[Documentation]
... LOG 1:20 DEBUG GLOB: *"goog:chromeOptions"*
... LOG 1:20 DEBUG GLOB: *"mobileEmulation": {"deviceName": "Galaxy S5"*
... LOG 1:20 DEBUG GLOB: *args": ["--disable-dev-shm-usage"?*
... LOG 1:3 DEBUG GLOB: *"goog:chromeOptions"*
... LOG 1:3 DEBUG GLOB: *"mobileEmulation": {"deviceName": "Galaxy S5"*
... LOG 1:3 DEBUG GLOB: *args": ["--disable-dev-shm-usage"?*
Open Browser ${FRONT PAGE} ${BROWSER} remote_url=${REMOTE_URL}
... desired_capabilities=${DESIRED_CAPABILITIES} options=add_argument ( "--disable-dev-shm-usage" ) ; add_experimental_option( "mobileEmulation" , { 'deviceName' : 'Galaxy S5'})

Chrome Browser With Selenium Options Object
[Documentation]
... LOG 2:20 DEBUG GLOB: *"goog:chromeOptions"*
... LOG 2:20 DEBUG GLOB: *args": ["--disable-dev-shm-usage"?*
... LOG 2:3 DEBUG GLOB: *"goog:chromeOptions"*
... LOG 2:3 DEBUG GLOB: *args": ["--disable-dev-shm-usage"?*
${options} = Get Chrome Options
Open Browser ${FRONT PAGE} ${BROWSER} remote_url=${REMOTE_URL}
... desired_capabilities=${DESIRED_CAPABILITIES} options=${options}
Expand All @@ -47,7 +47,7 @@ Chrome Browser With Selenium Options Invalid Method

Chrome Browser With Selenium Options Argument With Semicolon
[Documentation]
... LOG 1:20 DEBUG GLOB: *"goog:chromeOptions"*
... LOG 1:20 DEBUG GLOB: *["has;semicolon"*
... LOG 1:3 DEBUG GLOB: *"goog:chromeOptions"*
... LOG 1:3 DEBUG GLOB: *["has;semicolon"*
Open Browser ${FRONT PAGE} ${BROWSER} remote_url=${REMOTE_URL}
... desired_capabilities=${DESIRED_CAPABILITIES} options=add_argument("has;semicolon")
4 changes: 2 additions & 2 deletions atest/acceptance/open_and_close.robot
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ Close Browser Does Nothing When No Browser Is Opened

Browser Open With Not Well-Formed URL Should Close
[Documentation] Verify after incomplete 'Open Browser' browser closes
... LOG 1.1:41 DEBUG STARTS: Opened browser with session id
... LOG 1.1:41 DEBUG REGEXP: .*but failed to open url.*
... LOG 1.1:24 DEBUG STARTS: Opened browser with session id
... LOG 1.1:24 DEBUG REGEXP: .*but failed to open url.*
... LOG 2:2 DEBUG STARTS: DELETE
... LOG 2:5 DEBUG STARTS: Finished Request
Run Keyword And Expect Error * Open Browser bad.url.bad ${BROWSER}
Expand Down
11 changes: 1 addition & 10 deletions src/SeleniumLibrary/keywords/browsermanagement.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@ def open_browser(
| Internet Explorer | internetexplorer, ie |
| Edge | edge |
| Safari | safari |
| Iphone | iphone |
| PhantomJS | phantomjs |
| HTMLUnit | htmlunit |
| HTMLUnit with Javascript | htmlunitwithjs |
To be able to actually use one of these browsers, you need to have
a matching Selenium browser driver available. See the
Expand Down Expand Up @@ -140,9 +136,7 @@ def open_browser(
are available. Please note that not all browsers, supported by the
SeleniumLibrary, have Selenium options available. Therefore please
consult the Selenium documentation which browsers do support
the Selenium options. If ``browser`` argument is `android` then
[https://seleniumhq.github.io/selenium/docs/api/py/webdriver_chrome/selenium.webdriver.chrome.options.html#selenium.webdriver.chrome.options.Options|Chrome options]
is used. Selenium options are also supported, when ``remote_url``
the Selenium options. Selenium options are also supported, when ``remote_url``
argument is used.
The SeleniumLibrary ``options`` argument accepts Selenium
Expand Down Expand Up @@ -362,9 +356,6 @@ def create_webdriver(
| ${proxy}= | `Evaluate` | selenium.webdriver.Proxy() | modules=selenium, selenium.webdriver |
| ${proxy.http_proxy}= | `Set Variable` | localhost:8888 | |
| `Create Webdriver` | Firefox | proxy=${proxy} | |
| # Use proxy with PhantomJS | | | |
| ${service args}= | `Create List` | --proxy=192.168.132.104:8888 | |
| `Create Webdriver` | PhantomJS | service_args=${service args} | |
Returns the index of this browser instance which can be used later to
switch back to it. Index starts from 1 and is reset back to it when
Expand Down
111 changes: 2 additions & 109 deletions src/SeleniumLibrary/keywords/webdrivertools/webdrivertools.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ class WebDriverCreator:
"internetexplorer": "ie",
"edge": "edge",
"safari": "safari",
"phantomjs": "phantomjs",
"htmlunit": "htmlunit",
"htmlunitwithjs": "htmlunit_with_js",
"android": "android",
"iphone": "iphone",
}

def __init__(self, log_dir):
Expand Down Expand Up @@ -307,7 +302,7 @@ def create_edge(
desired_capabilities = self._remote_capabilities_resolver(
desired_capabilities, defaul_caps
)
return self._remote(desired_capabilities, remote_url)
return self._remote(desired_capabilities, remote_url, options=options)
if not executable_path:
executable_path = self._get_executable_path(webdriver.edge.service.Service)
service = EdgeService(executable_path=executable_path, log_path=service_log_path)
Expand All @@ -330,112 +325,12 @@ def create_safari(
desired_capabilities = self._remote_capabilities_resolver(
desired_capabilities, defaul_caps
)
return self._remote(desired_capabilities, remote_url)
return self._remote(desired_capabilities, remote_url, options=options)
if not executable_path:
executable_path = self._get_executable_path(webdriver.Safari)
service = SafariService(executable_path=executable_path, log_path=service_log_path)
return webdriver.Safari(options=options, service=service)

def create_phantomjs(
self,
desired_capabilities,
remote_url,
options=None,
service_log_path=None,
executable_path="phantomjs",
):
warnings.warn(
"SeleniumLibrary support for PhantomJS has been deprecated, "
"please use headlesschrome or headlessfirefox instead."
)
if remote_url:
defaul_caps = webdriver.DesiredCapabilities.PHANTOMJS.copy()
desired_capabilities = self._remote_capabilities_resolver(
desired_capabilities, defaul_caps
)
return self._remote(desired_capabilities, remote_url)
if options:
logger.warn("PhantomJS browser does not support Selenium options.")
if not executable_path:
executable_path = self._get_executable_path(webdriver.PhantomJS)
return webdriver.PhantomJS(
service_log_path=service_log_path,
executable_path=executable_path,
**desired_capabilities,
)

def create_htmlunit(
self,
desired_capabilities,
remote_url,
options=None,
service_log_path=None,
executable_path=None,
):
if service_log_path or options or executable_path:
logger.warn(
"Htmlunit does not support Selenium options, service_log_path or executable_path argument."
)
defaul_caps = webdriver.DesiredCapabilities.HTMLUNIT.copy()
desired_capabilities = self._remote_capabilities_resolver(
desired_capabilities, defaul_caps
)
return self._remote(desired_capabilities, remote_url, options=options)

def create_htmlunit_with_js(
self,
desired_capabilities,
remote_url,
options=None,
service_log_path=None,
executable_path=None,
):
if service_log_path or options or executable_path:
logger.warn(
"Htmlunit with JS does not support Selenium options, service_log_path or executable_path argument."
)
defaul_caps = webdriver.DesiredCapabilities.HTMLUNITWITHJS.copy()
desired_capabilities = self._remote_capabilities_resolver(
desired_capabilities, defaul_caps
)
return self._remote(desired_capabilities, remote_url, options=options)

def create_android(
self,
desired_capabilities,
remote_url,
options=None,
service_log_path=None,
executable_path=None,
):
if service_log_path or executable_path:
logger.warn(
"Android does not support Selenium options or executable_path argument."
)
defaul_caps = webdriver.DesiredCapabilities.ANDROID.copy()
desired_capabilities = self._remote_capabilities_resolver(
desired_capabilities, defaul_caps
)
return self._remote(desired_capabilities, remote_url, options=options)

def create_iphone(
self,
desired_capabilities,
remote_url,
options=None,
service_log_path=None,
executable_path=None,
):
if service_log_path or executable_path:
logger.warn(
"iPhone does not support service_log_path or executable_path argument."
)
defaul_caps = webdriver.DesiredCapabilities.IPHONE.copy()
desired_capabilities = self._remote_capabilities_resolver(
desired_capabilities, defaul_caps
)
return self._remote(desired_capabilities, remote_url, options=options)

def _remote(self, desired_capabilities, remote_url, profile_dir=None, options=None):
remote_url = str(remote_url)
file_detector = self._get_sl_file_detector()
Expand Down Expand Up @@ -620,8 +515,6 @@ def create(self, browser, options):
return selenium_options

def _import_options(self, browser):
if browser == "android":
browser = "chrome" # Android uses ChromeOptions()
browser = browser.replace("headless_", "", 1)
options = importlib.import_module(f"selenium.webdriver.{browser}.options")
return options.Options
Expand Down
Loading

0 comments on commit 4003462

Please sign in to comment.