Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open browser options bug #1877 #1879

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 " )']