Skip to content

Commit

Permalink
Merge 44e2a07 into a77e2b9
Browse files Browse the repository at this point in the history
  • Loading branch information
digitronik committed Aug 3, 2020
2 parents a77e2b9 + 44e2a07 commit 1e27cdf
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/widgetastic/browser.py
Expand Up @@ -896,6 +896,18 @@ def close_window(self, window_handle=None):
else:
self.selenium.close()

def save_screenshot(self, filename):
"""Saves a screenshot of current browser window to a PNG image file.
Args:
filename: The full path you wish to save your screenshot to.
This should end with a `.png` extension.
Returns:
``False`` for any IOError else ``True``.
"""
self.logger.debug("Saving screenshot to -> %r", filename)
self.selenium.save_screenshot(filename=filename)


class BrowserParentWrapper(object):
"""A wrapper/proxy class that ensures passing of correct parent locator on elements lookup.
Expand Down
2 changes: 1 addition & 1 deletion src/widgetastic/widget/base.py
Expand Up @@ -776,7 +776,7 @@ def view_process(cls_or_descriptor):
isinstance(cls_or_descriptor, WidgetDescriptor) or
(inspect.isclass(cls_or_descriptor) and issubclass(cls_or_descriptor, Widget))):
raise TypeError(
'Unsupported object registered into the selector (!r})'.format(
'Unsupported object registered into the selector ({!r})'.format(
cls_or_descriptor))
self.registered_views.append((condition, cls_or_descriptor))
if default:
Expand Down
13 changes: 13 additions & 0 deletions testing/test_browser.py
@@ -1,4 +1,8 @@
# -*- coding: utf-8 -*-
import tempfile
from datetime import datetime
from pathlib import Path

import pytest

from widgetastic.browser import BrowserParentWrapper, WebElement
Expand Down Expand Up @@ -289,3 +293,12 @@ def test_switch_to_window(browser, current_and_new_handle):
assert new_handle == browser.current_window_handle
browser.switch_to_window(main_handle)
assert main_handle == browser.current_window_handle


def test_save_screenshot(browser):
"""Test browser save screenshot method."""
tmp_dir = tempfile._get_default_tempdir()
filename = Path(tmp_dir) / "{}.png".format(datetime.now())
assert not filename.exists()
browser.save_screenshot(filename=filename.as_posix())
assert filename.exists()

0 comments on commit 1e27cdf

Please sign in to comment.