Skip to content

Commit 6e39522

Browse files
committed
Improved tests and documentation of backslash in Open Browser arguments
1 parent e76c8e1 commit 6e39522

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

src/SeleniumLibrary/keywords/browsermanagement.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ def open_browser(self, url=None, browser='firefox', alias=None,
125125
and attributes to define the profile using methods and attributes
126126
in the same way as with ``options`` argument. Example: It is possible
127127
to use FirefoxProfile `set_preference` to define different
128-
profile settings.
128+
profile settings. See ``options`` argument documentation in below
129+
how to handle backslash escaping.
129130
130131
Optional ``options`` argument allows defining browser specific
131132
Selenium options. Example for Chrome, the ``options`` argument
@@ -177,7 +178,16 @@ def open_browser(self, url=None, browser='firefox', alias=None,
177178
`add_argument ( "--headless" )` is same as
178179
`add_argument("--headless")`. But `add_argument(" --headless ")` is
179180
not same same as `add_argument ( "--headless" )`, because
180-
spaces inside of quotes are not removed.
181+
spaces inside of quotes are not removed. Please note that if
182+
options string contains backslash, example a Windows OS path,
183+
the backslash needs escaping both in Robot Framework data and
184+
in Python side. This means single backslash must be writen using
185+
four backslash characters. Example, Windows path:
186+
"C:\\path\\to\\profile" must be written as
187+
"C:\\\\\\\\path\\\\\\to\\\\\\\\profile". Another way to write
188+
backslash is use Python
189+
[https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals|raw strings]
190+
and example write: r"C:\\\\path\\\\to\\\\profile".
181191
182192
As last format, ``options`` argument also supports receiving
183193
the Selenium options as Python class instance. In this case, the
@@ -229,15 +239,16 @@ def open_browser(self, url=None, browser='firefox', alias=None,
229239
Example when using
230240
[https://seleniumhq.github.io/selenium/docs/api/py/webdriver_chrome/selenium.webdriver.chrome.options.html#selenium.webdriver.chrome.options.Options|Chrome options]
231241
method:
232-
| `Open Browser` | http://example.com | Chrome | options=add_argument("--disable-popup-blocking"); add_argument("--ignore-certificate-errors") | # Sting format |
233-
| ${options} = | Get Options | | | # Selenium options instance |
234-
| `Open Browser` | http://example.com | Chrome | options=${options} | |
235-
| `Open Browser` | None | Chrome | options=binary_location="/path/to/binary";add_argument("remote-debugging-port=port") | # Start Chomium-based application |
242+
| `Open Browser` | http://example.com | Chrome | options=add_argument("--disable-popup-blocking"); add_argument("--ignore-certificate-errors") | # Sting format. |
243+
| ${options} = | Get Options | | | # Selenium options instance. |
244+
| `Open Browser` | http://example.com | Chrome | options=${options} | |
245+
| `Open Browser` | None | Chrome | options=binary_location="/path/to/binary";add_argument("remote-debugging-port=port") | # Start Chomium-based application. |
246+
| `Open Browser` | None | Chrome | options=binary_location=r"C:\\\\path\\\\to\\\\binary" | # Windows OS path escaping. |
236247
237248
Example for FirefoxProfile
238-
| `Open Browser` | http://example.com | Firefox | ff_profile_dir=/path/to/profile | # Using profile from disk |
239-
| `Open Browser` | http://example.com | Firefox | ff_profile_dir=${FirefoxProfile_instance} | # Using instance of FirefoxProfile |
240-
| `Open Browser` | http://example.com | Firefox | ff_profile_dir=set_preference("key", "value");set_preference("other", "setting") | # Defining profile using FirefoxProfile mehtods |
249+
| `Open Browser` | http://example.com | Firefox | ff_profile_dir=/path/to/profile | # Using profile from disk. |
250+
| `Open Browser` | http://example.com | Firefox | ff_profile_dir=${FirefoxProfile_instance} | # Using instance of FirefoxProfile. |
251+
| `Open Browser` | http://example.com | Firefox | ff_profile_dir=set_preference("key", "value");set_preference("other", "setting") | # Defining profile using FirefoxProfile mehtods. |
241252
242253
If the provided configuration options are not enough, it is possible
243254
to use `Create Webdriver` to customize browser initialization even

0 commit comments

Comments
 (0)