@@ -58,7 +58,7 @@ def close_browser(self):
58
58
@keyword
59
59
def open_browser (self , url , browser = 'firefox' , alias = None ,
60
60
remote_url = False , desired_capabilities = None ,
61
- ff_profile_dir = None , service_log_path = None ):
61
+ ff_profile_dir = None , options = None , service_log_path = None ):
62
62
"""Opens a new browser instance to the given ``url``.
63
63
64
64
The ``browser`` argument specifies which browser to use, and the
@@ -119,6 +119,71 @@ def open_browser(self, url, browser='firefox', alias=None,
119
119
``ff_profile_dir`` can also be instance of the
120
120
[https://seleniumhq.github.io/selenium/docs/api/py/webdriver_firefox/selenium.webdriver.firefox.firefox_profile.html?highlight=firefoxprofile#selenium.webdriver.firefox.firefox_profile.FirefoxProfile|selenium.webdriver.FirefoxProfile].
121
121
122
+ Optional ``options`` argument allows to define browser specific
123
+ Selenium options. Example for Chrome, the ``options`` argument
124
+ allows defining the following
125
+ [https://seleniumhq.github.io/selenium/docs/api/py/webdriver_chrome/selenium.webdriver.chrome.options.html#selenium.webdriver.chrome.options.Options|methods and attributes]
126
+ and for Firefox these
127
+ [https://seleniumhq.github.io/selenium/docs/api/py/webdriver_firefox/selenium.webdriver.firefox.options.html?highlight=firefox#selenium.webdriver.firefox.options.Options|methods and attributes]
128
+ are available. Please note that not all browsers supported by the
129
+ SeleniumLibrary have Selenium options available. Therefore please
130
+ consult the Selenium documentation which browsers do support
131
+ the Selenium options. If ``browser`` argument is `android` then
132
+ [https://seleniumhq.github.io/selenium/docs/api/py/webdriver_chrome/selenium.webdriver.chrome.options.html#selenium.webdriver.chrome.options.Options|Chrome options]
133
+ is used. Selenium options are also supported, when ``remote_url``
134
+ argument is used.
135
+
136
+ The SeleniumLibrary ``options`` argument accepts Selenium
137
+ options in two different formats: as a string and as Python object
138
+ which is an instance of the Selenium options class.
139
+
140
+ The string format allows to define Selenium options methods
141
+ or attributes and their arguments in Robot Framework test data.
142
+ The method and attributes names are case and space sensitive and
143
+ must match to the Selenium options methods and attributes names.
144
+ When defining a method, is must defined in similar way as in
145
+ python: method name, opening parenthesis, zero to many arguments
146
+ and closing parenthesis. If there is need to define multiple
147
+ arguments for a single method, arguments must be separated with
148
+ comma, just like in Python. Example: `add_argument("--headless")`
149
+ or `add_experimental_option("key", "value")`. Attributes are
150
+ defined in similar way as in Python: attribute name, equal sing
151
+ and attribute value. Example, `headless=True`. Multiple methods
152
+ and attributes must separated by a semicolon, example:
153
+ `add_argument("--headless");add_argument("--start-maximized")`.
154
+
155
+ Arguments allow defining Python data types and arguments are
156
+ evaluated by using Python
157
+ [https://docs.python.org/3/library/ast.html#ast.literal_eval|ast.literal_eval].
158
+ Strings must be quoted with single or double quotes, example "value"
159
+ or 'value'. It is also possible define other Python builtin
160
+ data types, example `True` or `None`, by not using quotes
161
+ around the arguments.
162
+
163
+ The string format is space friendly and usually spaces do not alter
164
+ the defining the methods or attributes. There are two exceptions.
165
+ In some Robot Framework test data formats, two or more spaces are
166
+ considered as cell separator and instead of defining a single
167
+ argument, two or more arguments may be defined. Spaces in string
168
+ arguments are not removed and are left as is. Example
169
+ `add_argument ( "--headless" )` is same as
170
+ `add_argument("--headless")`. But `add_argument(" --headless ")` is
171
+ not same same as `add_argument ( "--headless" )`, because
172
+ spaces inside of quotes are not removed.
173
+
174
+ As last format ``options`` argument also support receiving
175
+ the Selenium options as Python class instance. In this case, the
176
+ instance is used as is and the SeleniumLibrary will not convert
177
+ the instance to other formats.
178
+ For example, if the following code return value is saved to
179
+ `${options}` variable in the Robot Framework data:
180
+ | options = webdriver.ChromeOptions()
181
+ | options.add_argument('--disable-dev-shm-usage')
182
+ | return options
183
+
184
+ Then the `${options}` variable can be used as argument to
185
+ ``options``.
186
+
122
187
Optional ``service_log_path`` argument defines the name of the
123
188
file where to write the browser driver logs. If the
124
189
``service_log_path`` argument contain a marker ``{index}``, it
@@ -142,6 +207,13 @@ def open_browser(self, url, browser='firefox', alias=None,
142
207
| Should Be Equal | ${1_index} | ${4_index} | | | |
143
208
| Should Be Equal | ${2_index} | ${2} | | | |
144
209
210
+ Example when using
211
+ [https://seleniumhq.github.io/selenium/docs/api/py/webdriver_chrome/selenium.webdriver.chrome.options.html#selenium.webdriver.chrome.options.Options|Chrome options]
212
+ method:
213
+ | `Open Browser` | http://example.com | Chrome | options=add_argument("--disable-popup-blocking"); add_argument("--ignore-certificate-errors") | # Sting format |
214
+ | ${options} = | Get Options | | | # Selenium options instance |
215
+ | `Open Browser` | http://example.com | Chrome | options=${options 2} | |
216
+
145
217
If the provided configuration options are not enough, it is possible
146
218
to use `Create Webdriver` to customize browser initialization even
147
219
more.
@@ -150,10 +222,10 @@ def open_browser(self, url, browser='firefox', alias=None,
150
222
new in SeleniumLibrary 3.1.
151
223
152
224
Using ``alias`` to decide, is the new browser opened is new
153
- in SeleniumLibrary 4.0. Also the ``service_log_path `` is new
154
- in SeleniumLibrary 4.0. Support for ``ff_profile_dir`` accepting
155
- instance of the `selenium.webdriver.FirefoxProfile` is new in
156
- SeleniumLibrary 4.0.
225
+ in SeleniumLibrary 4.0. The ``options `` and ``service_log_path``
226
+ are new in SeleniumLibrary 4.0. Support for ``ff_profile_dir``
227
+ accepting instance of the `selenium.webdriver.FirefoxProfile`
228
+ is new in SeleniumLibrary 4.0.
157
229
"""
158
230
index = self .drivers .get_index (alias )
159
231
if index :
@@ -163,19 +235,19 @@ def open_browser(self, url, browser='firefox', alias=None,
163
235
return index
164
236
return self ._make_new_browser (url , browser , alias , remote_url ,
165
237
desired_capabilities , ff_profile_dir ,
166
- service_log_path )
238
+ options , service_log_path )
167
239
168
240
def _make_new_browser (self , url , browser = 'firefox' , alias = None ,
169
241
remote_url = False , desired_capabilities = None ,
170
- ff_profile_dir = None , service_log_path = None ):
242
+ ff_profile_dir = None , options = None , service_log_path = None ):
171
243
if is_truthy (remote_url ):
172
244
self .info ("Opening browser '%s' to base url '%s' through "
173
245
"remote server at '%s'." % (browser , url , remote_url ))
174
246
else :
175
247
self .info ("Opening browser '%s' to base url '%s'." % (browser , url ))
176
248
driver = self ._make_driver (browser , desired_capabilities ,
177
249
ff_profile_dir , remote_url ,
178
- service_log_path )
250
+ options , service_log_path )
179
251
driver = self ._wrap_event_firing_webdriver (driver )
180
252
try :
181
253
driver .get (url )
@@ -504,11 +576,11 @@ def set_browser_implicit_wait(self, value):
504
576
"""
505
577
self .driver .implicitly_wait (timestr_to_secs (value ))
506
578
507
- def _make_driver (self , browser , desired_capabilities = None ,
508
- profile_dir = None , remote = None , service_log_path = None ):
579
+ def _make_driver (self , browser , desired_capabilities = None , profile_dir = None ,
580
+ remote = None , options = None , service_log_path = None ):
509
581
driver = WebDriverCreator (self .log_dir ).create_driver (
510
- browser = browser , desired_capabilities = desired_capabilities ,
511
- remote_url = remote , profile_dir = profile_dir , service_log_path = service_log_path )
582
+ browser = browser , desired_capabilities = desired_capabilities , remote_url = remote ,
583
+ profile_dir = profile_dir , options = options , service_log_path = service_log_path )
512
584
driver .set_script_timeout (self .ctx .timeout )
513
585
driver .implicitly_wait (self .ctx .implicit_wait )
514
586
if self .ctx .speed :
0 commit comments