Skip to main content

selenium_screenshots

GitHub last commit GitHub license<space><space> Documentation Status https://travis-ci.org/stas-prokopiev/selenium_screenshots.svg?branch=master PyPI PyPI - Python Version

Short Overview.

selenium_screenshots is a python package that helps to create many screenshots for selenium webdrivers.

Example

from selenium import webdriver
from selenium_screenshots import make_screenshot
# Please define here any webdriver which you would like to use E.G. driver = webdriver.Chrome()
# When you would want to create a screenshot, just call
make_screenshot(driver)
make_screenshot(driver, "some_description")
make_screenshot(driver, "characters_%%forbidden_in_the_..filename")

As the result you will get screenshots in the directory: ./screenshots/…

  • 1.png

  • 2_some_description.png

  • 3_characters___forbidden_in_the___filename.png

If you run this code some other time then you’ll get 3 more screenshots:

  • 1.png

  • 2_some_description.png

  • 3_characters___forbidden_in_the___filename.png

  • 4.png

  • 5_some_description.png

  • 6_characters___forbidden_in_the___filename.png

As you can see user shouldn’t worry about screenshot’s numbers as they will be handled automatically.

Installation via pip:

pip install selenium_screenshots

Basic Usage

Full signature of selenium_screenshots.make_screenshot(…)

from selenium_screenshots import make_screenshot

make_screenshot(
    webdriver,
    str_description="",
    str_path_dir_with_screenshots="screenshots",
)

Arguments

  1. webdriver:

    The only mandatary argument. Any selenium webdriver which to use for making of screenshot.

  2. str_description=””:
    Description of the screenshot to add to the screenshot filename.
    If in the screenshot description will be used symbols forbidden in the filenames they will be replaced on “_”.
    If filename of a new screenshot is longer than 50 symbols then it will be cut to 50.
  3. str_path_dir_with_screenshots=”screenshots”:

    Path to the directory where you want to save a new screenshot

Advanced Usage

selenium_screenshots.Screenshots(…)

Firstly, you have to define an object of class Screenshots to be able to handle screenshots.
This object will be named screenshots_handler in the code below.
from selenium import webdriver
from selenium_screenshots.main import Screenshots

# Please define here any webdriver which you would like to use E.G. driver = webdriver.Chrome()
screenshots_handler = Screenshots(
        webdriver,
        str_path_dir_with_screenshots="screenshots",
        int_screenshots_to_delete_half=9999,
        int_max_length_of_filename=50,
)

Arguments

  1. webdriver:

    The only mandatary argument. Any selenium webdriver which to use for making of screenshots.

  2. str_path_dir_with_screenshots=”screenshots”:

    Path to directory where to save screenshots.

  3. int_screenshots_to_delete_half=9999:

    Number of the screenshots in the directory when try to delete most old half

  4. int_max_length_of_filename=50:
    Max length of a new screenshot filename.
    If filename of a new screenshot is longer then filename will be cut.

Methods of screenshots_handler object

screenshots_handler.create_screenshot(…)

This method do exactly the same as selenium_screenshots.make_screenshot(…) in the Basic Usage

screenshots_handler.create_screenshot(str_description="")
  1. str_description=””:
    Description of the screenshot to add to the screenshot filename.
    If in the screenshot description is used symbols forbidden in the filenames they will be replaced on “_”.
    If filename of a new screenshot is longer than N symbols then it will be cut to N.

screenshots_handler.delete_all_screenshots(…)

This method will delete all screenshots in the directory.
Max used screenshot number won’t be lost, so new screenshot will have next number rather than 1.
screenshots_handler.delete_all_screenshots()

screenshots_handler.delete_not_unique_screenshots(…)

This method will delete screenshots with not unique descriptions.
screenshots_handler.delete_not_unique_screenshots(
    is_to_delete_screenshots_without_description=False)
  1. is_to_delete_screenshots_without_description=False:
    Flag if to delete screenshots without description

How to create screenshot every time when you caught an Exception

You can use this python package to make screenshots for every exception
with preserved description of an error in the screenshot filename.
from selenium_screenshots import make_screenshot

try:
    # Some code which you would like to test
except Exception as ex:
    make_screenshot(webdriver, str_description=str(ex))
    raise

Contacts

License

This project is licensed under the MIT License.

Metadata

Release files for selenium-screenshots 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for selenium-screenshots 0.1.3
File Size Uploaded
selenium_screenshots-0.1.3.tar.gz 8.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for selenium-screenshots 0.1.3
File Interpreter ABI Platform
selenium_screenshots-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 16.8 kB

Release files / selenium_screenshots-0.1.3.tar.gz

Download URL selenium_screenshots-0.1.3.tar.gz
Size 8.4 kB
Tags Source
SHA-256 checksum
How to use checksums
b5cf6d2c278ff515f1a8a837326d9ea19813403890d74f9ef33f3dcfa6df843d
BLAKE2b-256 checksum
How to use checksums
b424a1d4579d5e9a0c7d68591dfa5aec7b809a1126f3f6eabe6c5182ff63d558
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.9.7 Windows/10

Release files / selenium_screenshots-0.1.3-py3-none-any.whl

Download URL selenium_screenshots-0.1.3-py3-none-any.whl
Size 8.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
202717ebdec0e652e8ee5d353431a4637374c00e558536b1090449ab070105a6
BLAKE2b-256 checksum
How to use checksums
a537e635ba4c5c5eaff558421319cd363278b9c97ac021626dba288a4cb2406d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.9.7 Windows/10

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page