BehaveX extension library to attach images to the test execution report.
Project description
behavex-images
This implementation extends the BehaveX library to enable attaching images to the generated HTML report
Installation
pip install behavex-images
Basic Usage
The following methods are provided to manage image attachments in the BehaveX HTML report:
-
attach_image_binary(context, image_binary)
- This function attaches an image from binary data to the test execution report. It takes two parameters:
context
: The context object which contains various attributes used in the function.image_binary
: The binary data of the image to be attached.
- The function determines the binary format to ensure it maps to a JPG or PNG image. Otherwise, it raises an exception.
- Then, it converts the image to PNG format (if it is not already in that format) to add it to the gallery.
- This function attaches an image from binary data to the test execution report. It takes two parameters:
-
attach_image_file(context, file_path)
- This function attaches an image from a file to the test execution report. It takes two parameters:
context
: The context object which contains various attributes used in the function.file_path
: The absolute path to the image file to be attached.
- The function first checks if the file exists at the given path. If it does not, it raises an exception.
- If the file exists, it checks the file extension. If the extension is not JPG or PNG, it raises an exception.
- Then, it converts the image to PNG format (if it is not already in that format) to add it to the gallery.
- This function attaches an image from a file to the test execution report. It takes two parameters:
-
set_attachments_condition(context, condition)
- This function sets the condition to attach images to the HTML report. It takes two parameters:
context
: The context object which contains various attributes used in the function.condition
: The condition to attach images to the HTML report. Possible values:- AttachmentsCondition.ALWAYS: Attach images to the HTML report always.
- AttachmentsCondition.ONLY_ON_FAILURE: Attach images to the HTML report only when the test fails. This is the default value.
- AttachmentsCondition.NEVER: Do not attach images to the HTML report, no matter the test result.
- This function sets the condition to attach images to the HTML report. It takes two parameters:
-
clean_all_attached_images
- This function removes all images already attached to the HTML report for the current test scenario.
Examples
The provided methods can be used from the hooks available in the environment.py file, or directly from step definitions to attach images to the HTML report. For example:
- Example 1: Attaching an image file from a step definition
...
from behavex_images import image_attachments
@given('I take a screenshot from current page')
def step_impl(context):
image_attachments.attach_image_file(context, 'path/to/image.png')
- Example 2: Attaching an image binary from the
after_step
hook in environment.py
...
from behavex_images import image_attachments
from behavex_images.image_attachments import AttachmentsCondition
def before_all(context):
image_attachements.set_attachments_condition(context, AttachmentsCondition.ONLY_ON_FAILURE)
def after_step(context, step):
image_attachements.attach_image_binary(context, selenium_driver.get_screenshot_as_png())
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file behavex_images-3.0.7.tar.gz
.
File metadata
- Download URL: behavex_images-3.0.7.tar.gz
- Upload date:
- Size: 2.3 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 65312bd1f486987842fef8182750b0f59d0b143b6f4b1d96ce1905f9cd908867 |
|
MD5 | 1ff4d1c6074b3c9c16dc09288bd295b2 |
|
BLAKE2b-256 | 528d3878bfe660d351340c7bcac495140bfe58cc4e204f7d5368700b5f089f8d |