@@ -56,10 +56,10 @@ def close_browser(self):
56
56
self .drivers .close ()
57
57
58
58
@keyword
59
- def open_browser (self , url , browser = 'firefox' , alias = None ,
59
+ def open_browser (self , url = None , browser = 'firefox' , alias = None ,
60
60
remote_url = False , desired_capabilities = None ,
61
61
ff_profile_dir = None , options = None , service_log_path = None ):
62
- """Opens a new browser instance to the given ``url``.
62
+ """Opens a new browser instance to the optional ``url``.
63
63
64
64
The ``browser`` argument specifies which browser to use. The
65
65
supported browsers are listed in the table below. The browser names
@@ -87,6 +87,9 @@ def open_browser(self, url, browser='firefox', alias=None,
87
87
Headless Chrome are new additions in SeleniumLibrary 3.1.0
88
88
and require Selenium 3.8.0 or newer.
89
89
90
+ After opening the browser, it is possible to use optional
91
+ ``url`` to navigate the browser to the desired address.
92
+
90
93
Optional ``alias`` is an alias given for this browser instance and
91
94
it can be used for switching between browsers. When same ``alias``
92
95
is given with two `Open Browser` keywords, the first keyword will
@@ -212,6 +215,7 @@ def open_browser(self, url, browser='firefox', alias=None,
212
215
| `Open Browser` | http://example.com | Firefox | alias=Firefox |
213
216
| `Open Browser` | http://example.com | Edge | remote_url=http://127.0.0.1:4444/wd/hub |
214
217
| `Open Browser` | about:blank | | |
218
+ | `Open Browser` | browser=Chrome | | |
215
219
216
220
Alias examples:
217
221
| ${1_index} = | `Open Browser` | http://example.com | Chrome | alias=Chrome | # Opens new browser because alias is new. |
@@ -248,18 +252,21 @@ def open_browser(self, url, browser='firefox', alias=None,
248
252
accepting an instance of the `selenium.webdriver.FirefoxProfile`
249
253
and support defining FirefoxProfile with methods and
250
254
attributes are new in SeleniumLibrary 4.0.
255
+
256
+ Making ``url`` optional is new in SeleniumLibrary 4.1.
251
257
"""
252
258
index = self .drivers .get_index (alias )
253
259
if index :
254
260
self .info ('Using existing browser from index %s.' % index )
255
261
self .switch_browser (alias )
256
- self .go_to (url )
262
+ if is_truthy (url ):
263
+ self .go_to (url )
257
264
return index
258
265
return self ._make_new_browser (url , browser , alias , remote_url ,
259
266
desired_capabilities , ff_profile_dir ,
260
267
options , service_log_path )
261
268
262
- def _make_new_browser (self , url , browser = 'firefox' , alias = None ,
269
+ def _make_new_browser (self , url = None , browser = 'firefox' , alias = None ,
263
270
remote_url = False , desired_capabilities = None ,
264
271
ff_profile_dir = None , options = None , service_log_path = None ):
265
272
if is_truthy (remote_url ):
@@ -272,12 +279,13 @@ def _make_new_browser(self, url, browser='firefox', alias=None,
272
279
options , service_log_path )
273
280
driver = self ._wrap_event_firing_webdriver (driver )
274
281
index = self .ctx .register_driver (driver , alias )
275
- try :
276
- driver .get (url )
277
- except Exception :
278
- self .debug ("Opened browser with session id %s but failed "
279
- "to open url '%s'." % (driver .session_id , url ))
280
- raise
282
+ if is_truthy (url ):
283
+ try :
284
+ driver .get (url )
285
+ except Exception :
286
+ self .debug ("Opened browser with session id %s but failed "
287
+ "to open url '%s'." % (driver .session_id , url ))
288
+ raise
281
289
self .debug ('Opened browser with session id %s.' % driver .session_id )
282
290
return index
283
291
0 commit comments