Skip to content
Open
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
15 changes: 10 additions & 5 deletions src/SeleniumLibrary/keywords/browsermanagement.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
secs_to_timestr,
timestr_to_secs,
)
from SeleniumLibrary.utils.types import Secret

from .webdrivertools import WebDriverCreator

Expand Down Expand Up @@ -64,7 +65,7 @@ def close_browser(self):
@keyword
def open_browser(
self,
url: str | None = None,
url: str | Secret | None = None,
browser: str = "firefox",
alias: str | None = None,
remote_url: bool | str = False,
Expand Down Expand Up @@ -96,7 +97,10 @@ def open_browser(
project documentation] for more details.

After opening the browser, it is possible to use optional
``url`` to navigate the browser to the desired address.
``url`` to navigate the browser to the desired address. The ``url``
can also be a
[https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#secret-variables|Secret]
value, in which case the value is not shown in the logs.

Examples:
| `Open Browser` | http://example.com | Chrome | |
Expand Down Expand Up @@ -214,7 +218,7 @@ def open_browser(
self.info(f"Using existing browser from index {index}.")
self.switch_browser(alias)
if url:
self.go_to(url)
self.go_to(url.value if isinstance(url, Secret) else url)
return index
if desired_capabilities:
self.warn(
Expand Down Expand Up @@ -273,9 +277,10 @@ def _make_new_browser(
)
driver = self._wrap_event_firing_webdriver(driver)
index = self.ctx.register_driver(driver, alias)
if url:
url_value = url.value if isinstance(url, Secret) else url
if url_value:
try:
driver.get(url)
driver.get(url_value)
except Exception:
self.debug(
f"Opened browser with session id {driver.session_id} but failed to open url '{url}'."
Expand Down
14 changes: 14 additions & 0 deletions utest/test/keywords/test_browsermanagement.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from SeleniumLibrary import SeleniumLibrary
from SeleniumLibrary.keywords import BrowserManagementKeywords
from SeleniumLibrary.utils.types import Secret


def test_set_selenium_timeout_only_affects_open_browsers():
Expand Down Expand Up @@ -149,6 +150,19 @@ def test_open_browser_speed():
assert browser._speed == 5.0


def test_open_browser_with_secret_url():
ctx = mock()
ctx._drivers = mock()
ctx.event_firing_webdriver = None
ctx.speed = 0.0
browser = mock()
when(webdriver).Chrome(options=None, service=ANY).thenReturn(browser)
bm = BrowserManagementKeywords(ctx)
when(bm._webdriver_creator)._get_executable_path(ANY).thenReturn("chromedriver")
bm.open_browser(Secret("http://robotframework.org/"), "chrome")
verify(browser).get("http://robotframework.org/")


def test_create_webdriver_speed():
ctx = mock()
ctx._drivers = mock()
Expand Down
Loading