Get rid of WebElement.debug_text
This commit is contained in:
parent
6635c71849
commit
60c86a08c4
@ -75,8 +75,7 @@ def _find_prevnext(prev, elems):
|
||||
if e.tag_name() != 'link' or 'rel' not in e:
|
||||
continue
|
||||
if e['rel'] in rel_values:
|
||||
log.hints.debug("Found '{}' with rel={}".format(
|
||||
e.debug_text(), e['rel']))
|
||||
log.hints.debug("Found {!r} with rel={}".format(e, e['rel']))
|
||||
return e
|
||||
|
||||
# Then check for regular links/buttons.
|
||||
|
@ -106,7 +106,7 @@ class AbstractWebElement(collections.abc.MutableMapping):
|
||||
|
||||
def __repr__(self):
|
||||
try:
|
||||
html = self.debug_text()
|
||||
html = utils.compact_text(self.outer_xml(), 500)
|
||||
except Error:
|
||||
html = None
|
||||
return utils.get_repr(self, html=html)
|
||||
@ -310,10 +310,6 @@ class AbstractWebElement(collections.abc.MutableMapping):
|
||||
break
|
||||
elem = elem.parent()
|
||||
|
||||
def debug_text(self):
|
||||
"""Get a text based on an element suitable for debug output."""
|
||||
return utils.compact_text(self.outer_xml(), 500)
|
||||
|
||||
def resolve_url(self, baseurl):
|
||||
"""Resolve the URL in the element's src/href attribute.
|
||||
|
||||
@ -365,9 +361,8 @@ class AbstractWebElement(collections.abc.MutableMapping):
|
||||
|
||||
pos = self._mouse_pos()
|
||||
|
||||
log.hints.debug("Sending fake click to '{}' at position {} with "
|
||||
"target {}".format(self.debug_text(), pos,
|
||||
click_target))
|
||||
log.hints.debug("Sending fake click to {!r} at position {} with "
|
||||
"target {}".format(self, pos, click_target))
|
||||
|
||||
if click_target in [usertypes.ClickTarget.tab,
|
||||
usertypes.ClickTarget.tab_bg,
|
||||
|
@ -126,12 +126,10 @@ class WebKitElement(webelem.AbstractWebElement):
|
||||
def set_text(self, text, *, use_js=False):
|
||||
self._check_vanished()
|
||||
if self.is_content_editable() or not use_js:
|
||||
log.misc.debug("Filling element {} via set_text.".format(
|
||||
self.debug_text()))
|
||||
log.misc.debug("Filling {!r} via set_text.".format(self))
|
||||
self._elem.setPlainText(text)
|
||||
else:
|
||||
log.misc.debug("Filling element {} via javascript.".format(
|
||||
self.debug_text()))
|
||||
log.misc.debug("Filling {!r} via javascript.".format(self))
|
||||
text = javascript.string_escape(text)
|
||||
self._elem.evaluateJavaScript("this.value='{}'".format(text))
|
||||
|
||||
|
@ -266,7 +266,6 @@ class TestWebKitElement:
|
||||
lambda e: e.is_editable(),
|
||||
lambda e: e.is_text_input(),
|
||||
lambda e: e.remove_blank_target(),
|
||||
lambda e: e.debug_text(),
|
||||
lambda e: e.outer_xml(),
|
||||
lambda e: e.tag_name(),
|
||||
lambda e: e.rect_on_view(),
|
||||
@ -274,8 +273,8 @@ class TestWebKitElement:
|
||||
], ids=['str', 'getitem', 'setitem', 'delitem', 'contains', 'iter', 'len',
|
||||
'frame', 'geometry', 'style_property', 'text', 'set_text',
|
||||
'insert_text', 'is_writable', 'is_content_editable', 'is_editable',
|
||||
'is_text_input', 'remove_blank_target', 'debug_text', 'outer_xml',
|
||||
'tag_name', 'rect_on_view', 'is_visible'])
|
||||
'is_text_input', 'remove_blank_target', 'outer_xml', 'tag_name',
|
||||
'rect_on_view', 'is_visible'])
|
||||
def test_vanished(self, elem, code):
|
||||
"""Make sure methods check if the element is vanished."""
|
||||
elem._elem.isNull.return_value = True
|
||||
@ -286,14 +285,19 @@ class TestWebKitElement:
|
||||
def test_str(self, elem):
|
||||
assert str(elem) == 'text'
|
||||
|
||||
@pytest.mark.parametrize('is_null, expected', [
|
||||
(False, "<qutebrowser.browser.webkit.webkitelem.WebKitElement "
|
||||
"html='<fakeelem/>'>"),
|
||||
(True, '<qutebrowser.browser.webkit.webkitelem.WebKitElement '
|
||||
'html=None>'),
|
||||
wke_qualname = 'qutebrowser.browser.webkit.webkitelem.WebKitElement'
|
||||
|
||||
@pytest.mark.parametrize('is_null, xml, expected', [
|
||||
(False, '<fakeelem/>', "<{} html='<fakeelem/>'>".format(wke_qualname)),
|
||||
(False, '<foo>\n<bar/>\n</foo>',
|
||||
"<{} html='<foo><bar/></foo>'>".format(wke_qualname)),
|
||||
(False, '<foo>{}</foo>'.format('x' * 500),
|
||||
"<{} html='<foo>{}…'>".format(wke_qualname, 'x' * 494)),
|
||||
(True, None, '<{} html=None>'.format(wke_qualname)),
|
||||
])
|
||||
def test_repr(self, elem, is_null, expected):
|
||||
def test_repr(self, elem, is_null, xml, expected):
|
||||
elem._elem.isNull.return_value = is_null
|
||||
elem._elem.toOuterXml.return_value = xml
|
||||
assert repr(elem) == expected
|
||||
|
||||
def test_getitem(self):
|
||||
@ -384,15 +388,6 @@ class TestWebKitElement:
|
||||
elem = get_webelem(tagname=tagname, attributes=attributes)
|
||||
assert elem.is_text_input() == expected
|
||||
|
||||
@pytest.mark.parametrize('xml, expected', [
|
||||
('<fakeelem/>', '<fakeelem/>'),
|
||||
('<foo>\n<bar/>\n</foo>', '<foo><bar/></foo>'),
|
||||
('<foo>{}</foo>'.format('x' * 500), '<foo>{}…'.format('x' * 494)),
|
||||
], ids=['fakeelem', 'newlines', 'long'])
|
||||
def test_debug_text(self, elem, xml, expected):
|
||||
elem._elem.toOuterXml.return_value = xml
|
||||
assert elem.debug_text() == expected
|
||||
|
||||
@pytest.mark.parametrize('attribute, code', [
|
||||
('geometry', lambda e: e.geometry()),
|
||||
('toOuterXml', lambda e: e.outer_xml()),
|
||||
|
Loading…
Reference in New Issue
Block a user