Adapte errors on click-element to filter.
This commit is contained in:
parent
39dbf2266f
commit
d1bc60edb8
|
|
@ -234,6 +234,14 @@ def _wrap_find_at_pos(value: str, tab: apitypes.Tab,
|
|||
tab.elements.find_at_pos(point, callback)
|
||||
|
||||
|
||||
_FILTER_ERRORS = {
|
||||
'id': lambda x: f'with ID "{x}"',
|
||||
'css': lambda x: f'matching CSS selector "{x}"',
|
||||
'focused': lambda _: 'with focus',
|
||||
'position': lambda x: 'at position {x}',
|
||||
}
|
||||
|
||||
|
||||
@cmdutils.register()
|
||||
@cmdutils.argument('tab', value=cmdutils.Value.cur_tab)
|
||||
@cmdutils.argument('filter_', choices=['id', 'css', 'position', 'focused'])
|
||||
|
|
@ -269,18 +277,18 @@ def click_element(tab: apitypes.Tab, filter_: str, value: str = None, *,
|
|||
def single_cb(elem: Optional[apitypes.WebElement]) -> None:
|
||||
"""Click a single element."""
|
||||
if elem is None:
|
||||
message.error(f"No element found matching {filter_}={value}!")
|
||||
message.error(f"No element found {_FILTER_ERRORS[filter_](value)}!")
|
||||
return
|
||||
|
||||
do_click(elem)
|
||||
|
||||
def multiple_cb(elems: List[apitypes.WebElement]) -> None:
|
||||
if not elems:
|
||||
message.error(f"No element found matching {filter_}={value}!")
|
||||
message.error(f"No element found {_FILTER_ERRORS[filter_](value)}!")
|
||||
return
|
||||
|
||||
if not select_first and len(elems) > 1:
|
||||
message.error(f"Multiple elements found matching {filter_}={value}!")
|
||||
message.error(f"Multiple elements found {_FILTER_ERRORS[filter_](value)}!")
|
||||
return
|
||||
|
||||
do_click(elems[0])
|
||||
|
|
|
|||
|
|
@ -436,7 +436,7 @@ Feature: Various utility commands.
|
|||
Scenario: Clicking an element with unknown ID
|
||||
When I open data/click_element.html
|
||||
And I run :click-element id blah
|
||||
Then the error "No element found matching id=blah!" should be shown
|
||||
Then the error "No element found with ID "blah"!" should be shown
|
||||
|
||||
Scenario: Clicking an element by ID
|
||||
When I open data/click_element.html
|
||||
|
|
@ -465,7 +465,7 @@ Feature: Various utility commands.
|
|||
Scenario: Clicking an element with non-unique filter
|
||||
When I open data/click_element.html
|
||||
And I run :click-element css span
|
||||
Then the error "Multiple elements found matching css=span!" should be shown
|
||||
Then the error "Multiple elements found matching CSS selector "span"!" should be shown
|
||||
|
||||
Scenario: Clicking first element matching a selector
|
||||
When I open data/click_element.html
|
||||
|
|
@ -493,7 +493,7 @@ Feature: Various utility commands.
|
|||
And I run :click-element position 20,42
|
||||
And I wait for the javascript message "click_element position"
|
||||
And I run :click-element focused
|
||||
Then the error "No element found matching focused=None!" should be shown
|
||||
Then the error "No element found with focus!" should be shown
|
||||
|
||||
Scenario: Clicking on focused element
|
||||
When I open data/click_element.html
|
||||
|
|
|
|||
Loading…
Reference in New Issue