Skip to content

Commit 61bbacf

Browse files
rubygeekaaltat
authored andcommitted
added optional message param to the Title Should Be function (#1044)
Added optional message param to the Title Should Be function
1 parent c5bc69f commit 61bbacf

3 files changed

Lines changed: 20 additions & 5 deletions

File tree

CHANGES.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Release Notes
22
=============
33

4+
3.1.0
5+
-----
6+
- Added a message param to `Title Should Be` to display custom error message [rubygeek]
7+
48
3.0.0
59
-----
610
- Added 'Get Locations' keyword [thaffenden]

src/SeleniumLibrary/keywords/browsermanagement.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
from SeleniumLibrary.base import keyword, LibraryComponent
2525
from SeleniumLibrary.locators import WindowManager
26-
from SeleniumLibrary.utils import (is_falsy, is_truthy, secs_to_timestr,
26+
from SeleniumLibrary.utils import (is_falsy, is_truthy, is_noney, secs_to_timestr,
2727
timestr_to_secs, SELENIUM_VERSION)
2828

2929

@@ -303,12 +303,19 @@ def log_title(self):
303303
return title
304304

305305
@keyword
306-
def title_should_be(self, title):
307-
"""Verifies that current page title equals ``title``."""
306+
def title_should_be(self, title, message=None):
307+
"""Verifies that current page title equals ``title``.
308+
309+
The ``message`` argument can be used to override the default error
310+
message.
311+
312+
``message`` argument is new in SeleniumLibrary 3.1.
313+
"""
308314
actual = self.get_title()
309315
if actual != title:
310-
raise AssertionError("Title should have been '%s' but was '%s'."
311-
% (title, actual))
316+
if is_noney(message):
317+
message = "Title should have been '%s' but was '%s'." % (title, actual)
318+
raise AssertionError(message)
312319
self.info("Page title is '%s'." % title)
313320

314321
@keyword

test/acceptance/keywords/content_assertions.robot

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ Title Should Be
2525
Run Keyword And Expect Error
2626
... Title should have been 'not a title' but was '(root)/index.html'.
2727
... Title Should Be not a title
28+
Run Keyword And Expect Error
29+
... Page title was not expected
30+
... Title Should Be not a title message=Page title was not expected
31+
2832

2933
Page Should Contain
3034
[Documentation] LOG 2:5 Current page contains text 'needle'.

0 commit comments

Comments
 (0)