Skip to content

Commit

Permalink
Merge pull request #1879 from emanlove/open-browser-options-bug-#1877
Browse files Browse the repository at this point in the history
Open browser options bug #1877
  • Loading branch information
emanlove committed Jan 20, 2024
2 parents 4ba475b + 4ad50bb commit 483e365
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
1 change: 0 additions & 1 deletion atest/acceptance/keywords/elements.robot
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ Documentation Tests elements
Test Setup Go To Page "links.html"
Resource ../resource.robot
Library String
Library DebugLibrary

*** Test Cases ***
Get Many Elements
Expand Down
17 changes: 17 additions & 0 deletions atest/acceptance/multiple_browsers_options.robot
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,20 @@ Chrome Browser With Selenium Options Argument With Semicolon
... LOG 1:14 DEBUG GLOB: *["has;semicolon"*
Open Browser ${FRONT PAGE} ${BROWSER} remote_url=${REMOTE_URL}
... desired_capabilities=${DESIRED_CAPABILITIES} options=add_argument("has;semicolon")

Chrome Browser with Selenium Options Ending With Semicolon
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 Ending With A Few Semicolons
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 Containing Empty Option
Open Browser ${FRONT PAGE} ${BROWSER} remote_url=${REMOTE_URL}
... desired_capabilities=${DESIRED_CAPABILITIES} options=add_argument ( "--disable-dev-shm-usage" ) ; ; add_argument ( "--headless=new" )

Chrome Browser with Selenium Options With A Missing Semicolon
Run Keyword And Expect Error ValueError: Unable to parse option: "add_argument ( "--disable-dev-shm-usage" ) add_argument ( "--headless=new" )"
... Open Browser ${FRONT PAGE} ${BROWSER} remote_url=${REMOTE_URL}
... desired_capabilities=${DESIRED_CAPABILITIES} options=add_argument ( "--disable-dev-shm-usage" ) add_argument ( "--headless=new" )
12 changes: 9 additions & 3 deletions src/SeleniumLibrary/keywords/webdrivertools/webdrivertools.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,9 @@ def create(self, browser, options):
selenium_options = selenium_options()
for option in options:
for key in option:
if key == '' and option[key]==[]:
logger.warn('Empty selenium option found and ignored. Suggested you review options passed to `Open Browser` keyword')
continue
attr = getattr(selenium_options, key)
if callable(attr):
attr(*option[key])
Expand Down Expand Up @@ -566,9 +569,12 @@ def _split(self, options):
split_options = []
start_position = 0
tokens = generate_tokens(StringIO(options).readline)
for toknum, tokval, tokpos, _, _ in tokens:
if toknum == token.OP and tokval == ";":
for toktype, tokval, tokpos, _, _ in tokens:
if toktype == token.OP and tokval == ";":
split_options.append(options[start_position : tokpos[1]].strip())
start_position = tokpos[1] + 1
split_options.append(options[start_position:])
# Handles trailing semicolon
# !! Note: If multiline options allowed this splitter might fail !!
if toktype == token.NEWLINE and start_position != tokpos[1]:
split_options.append(options[start_position : tokpos[1]].strip())
return split_options
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ Selenium options string splitting
2) ['attribute=True']
3) ['attribute="semi;colons;middle"', 'other_attribute=True']
4) ['method("arg1;")', 'method(";arg2;")']
5) ['method ( " arg1 ")', ' method ( " arg2 " ) ']
5) ['method ( " arg1 ")', 'method ( " arg2 " )']

0 comments on commit 483e365

Please sign in to comment.