Skip to main content

pytest-failed-screenshot: pytest plugin

For UI automation test cases using selenium and appium, screenshots are saved when they fail, and are attached to the report when allure is used

Support helium, the webdriver process cannot be killed within a use case

install

pip install pytest-failed-screenshot

Usage

command line:pytest --screenshot={on:off} --screenshot_path={on:off:absolute path}

    • options:

    • screenshot: Used to open plugin, default “off”

    • screenshot_path:
      • off: The default is ‘off’.The screenshot will not be saved and will only be attached to the allure report.

      • on: The screenshots will be saved to the “./screenshot/%Y-%m-%d/” directory in the root path of the project. If the directory has historical screenshots, the historical screenshots will be archived, moved to the “./screenshot/history/%Y-%m-%d/{times}” directory, and attached to the allure report

      • Absolute path: The screenshot will be saved in that path and attached to the report.

Demo

The driver instances of selenium and appium must be transferred by a fixture.

import pytest
from selenium import webdriver


@pytest.fixture()
def init_driver():
    driver = webdriver.Chrome()
    yield driver
    driver.close()
    driver.quit()


def test_login_success(init_driver):
    init_driver.get("https://github.com/fungaegis/pytest-failed-screenshot")
    assert False


# helium demo
@pytest.fixture()
def init_helium():
    yield None
    kill_browser()


@pytest.mark.usefixtures("init_helium")
def test_helium_demo():
    start_chrome("https://github.com/fungaegis/pytest-failed-screenshot")
    # The webdriver process cannot be killed within a use case
    assert False

command: pytest --screenshot=on --screenshot_path=on

tip: Support the use of pytest-xdist together

log

v1.0.1

Support helium for screenshots , solve the problem https://github.com/fungaegis/pytest-failed-screenshot/issues/1

v1.0.2

Update the readme and add demo

Metadata

Release files for pytest-failed-screenshot 1.0.2

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

Source distribution (sdist)

Source distribution for pytest-failed-screenshot 1.0.2
File Size Uploaded
pytest_failed_screenshot-1.0.2.tar.gz 3.7 kB Details

Release files / pytest_failed_screenshot-1.0.2.tar.gz

Download URL pytest_failed_screenshot-1.0.2.tar.gz
Size 3.7 kB
Tags Source
SHA-256 checksum
How to use checksums
305c301cb980f28b45e9441d14b21c434b78f49701d7edbf9065c1bcacd04d4d
BLAKE2b-256 checksum
How to use checksums
92158f52ddfc7d58989f2ef0e1b36992146733f97373b90e00be4fc692a50f82
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.7.5

Release history Release notifications | RSS feed

This release

1.0.2 This release

1 release file

1.0.1

1 release file

1.0.0

1 release file

0.1

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