Skip to content

Commit 483e365

Browse files
authored
Merge pull request #1879 from emanlove/open-browser-options-bug-#1877
Open browser options bug #1877
2 parents 4ba475b + 4ad50bb commit 483e365

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

atest/acceptance/keywords/elements.robot

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ Documentation Tests elements
33
Test Setup Go To Page "links.html"
44
Resource ../resource.robot
55
Library String
6-
Library DebugLibrary
76

87
*** Test Cases ***
98
Get Many Elements

atest/acceptance/multiple_browsers_options.robot

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,20 @@ Chrome Browser With Selenium Options Argument With Semicolon
5151
... LOG 1:14 DEBUG GLOB: *["has;semicolon"*
5252
Open Browser ${FRONT PAGE} ${BROWSER} remote_url=${REMOTE_URL}
5353
... desired_capabilities=${DESIRED_CAPABILITIES} options=add_argument("has;semicolon")
54+
55+
Chrome Browser with Selenium Options Ending With Semicolon
56+
Open Browser ${FRONT PAGE} ${BROWSER} remote_url=${REMOTE_URL}
57+
... desired_capabilities=${DESIRED_CAPABILITIES} options=add_argument("--disable-dev-shm-usage") ;
58+
59+
Chrome Browser with Selenium Options Ending With A Few Semicolons
60+
Open Browser ${FRONT PAGE} ${BROWSER} remote_url=${REMOTE_URL}
61+
... desired_capabilities=${DESIRED_CAPABILITIES} options=add_argument("--disable-dev-shm-usage") ; ; ;
62+
63+
Chrome Browser with Selenium Options Containing Empty Option
64+
Open Browser ${FRONT PAGE} ${BROWSER} remote_url=${REMOTE_URL}
65+
... desired_capabilities=${DESIRED_CAPABILITIES} options=add_argument ( "--disable-dev-shm-usage" ) ; ; add_argument ( "--headless=new" )
66+
67+
Chrome Browser with Selenium Options With A Missing Semicolon
68+
Run Keyword And Expect Error ValueError: Unable to parse option: "add_argument ( "--disable-dev-shm-usage" ) add_argument ( "--headless=new" )"
69+
... Open Browser ${FRONT PAGE} ${BROWSER} remote_url=${REMOTE_URL}
70+
... desired_capabilities=${DESIRED_CAPABILITIES} options=add_argument ( "--disable-dev-shm-usage" ) add_argument ( "--headless=new" )

src/SeleniumLibrary/keywords/webdrivertools/webdrivertools.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,9 @@ def create(self, browser, options):
503503
selenium_options = selenium_options()
504504
for option in options:
505505
for key in option:
506+
if key == '' and option[key]==[]:
507+
logger.warn('Empty selenium option found and ignored. Suggested you review options passed to `Open Browser` keyword')
508+
continue
506509
attr = getattr(selenium_options, key)
507510
if callable(attr):
508511
attr(*option[key])
@@ -566,9 +569,12 @@ def _split(self, options):
566569
split_options = []
567570
start_position = 0
568571
tokens = generate_tokens(StringIO(options).readline)
569-
for toknum, tokval, tokpos, _, _ in tokens:
570-
if toknum == token.OP and tokval == ";":
572+
for toktype, tokval, tokpos, _, _ in tokens:
573+
if toktype == token.OP and tokval == ";":
571574
split_options.append(options[start_position : tokpos[1]].strip())
572575
start_position = tokpos[1] + 1
573-
split_options.append(options[start_position:])
576+
# Handles trailing semicolon
577+
# !! Note: If multiline options allowed this splitter might fail !!
578+
if toktype == token.NEWLINE and start_position != tokpos[1]:
579+
split_options.append(options[start_position : tokpos[1]].strip())
574580
return split_options

utest/test/keywords/approved_files/test_selenium_options_parser.test_split_options.approved.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ Selenium options string splitting
55
2) ['attribute=True']
66
3) ['attribute="semi;colons;middle"', 'other_attribute=True']
77
4) ['method("arg1;")', 'method(";arg2;")']
8-
5) ['method ( " arg1 ")', ' method ( " arg2 " ) ']
8+
5) ['method ( " arg1 ")', 'method ( " arg2 " )']

0 commit comments

Comments
 (0)