Last active
August 10, 2021 00:34
-
-
Save BrunoMoraes-Z/d83b19dedf65c6d01909af53f7ff32ca to your computer and use it in GitHub Desktop.
a Listener for RobotFramework in a way that allows you to organize the screenshots by suite and by scene (robot -d results --listener screenshot_listener.py cases/scenarios.robot)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from robot.libraries.BuiltIn import BuiltIn | |
import os.path | |
from pathlib import Path | |
ROBOT_LISTENER_API_VERSION = 2 | |
def start_test(name, attributes): | |
separator = BuiltIn().get_variable_value('${/}') | |
output = BuiltIn().get_variable_value('${OUTPUT_DIR}') | |
execd = BuiltIn().get_variable_value('${EXECDIR}') | |
test = _normalize(name) | |
suite = BuiltIn().get_variable_value('${SUITE_NAME}') | |
path = Path(f'{output.split(separator)[-1:][0]}{separator}{suite}{separator}{test}') | |
BuiltIn().run_keyword('Set Screenshot Directory', path) | |
def _normalize(input: str): | |
return ''.join(x for x in input if x.isalnum()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment