Make WebKitElement._is_visible private
It makes a lot of sense for this to be in webkitelem.py, but it should not be public API as it's only used internally and can't be implemented here with QtWebEngine.
This commit is contained in:
parent
ae3b7c9f15
commit
3e1583bb1c
@ -187,11 +187,6 @@ class AbstractWebElement(collections.abc.MutableMapping):
|
|||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def is_visible(self, mainframe):
|
|
||||||
"""Check if the given element is visible in the given frame."""
|
|
||||||
# FIXME:qtwebengine get rid of this?
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
def is_writable(self):
|
def is_writable(self):
|
||||||
"""Check whether an element is writable."""
|
"""Check whether an element is writable."""
|
||||||
return not ('disabled' in self or 'readonly' in self)
|
return not ('disabled' in self or 'readonly' in self)
|
||||||
|
@ -162,9 +162,3 @@ class WebEngineElement(webelem.AbstractWebElement):
|
|||||||
log.webelem.debug("Couldn't find rectangle for {!r} ({})".format(
|
log.webelem.debug("Couldn't find rectangle for {!r} ({})".format(
|
||||||
self, rects))
|
self, rects))
|
||||||
return QRect()
|
return QRect()
|
||||||
|
|
||||||
def is_visible(self, mainframe):
|
|
||||||
"""Check if the given element is visible in the given frame."""
|
|
||||||
# FIXME:qtwebengine get rid of this?
|
|
||||||
log.stub()
|
|
||||||
return True
|
|
||||||
|
@ -233,8 +233,13 @@ class WebKitElement(webelem.AbstractWebElement):
|
|||||||
# No suitable rects found via JS, try via the QWebElement API
|
# No suitable rects found via JS, try via the QWebElement API
|
||||||
return self._rect_on_view_python(elem_geometry)
|
return self._rect_on_view_python(elem_geometry)
|
||||||
|
|
||||||
def is_visible(self, mainframe):
|
def _is_visible(self, mainframe):
|
||||||
"""Check if the given element is visible in the given frame."""
|
"""Check if the given element is visible in the given frame.
|
||||||
|
|
||||||
|
This is not public API because it can't be implemented easily here with
|
||||||
|
QtWebEngine, and is only used via find_css(..., only_visible=True) via
|
||||||
|
the tab API.
|
||||||
|
"""
|
||||||
self._check_vanished()
|
self._check_vanished()
|
||||||
# CSS attributes which hide an element
|
# CSS attributes which hide an element
|
||||||
hidden_attributes = {
|
hidden_attributes = {
|
||||||
|
@ -507,7 +507,9 @@ class WebKitElements(browsertab.AbstractElements):
|
|||||||
elems.append(webkitelem.WebKitElement(elem, tab=self._tab))
|
elems.append(webkitelem.WebKitElement(elem, tab=self._tab))
|
||||||
|
|
||||||
if only_visible:
|
if only_visible:
|
||||||
elems = [e for e in elems if e.is_visible(mainframe)]
|
# pylint: disable=protected-access
|
||||||
|
elems = [e for e in elems if e._is_visible(mainframe)]
|
||||||
|
# pylint: enable=protected-access
|
||||||
|
|
||||||
callback(elems)
|
callback(elems)
|
||||||
|
|
||||||
|
@ -269,7 +269,7 @@ class TestWebKitElement:
|
|||||||
lambda e: e.outer_xml(),
|
lambda e: e.outer_xml(),
|
||||||
lambda e: e.tag_name(),
|
lambda e: e.tag_name(),
|
||||||
lambda e: e.rect_on_view(),
|
lambda e: e.rect_on_view(),
|
||||||
lambda e: e.is_visible(None),
|
lambda e: e._is_visible(None),
|
||||||
], ids=['str', 'getitem', 'setitem', 'delitem', 'contains', 'iter', 'len',
|
], ids=['str', 'getitem', 'setitem', 'delitem', 'contains', 'iter', 'len',
|
||||||
'frame', 'geometry', 'style_property', 'text', 'set_text',
|
'frame', 'geometry', 'style_property', 'text', 'set_text',
|
||||||
'insert_text', 'is_writable', 'is_content_editable', 'is_editable',
|
'insert_text', 'is_writable', 'is_content_editable', 'is_editable',
|
||||||
@ -491,14 +491,14 @@ class TestIsVisible:
|
|||||||
assert not rect.isValid()
|
assert not rect.isValid()
|
||||||
frame = stubs.FakeWebFrame(rect)
|
frame = stubs.FakeWebFrame(rect)
|
||||||
elem = get_webelem(QRect(0, 0, 10, 10), frame)
|
elem = get_webelem(QRect(0, 0, 10, 10), frame)
|
||||||
assert not elem.is_visible(frame)
|
assert not elem._is_visible(frame)
|
||||||
|
|
||||||
def test_invalid_invisible(self, frame):
|
def test_invalid_invisible(self, frame):
|
||||||
"""Test elements with an invalid geometry which are invisible."""
|
"""Test elements with an invalid geometry which are invisible."""
|
||||||
elem = get_webelem(QRect(0, 0, 0, 0), frame)
|
elem = get_webelem(QRect(0, 0, 0, 0), frame)
|
||||||
assert not elem.geometry().isValid()
|
assert not elem.geometry().isValid()
|
||||||
assert elem.geometry().x() == 0
|
assert elem.geometry().x() == 0
|
||||||
assert not elem.is_visible(frame)
|
assert not elem._is_visible(frame)
|
||||||
|
|
||||||
def test_invalid_visible(self, frame):
|
def test_invalid_visible(self, frame):
|
||||||
"""Test elements with an invalid geometry which are visible.
|
"""Test elements with an invalid geometry which are visible.
|
||||||
@ -508,7 +508,7 @@ class TestIsVisible:
|
|||||||
"""
|
"""
|
||||||
elem = get_webelem(QRect(10, 10, 0, 0), frame)
|
elem = get_webelem(QRect(10, 10, 0, 0), frame)
|
||||||
assert not elem.geometry().isValid()
|
assert not elem.geometry().isValid()
|
||||||
assert elem.is_visible(frame)
|
assert elem._is_visible(frame)
|
||||||
|
|
||||||
@pytest.mark.parametrize('geometry, visible', [
|
@pytest.mark.parametrize('geometry, visible', [
|
||||||
(QRect(5, 5, 4, 4), False),
|
(QRect(5, 5, 4, 4), False),
|
||||||
@ -518,7 +518,7 @@ class TestIsVisible:
|
|||||||
scrolled_frame = stubs.FakeWebFrame(QRect(0, 0, 100, 100),
|
scrolled_frame = stubs.FakeWebFrame(QRect(0, 0, 100, 100),
|
||||||
scroll=QPoint(10, 10))
|
scroll=QPoint(10, 10))
|
||||||
elem = get_webelem(geometry, scrolled_frame)
|
elem = get_webelem(geometry, scrolled_frame)
|
||||||
assert elem.is_visible(scrolled_frame) == visible
|
assert elem._is_visible(scrolled_frame) == visible
|
||||||
|
|
||||||
@pytest.mark.parametrize('style, visible', [
|
@pytest.mark.parametrize('style, visible', [
|
||||||
({'visibility': 'visible'}, True),
|
({'visibility': 'visible'}, True),
|
||||||
@ -530,7 +530,7 @@ class TestIsVisible:
|
|||||||
])
|
])
|
||||||
def test_css_attributes(self, frame, style, visible):
|
def test_css_attributes(self, frame, style, visible):
|
||||||
elem = get_webelem(QRect(0, 0, 10, 10), frame, style=style)
|
elem = get_webelem(QRect(0, 0, 10, 10), frame, style=style)
|
||||||
assert elem.is_visible(frame) == visible
|
assert elem._is_visible(frame) == visible
|
||||||
|
|
||||||
|
|
||||||
class TestIsVisibleIframe:
|
class TestIsVisibleIframe:
|
||||||
@ -580,20 +580,20 @@ class TestIsVisibleIframe:
|
|||||||
get_webelem(QRect(30, 180, 10, 10), frame),
|
get_webelem(QRect(30, 180, 10, 10), frame),
|
||||||
]
|
]
|
||||||
|
|
||||||
assert elems[0].is_visible(frame)
|
assert elems[0]._is_visible(frame)
|
||||||
assert elems[1].is_visible(frame)
|
assert elems[1]._is_visible(frame)
|
||||||
assert not elems[2].is_visible(frame)
|
assert not elems[2]._is_visible(frame)
|
||||||
assert elems[3].is_visible(frame)
|
assert elems[3]._is_visible(frame)
|
||||||
|
|
||||||
return self.Objects(frame=frame, iframe=iframe, elems=elems)
|
return self.Objects(frame=frame, iframe=iframe, elems=elems)
|
||||||
|
|
||||||
def test_iframe_scrolled(self, objects):
|
def test_iframe_scrolled(self, objects):
|
||||||
"""Scroll iframe down so elem3 gets visible and elem1/elem2 not."""
|
"""Scroll iframe down so elem3 gets visible and elem1/elem2 not."""
|
||||||
objects.iframe.scrollPosition.return_value = QPoint(0, 100)
|
objects.iframe.scrollPosition.return_value = QPoint(0, 100)
|
||||||
assert not objects.elems[0].is_visible(objects.frame)
|
assert not objects.elems[0]._is_visible(objects.frame)
|
||||||
assert not objects.elems[1].is_visible(objects.frame)
|
assert not objects.elems[1]._is_visible(objects.frame)
|
||||||
assert objects.elems[2].is_visible(objects.frame)
|
assert objects.elems[2]._is_visible(objects.frame)
|
||||||
assert objects.elems[3].is_visible(objects.frame)
|
assert objects.elems[3]._is_visible(objects.frame)
|
||||||
|
|
||||||
def test_mainframe_scrolled_iframe_visible(self, objects):
|
def test_mainframe_scrolled_iframe_visible(self, objects):
|
||||||
"""Scroll mainframe down so iframe is partly visible but elem1 not."""
|
"""Scroll mainframe down so iframe is partly visible but elem1 not."""
|
||||||
@ -602,10 +602,10 @@ class TestIsVisibleIframe:
|
|||||||
objects.frame.scrollPosition())
|
objects.frame.scrollPosition())
|
||||||
assert not geom.contains(objects.iframe.geometry())
|
assert not geom.contains(objects.iframe.geometry())
|
||||||
assert geom.intersects(objects.iframe.geometry())
|
assert geom.intersects(objects.iframe.geometry())
|
||||||
assert not objects.elems[0].is_visible(objects.frame)
|
assert not objects.elems[0]._is_visible(objects.frame)
|
||||||
assert objects.elems[1].is_visible(objects.frame)
|
assert objects.elems[1]._is_visible(objects.frame)
|
||||||
assert not objects.elems[2].is_visible(objects.frame)
|
assert not objects.elems[2]._is_visible(objects.frame)
|
||||||
assert objects.elems[3].is_visible(objects.frame)
|
assert objects.elems[3]._is_visible(objects.frame)
|
||||||
|
|
||||||
def test_mainframe_scrolled_iframe_invisible(self, objects):
|
def test_mainframe_scrolled_iframe_invisible(self, objects):
|
||||||
"""Scroll mainframe down so iframe is invisible."""
|
"""Scroll mainframe down so iframe is invisible."""
|
||||||
@ -614,10 +614,10 @@ class TestIsVisibleIframe:
|
|||||||
objects.frame.scrollPosition())
|
objects.frame.scrollPosition())
|
||||||
assert not geom.contains(objects.iframe.geometry())
|
assert not geom.contains(objects.iframe.geometry())
|
||||||
assert not geom.intersects(objects.iframe.geometry())
|
assert not geom.intersects(objects.iframe.geometry())
|
||||||
assert not objects.elems[0].is_visible(objects.frame)
|
assert not objects.elems[0]._is_visible(objects.frame)
|
||||||
assert not objects.elems[1].is_visible(objects.frame)
|
assert not objects.elems[1]._is_visible(objects.frame)
|
||||||
assert not objects.elems[2].is_visible(objects.frame)
|
assert not objects.elems[2]._is_visible(objects.frame)
|
||||||
assert objects.elems[3].is_visible(objects.frame)
|
assert objects.elems[3]._is_visible(objects.frame)
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def invalid_objects(self, stubs):
|
def invalid_objects(self, stubs):
|
||||||
@ -661,11 +661,11 @@ class TestIsVisibleIframe:
|
|||||||
which *are* visible, but don't have a valid geometry.
|
which *are* visible, but don't have a valid geometry.
|
||||||
"""
|
"""
|
||||||
elem = invalid_objects.elems[0]
|
elem = invalid_objects.elems[0]
|
||||||
assert elem.is_visible(invalid_objects.frame)
|
assert elem._is_visible(invalid_objects.frame)
|
||||||
|
|
||||||
def test_invalid_invisible(self, invalid_objects):
|
def test_invalid_invisible(self, invalid_objects):
|
||||||
"""Test elements with an invalid geometry which are invisible."""
|
"""Test elements with an invalid geometry which are invisible."""
|
||||||
assert not invalid_objects.elems[1].is_visible(invalid_objects.frame)
|
assert not invalid_objects.elems[1]._is_visible(invalid_objects.frame)
|
||||||
|
|
||||||
|
|
||||||
class TestRectOnView:
|
class TestRectOnView:
|
||||||
|
Loading…
Reference in New Issue
Block a user