Remove no longer needed webelem methods
The following methods were only used for hint labels and thus removed now: - document_element - create_inside - find_first - set_inner_xml - remove_from_document - set_style_property
This commit is contained in:
parent
1753d3507c
commit
cf7170a33b
@ -112,21 +112,6 @@ class AbstractWebElement(collections.abc.MutableMapping):
|
||||
"""Get the geometry for this element."""
|
||||
raise NotImplementedError
|
||||
|
||||
def document_element(self):
|
||||
"""Get the document element of this element."""
|
||||
# FIXME:qtwebengine get rid of this?
|
||||
raise NotImplementedError
|
||||
|
||||
def create_inside(self, tagname):
|
||||
"""Append the given element inside the current one."""
|
||||
# FIXME:qtwebengine get rid of this?
|
||||
raise NotImplementedError
|
||||
|
||||
def find_first(self, selector):
|
||||
"""Find the first child based on the given CSS selector."""
|
||||
# FIXME:qtwebengine get rid of this?
|
||||
raise NotImplementedError
|
||||
|
||||
def style_property(self, name, *, strategy):
|
||||
"""Get the element style resolved with the given strategy."""
|
||||
raise NotImplementedError
|
||||
@ -166,21 +151,6 @@ class AbstractWebElement(collections.abc.MutableMapping):
|
||||
# FIXME:qtwebengine what to do about use_js with WebEngine?
|
||||
raise NotImplementedError
|
||||
|
||||
def set_inner_xml(self, xml):
|
||||
"""Set the given inner XML."""
|
||||
# FIXME:qtwebengine get rid of this?
|
||||
raise NotImplementedError
|
||||
|
||||
def remove_from_document(self):
|
||||
"""Remove the node from the document."""
|
||||
# FIXME:qtwebengine get rid of this?
|
||||
raise NotImplementedError
|
||||
|
||||
def set_style_property(self, name, value):
|
||||
"""Set the element style."""
|
||||
# FIXME:qtwebengine get rid of this?
|
||||
raise NotImplementedError
|
||||
|
||||
def run_js_async(self, code, callback=None):
|
||||
"""Run the given JS snippet async on the element."""
|
||||
# FIXME:qtwebengine get rid of this?
|
||||
|
@ -66,18 +66,6 @@ class WebEngineElement(webelem.AbstractWebElement):
|
||||
log.stub()
|
||||
return QRect()
|
||||
|
||||
def document_element(self):
|
||||
log.stub()
|
||||
return None
|
||||
|
||||
def create_inside(self, tagname):
|
||||
log.stub()
|
||||
return None
|
||||
|
||||
def find_first(self, selector):
|
||||
log.stub()
|
||||
return None
|
||||
|
||||
def style_property(self, name, *, strategy):
|
||||
log.stub()
|
||||
return ''
|
||||
@ -121,21 +109,6 @@ class WebEngineElement(webelem.AbstractWebElement):
|
||||
js_code = javascript.assemble('webelem', 'set_text', self._id, text)
|
||||
self._run_js(js_code)
|
||||
|
||||
def set_inner_xml(self, xml):
|
||||
"""Set the given inner XML."""
|
||||
# FIXME:qtwebengine get rid of this?
|
||||
log.stub()
|
||||
|
||||
def remove_from_document(self):
|
||||
"""Remove the node from the document."""
|
||||
# FIXME:qtwebengine get rid of this?
|
||||
log.stub()
|
||||
|
||||
def set_style_property(self, name, value):
|
||||
"""Set the element style."""
|
||||
# FIXME:qtwebengine get rid of this?
|
||||
log.stub()
|
||||
|
||||
def run_js_async(self, code, callback=None):
|
||||
"""Run the given JS snippet async on the element."""
|
||||
# FIXME:qtwebengine get rid of this?
|
||||
|
@ -91,28 +91,6 @@ class WebKitElement(webelem.AbstractWebElement):
|
||||
self._check_vanished()
|
||||
return self._elem.geometry()
|
||||
|
||||
def document_element(self):
|
||||
self._check_vanished()
|
||||
elem = self._elem.webFrame().documentElement()
|
||||
return WebKitElement(elem)
|
||||
|
||||
def create_inside(self, tagname):
|
||||
# It seems impossible to create an empty QWebElement for which isNull()
|
||||
# is false so we can work with it.
|
||||
# As a workaround, we use appendInside() with markup as argument, and
|
||||
# then use lastChild() to get a reference to it.
|
||||
# See: http://stackoverflow.com/q/7364852/2085149
|
||||
self._check_vanished()
|
||||
self._elem.appendInside('<{}></{}>'.format(tagname, tagname))
|
||||
return WebKitElement(self._elem.lastChild())
|
||||
|
||||
def find_first(self, selector):
|
||||
self._check_vanished()
|
||||
elem = self._elem.findFirst(selector)
|
||||
if elem.isNull():
|
||||
return None
|
||||
return WebKitElement(elem)
|
||||
|
||||
def style_property(self, name, *, strategy):
|
||||
self._check_vanished()
|
||||
strategies = {
|
||||
@ -156,18 +134,6 @@ class WebKitElement(webelem.AbstractWebElement):
|
||||
text = javascript.string_escape(text)
|
||||
self._elem.evaluateJavaScript("this.value='{}'".format(text))
|
||||
|
||||
def set_inner_xml(self, xml):
|
||||
self._check_vanished()
|
||||
self._elem.setInnerXml(xml)
|
||||
|
||||
def remove_from_document(self):
|
||||
self._check_vanished()
|
||||
self._elem.removeFromDocument()
|
||||
|
||||
def set_style_property(self, name, value):
|
||||
self._check_vanished()
|
||||
return self._elem.setStyleProperty(name, value)
|
||||
|
||||
def run_js_async(self, code, callback=None):
|
||||
"""Run the given JS snippet async on the element."""
|
||||
self._check_vanished()
|
||||
|
@ -80,7 +80,7 @@ class FakeWebFrame:
|
||||
"""
|
||||
|
||||
def __init__(self, geometry=None, *, scroll=None, plaintext=None,
|
||||
html=None, parent=None, zoom=1.0, document_element=None):
|
||||
html=None, parent=None, zoom=1.0):
|
||||
"""Constructor.
|
||||
|
||||
Args:
|
||||
@ -89,7 +89,6 @@ class FakeWebFrame:
|
||||
plaintext: Return value of toPlainText
|
||||
html: Return value of tohtml.
|
||||
zoom: The zoom factor.
|
||||
document_element: The documentElement() to return
|
||||
parent: The parent frame.
|
||||
"""
|
||||
if scroll is None:
|
||||
@ -101,7 +100,6 @@ class FakeWebFrame:
|
||||
self.toPlainText = mock.Mock(return_value=plaintext)
|
||||
self.toHtml = mock.Mock(return_value=html)
|
||||
self.zoomFactor = mock.Mock(return_value=zoom)
|
||||
self.documentElement = mock.Mock(return_value=document_element)
|
||||
|
||||
def findFirstElement(self, selector):
|
||||
if selector == '*:focus':
|
||||
|
@ -255,15 +255,9 @@ class TestWebKitElement:
|
||||
len,
|
||||
lambda e: e.frame(),
|
||||
lambda e: e.geometry(),
|
||||
lambda e: e.document_element(),
|
||||
lambda e: e.create_inside('span'),
|
||||
lambda e: e.find_first('span'),
|
||||
lambda e: e.style_property('visibility', strategy='computed'),
|
||||
lambda e: e.text(),
|
||||
lambda e: e.set_text('foo'),
|
||||
lambda e: e.set_inner_xml(''),
|
||||
lambda e: e.remove_from_document(),
|
||||
lambda e: e.set_style_property('visibility', 'hidden'),
|
||||
lambda e: e.is_writable(),
|
||||
lambda e: e.is_content_editable(),
|
||||
lambda e: e.is_editable(),
|
||||
@ -276,9 +270,7 @@ class TestWebKitElement:
|
||||
lambda e: e.rect_on_view(),
|
||||
lambda e: e.is_visible(None),
|
||||
], ids=['str', 'getitem', 'setitem', 'delitem', 'contains', 'iter', 'len',
|
||||
'frame', 'geometry', 'document_element', 'create_inside',
|
||||
'find_first', 'style_property', 'text', 'set_text',
|
||||
'set_inner_xml', 'remove_from_document', 'set_style_property',
|
||||
'frame', 'geometry', 'style_property', 'text', 'set_text',
|
||||
'is_writable', 'is_content_editable', 'is_editable',
|
||||
'is_text_input', 'remove_blank_target', 'debug_text', 'outer_xml',
|
||||
'tag_name', 'run_js_async', 'rect_on_view', 'is_visible'])
|
||||
@ -410,17 +402,6 @@ class TestWebKitElement:
|
||||
setattr(mock, 'return_value', sentinel)
|
||||
assert code(elem) is sentinel
|
||||
|
||||
@pytest.mark.parametrize('code, method, args', [
|
||||
(lambda e: e.set_inner_xml('foo'), 'setInnerXml', ['foo']),
|
||||
(lambda e: e.set_style_property('foo', 'bar'), 'setStyleProperty',
|
||||
['foo', 'bar']),
|
||||
(lambda e: e.remove_from_document(), 'removeFromDocument', []),
|
||||
])
|
||||
def test_simple_setters(self, elem, code, method, args):
|
||||
code(elem)
|
||||
mock = getattr(elem._elem, method)
|
||||
mock.assert_called_with(*args)
|
||||
|
||||
def test_tag_name(self, elem):
|
||||
elem._elem.tagName.return_value = 'SPAN'
|
||||
assert elem.tag_name() == 'span'
|
||||
@ -428,34 +409,6 @@ class TestWebKitElement:
|
||||
def test_style_property(self, elem):
|
||||
assert elem.style_property('foo', strategy='computed') == 'bar'
|
||||
|
||||
def test_document_element(self, stubs):
|
||||
doc_elem = get_webelem()
|
||||
frame = stubs.FakeWebFrame(document_element=doc_elem._elem)
|
||||
elem = get_webelem(frame=frame)
|
||||
|
||||
doc_elem_ret = elem.document_element()
|
||||
assert isinstance(doc_elem_ret, webkitelem.WebKitElement)
|
||||
assert doc_elem_ret == doc_elem
|
||||
|
||||
def test_find_first(self, elem):
|
||||
result = get_webelem()
|
||||
elem._elem.findFirst.return_value = result._elem
|
||||
find_result = elem.find_first('')
|
||||
assert isinstance(find_result, webkitelem.WebKitElement)
|
||||
assert find_result == result
|
||||
|
||||
def test_create_inside(self, elem):
|
||||
child = get_webelem()
|
||||
elem._elem.lastChild.return_value = child._elem
|
||||
assert elem.create_inside('span')._elem is child._elem
|
||||
elem._elem.appendInside.assert_called_with('<span></span>')
|
||||
|
||||
def test_find_first_null(self, elem):
|
||||
nullelem = get_webelem()
|
||||
nullelem._elem.isNull.return_value = True
|
||||
elem._elem.findFirst.return_value = nullelem._elem
|
||||
assert elem.find_first('foo') is None
|
||||
|
||||
@pytest.mark.parametrize('use_js, editable, expected', [
|
||||
(True, 'false', 'js'),
|
||||
(True, 'true', 'nojs'),
|
||||
|
Loading…
Reference in New Issue
Block a user