diff options
author | Florian Bruhin <me@the-compiler.org> | 2023-11-21 16:26:29 +0100 |
---|---|---|
committer | Florian Bruhin <me@the-compiler.org> | 2023-11-21 16:26:29 +0100 |
commit | 9e148db5a635231a363c09d2bdd740bebd293689 (patch) | |
tree | 0b88291e1e3d641a64067b526ad7585b6817b237 | |
parent | 14c00fcdf0bc1e77d82b69d663e883ffe89f2421 (diff) | |
download | qutebrowser-9e148db5a635231a363c09d2bdd740bebd293689.tar.gz qutebrowser-9e148db5a635231a363c09d2bdd740bebd293689.zip |
Save screenshots when using click-elementmaint/flaky_js_tests
-rw-r--r-- | qutebrowser/browser/webelem.py | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/qutebrowser/browser/webelem.py b/qutebrowser/browser/webelem.py index 2356ad086..e5a97116b 100644 --- a/qutebrowser/browser/webelem.py +++ b/qutebrowser/browser/webelem.py @@ -4,12 +4,15 @@ """Generic web element related code.""" +import os +import functools +import datetime from typing import Iterator, Optional, Set, TYPE_CHECKING, Union, Dict import collections.abc from qutebrowser.qt import machinery -from qutebrowser.qt.core import QUrl, Qt, QEvent, QTimer, QRect, QPointF -from qutebrowser.qt.gui import QMouseEvent +from qutebrowser.qt.core import QUrl, Qt, QEvent, QTimer, QRect, QPointF, QPoint, QSize +from qutebrowser.qt.gui import QMouseEvent, QPainter from qutebrowser.config import config from qutebrowser.keyinput import modeman @@ -355,10 +358,27 @@ class AbstractWebElement(collections.abc.MutableMapping): # type: ignore[type-a QMouseEvent(QEvent.Type.MouseButtonRelease, pos, button, Qt.MouseButton.NoButton, modifiers), ] + pixmap = self._tab.private_api.event_target().grab() + assert not pixmap.isNull() + painter = QPainter() + assert painter.begin(pixmap) + painter.setPen(Qt.GlobalColor.red) + painter.drawLine(pos - QPointF(10, 0), pos + QPointF(10, 0)) + painter.drawLine(pos - QPointF(0, 10), pos + QPointF(0, 10)) + assert painter.end() + for evt in events: self._tab.send_event(evt) QTimer.singleShot(0, self._move_text_cursor) + QTimer.singleShot(0, functools.partial(self._save_pixmap, pixmap)) + + def _save_pixmap(self, pixmap): + test = os.environ.get("PYTEST_CURRENT_TEST", "unknown").replace("/", "_") + ts = datetime.datetime.now().isoformat() + filename = f"/tmp/qb-{test}-{ts}.png" + log.misc.debug(filename) + assert pixmap.save(filename) def _click_editable(self, click_target: usertypes.ClickTarget) -> None: """Fake a click on an editable input field.""" |