Skip to content

Commit

Permalink
Update exception logging for BootstrapSelect
Browse files Browse the repository at this point in the history
list the available selection items on exception for
NoSuchElementException
  • Loading branch information
mshriver committed Feb 6, 2018
1 parent 09843cd commit a93f681
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions src/widgetastic_patternfly/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@ class DropdownItemNotFound(Exception):
pass


class SelectItemNotFound(Exception):
def __init__(self, widget, item, options=None):
self.widget = widget
self.item = item
self.options = options

@property
def message(self):
return ('Could not find {!r} in {!r}\n'
'These options are present: {!r}'
.format(self.item, self.widget, ', '.join(self.options)))

def __str__(self):
return self.message


class Button(Widget, ClickableMixin):
"""A PatternFly/Bootstrap button
Expand Down Expand Up @@ -833,8 +849,8 @@ def select_by_visible_text(self, *items):
self.browser.click(
self.BY_PARTIAL_VISIBLE_TEXT.format(quote(item)))
except NoSuchElementException:
raise NoSuchElementException(
'Could not find {!r} in {!r} using partial match'.format(item, self))
raise SelectItemNotFound(widget=self, item=item,
options=[opt.text for opt in self.all_options])
else:
self.logger.info('selecting by visible text: %r', item)
try:
Expand All @@ -845,8 +861,8 @@ def select_by_visible_text(self, *items):
# button and doesn't have exact id or name
self.browser.click(self.BY_VISIBLE_TEXT.format(quote(item)))
except NoSuchElementException:
raise NoSuchElementException(
'Could not find {!r} in {!r}'.format(item, self))
raise SelectItemNotFound(widget=self, item=item,
options=[opt.text for opt in self.all_options])
self.close()

@property
Expand Down Expand Up @@ -1514,7 +1530,9 @@ def item_select(self, item, handle_alert=None):
self.open()
if not self.item_enabled(item):
raise DropdownItemDisabled(
'Item "{}" of dropdown "{}" is disabled'.format(item, self.text))
'Item "{}" of dropdown "{}" is disabled\n'
'The following items are available: {}'
.format(item, self.text, ';'.join(self.items)))
self.browser.click(self.item_element(item), ignore_ajax=handle_alert is not None)
if handle_alert is not None:
self.browser.handle_alert(cancel=not handle_alert, wait=10.0)
Expand Down

0 comments on commit a93f681

Please sign in to comment.