Open Yaswanthbobbu opened 2 weeks ago
Hi @Yaswanthbobbu, I was checking your code and I see some things:
1- In the following line:
image_attachments.set_attachments_condition(context.driver, AttachmentsCondition.ONLY_ON_FAILURE)
You should only pass the context variable, instead of context.driver. Like this:
image_attachments.set_attachments_condition(context, AttachmentsCondition.ONLY_ON_FAILURE)
2- You don't need to check if the scenario passed or failed, the attachments condition will do it for you, so this statement is not necessary:
if run_type == 'parallel' and step.status == 'failed'
In the same line, the screenshots from previous steps will not be stored if you are storing the screenshots only if a step failed.
When setting AttachmentsCondition.ONLY_ON_FAILURE, if the scenario failed, it will store the screenshots from the failing and the previous steps and show them in the gallery, and if the scenario passed, all the screenshots will be discarded.
Please, keep me posted on this. Thanks!
Hello hrcorval,
Thanks a ton for your kind response.. still i couldnt see any image in the html report
im now simply using
def before_all(context): image_attachments.set_attachments_condition(context, AttachmentsCondition.ONLY_ON_FAILURE)
def after_step(context, step): try: image_attachments.attach_image_binary(context, context.driver.get_screenshot_as_png()) except Exception as error: print(f"Failed to take screenshot for parallel run: {error}")
below is error:
HOOK-ERROR in after_step: AttributeError: type object 'AttachmentsCondition' has no attribute 'ON_FAILURE'
After successful execution no images are stored in img_attachement_utils folder and nothing in html report. could you please help me
Hi @Yaswanthbobbu , thanks for the feedback you provided, it was very useful to identify a bug in the behavex-images library. The bug was fixed and the release version 3.0.7 is ready to use.
You can update the library in your project. Not sure which tool you use to install all libraries, but here you have a couple of examples with pip
, and also pipenv
:
pip install behavex-images --upgrade
pipenv update behavex-images
I hope that with this change you start seeing the image gallery. Otherwise, we can continue working to ensure it works. Thanks,
Hello @hrcorval
Thank you very much.. for taking some time to respond.. I have upgraded but still i doesnt work
below are the snippets of code for your ref
bdd_runner.py file has below command
def parallel_run_tests(tag, result_dir, num): parallel_results_dir = os.path.join(result_dir, "allure-results") parallel_reports_dir = os.path.join(result_dir, "allure-report") command = [ 'behavex', 'tests/bdd', f'-t={tag}', '--tags=~@wip', '--tags=~@skip', '--tags=~@ok-to-fail', f'--parallel-processes={num}', '--parallel-scheme=feature', '-o', parallel_results_dir ] subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
subprocess.run(['allure', 'generate', parallel_results_dir, '-o', parallel_reports_dir, '--clean'], shell=True)
subprocess.run(['allure', 'open', parallel_results_dir], shell=True) # >> using parallel_report_dir doesnt generate behavex html report
environment.py file has
def before_all(context): if hasattr(context, 'driver'): image_attachments.set_attachments_condition(context, AttachmentsCondition.ONLY_ON_FAILURE)
def after_step(context, step): run_type = os.getenv('RUN_TYPE', 'dry') screenshot = context.driver.get_screenshot_as_png() if run_type == 'dry': screenshot_name = getattr(step, 'name', 'Unnamed Step') allure.attach(screenshot, name=screenshot_name, attachment_type=AttachmentType.PNG) if run_type == 'parallel': image_attachments.attach_image_binary(context, screenshot)
image_attachments_utils doesnt have any images stored.
also using @AUTORETRY (for failed) below info is shown on console
Another program is using the files in path .\allure-results\outputs\logs\image_attachments_utils. Please, close the program and press 'c' to continue or 'a' for abort. Retry number 2
any guidance would be appreciated
Hi @Yaswanthbobbu, your feedback is very important to determine the root cause of the issue. Considering you are seeing the "image_attachments_utils" folder empty and the "Another program is using the files in path..." message when performing a retry, I can infere the issue is relate with the write privileges on the executing processes over the output folder.
The behavex-images library, executes the following command to copy all assets into the image_attachments_utils
folder:
shutil.copytree(image_attachments_path, destination_path)
(https://github.com/abmercado19/behavex-images/blob/master/behavex_images/extend_environment.py#L261)
Also, when you get the "Another program is using the files in path..." message when performing a retry, this is because the files generated from previous execution could not be removed, due to there is another process still using the files from previous executions or the test execution process does not have privileges to remove the files.
Considering your evidence, I would take the path of reviewing the read/write privileges of the test execution processes over the output folder.
Please, keeps us posted on that. Thanks!
Hi @hrcorval
Firstly thanks for your response.. and slight correction (to avoid any misleading please) I have told image_attachments_utils doesn't have any images stored. but not empty ( it has all support/generic files that are present by befault)
attached screenshot
just to add when we use clean_all_attached_images method
def after_all(context): image_attachments.clean_all_attached_images(context) if hasattr(context, 'driver'): context.driver.quit()
we get error as HOOK-ERROR in after_all: AttributeError: 'Context' object has no attribute 'bhximgs_log_stream' how ever i'm avoiding it by using
if hasattr(context, 'bhximgs_log_stream'): image_attachments.clean_all_attached_images(context)
Hello hrcorval,
Could you please help me fix this, below are details of before_all and after step definitions
def before_all(context): run_type = os.getenv('RUN_TYPE', 'dry') if run_type == 'parallel': if hasattr(context, 'driver'): image_attachments.set_attachments_condition(context.driver, AttachmentsCondition.ONLY_ON_FAILURE) else: pass
def after_step(context, step): run_type = os.getenv('RUN_TYPE', 'dry') if run_type == 'parallel' and step.status == 'failed': screenshotname = f"{step.name}{threading.get_ident()}.png" screenshot_path = os.path.join(os.getcwd(), f'screenshots/', screenshot_name)
create_folder(screenshot_path)
is the report generated with out image icon
could you please guide