Package: pytest-enhanced-reports
pytest-enhanced-reportsA pytest plugin to capture screenshots, videos and JS logs (similar to Cypress) and attach them to supported test reports.SupportPython>= 3.7BrowsersFully supported- Chromium based browsers - Chrome, Edge, Brave, Opera, Vivaldi, etcPlanned in the future- Firefox, SafariReportingFully supported-allure-pytest-bddPlanned in the future-pytest-html,pytest-testrail-clientInstallationpipinstallpytest-enhanced-reportsUsageSetupThe plugin needs a code change to be able to capture data from the webdriver instance. Usually, this is just a few lines added to the webdriver initialization logic.Before plugin integration@pytest.fixturedefdriver():driver=webdriver.Chrome()yielddriverdriver.quit()After plugin integration@pytest.fixturedefdriver(enhance_driver):# `enhance_driver` is a fixture provided by the plugindriver=webdriver.Chrome()enhanced_driver=Nonetry:enhanced_driver=enhance_driver(driver)exceptExceptionase:logger.error(e)yieldenhanced_driverifenhanced_driverelsedriverdriver.quit()ConfigurationThe plugin can be configured through command line arguments and/or environment variables. Either option can be used, but if both are provided for any configuration, the command line argument takes precedence over the environment variable.The following sets of shell commands are equivalent and do the same thing. These examples ignore any configuration for all other plugins/dependencies.# Using only command line argumentspytest--report_screenshot_capture="error-only"--report_screenshot_dir="~/tests/screenshots"--report_browser_console_log_capture="on_failure"# Using a combination of command line arguments and environment variablesREPORT_SCREENSHOT_DIR="~/tests/screenshots"pytest--report_screenshot_capture="error-only"--report_browser_console_log_capture="on_failure"# Using only environment variablesREPORT_SCREENSHOT_CAPTURE="error-only"REPORT_SCREENSHOT_DIR="~/tests/screenshots"REPORT_BROWSER_CONSOLE_LOG_CAPTURE="on_failure"pytestThe full list of configuration options are listed below.ScreenshotsConfiguration OptionExpected ValueDefault ValueDescriptionreport_screenshot_captureOne of "always", "each_ui_operation", "end_of_each_test", "failed_test_only", "never"each_ui_operationSpecifies when to capture screenshots.report_screenshot_widthint0The expected width of the resized screenshot used in reports. Actual value could be slightly different as it needs to fit the aspect ratio.report_screenshot_heightint0The expected height of the resized screenshot used in reports. Actual value could be slightly different as it needs to fit the aspect ratio.report_screenshot_resize_percentint40A percentage by which the screenshot will be resized. This is ignored if screenshot height and width values are also provided. Valid values - 75, 60, 50, etc.report_screenshot_dirpath to directory"reports/screenshots"If set to True, the element being interacted with will be highlighted before taking the screenshot.report_keep_screenshotsTrue or FalseFalseIf set to True, generated screenshot images will not be deleted after the test run.report_highlighted_screenshotTrue or FalseFalseUsed to highlight element and take a screenshot before user's interactionVideo RecordingConfiguration OptionExpected ValueDefault ValueDescriptionreport_video_recordingTrue or FalseFalseIf set to True, a video will be recorded for each test.report_video_widthint0Expected width of the video. Actual value could be different as it needs to fit the aspect ratio.report_video_heightint0Expected height of the video. Actual value could be different as it needs to fit the aspect ratio.report_video_resize_percentint75A percentage by which the video frames will be resized. This is ignored if video height and width values are also provided. Valid values - 75, 60, 50, etc.report_video_frame_rateint30The expected number of frames per second while recording a video. This is applicable only when enough frames were recorded in one second, which is not guaranteed.report_video_dirpath to directory"reports/videos"The path to the directory where video files will be stored.report_keep_videosTrue or FalseFalseIf set to True, generated video files will not be deleted after the test run.Browser console outputsConfiguration OptionExpected ValueDefault ValueDescriptionreport_browser_console_log_captureOne of "always", "each_ui_operation", "end_of_each_test", "failed_test_only", "never"failed_test_onlySpecifies when to capture info from the browser console logContributingJust the standard fork, branch, commit, test, push, pull request workflow. Including specifics for the sake of documentation.Create a fork ofthe repoand clone the forkInstall all dependencies fromrequirements.txtMake changesWhen committing changes,blackandflake8will be run automatically to ensure code qualityIn case they don't run automatically, executeblack . && flake8blackwill automatically make changes to fix any issues it identifies, however the changes would need to be staged again and committedAny problems highlighted byflake8requires manual changes/adjustmentsRun the tests to ensure nothing brokePush changes, create a pull request