diff --git a/.drone.star b/.drone.star index 2c2984e20e4..567ea3b3fef 100644 --- a/.drone.star +++ b/.drone.star @@ -331,6 +331,7 @@ def gui_tests(squish_parameters = "", server_type = "oc10"): "STACKTRACE_FILE": "%s/stacktrace.log" % dir["guiTestReport"], "PLAYWRIGHT_BROWSERS_PATH": "%s/.playwright" % dir["base"], "OWNCLOUD_CORE_DUMP": 1, + "SCREEN_RECORD_ON_FAILURE": False, # allow to use any available pnpm version "COREPACK_ENABLE_STRICT": 0, }, diff --git a/test/gui/.pylintrc b/test/gui/.pylintrc index c8730bf40b0..70ffcbf4e7d 100644 --- a/test/gui/.pylintrc +++ b/test/gui/.pylintrc @@ -40,6 +40,7 @@ variable-naming-style=snake_case [VARIABLES] additional-builtins= squish, + squishinfo, test, testSettings, OnFeatureStart, diff --git a/test/gui/config.sample.ini b/test/gui/config.sample.ini index 495d6db2a81..1c374b19dc1 100644 --- a/test/gui/config.sample.ini +++ b/test/gui/config.sample.ini @@ -11,4 +11,4 @@ TEMP_FOLDER_PATH= CLIENT_CONFIG_DIR= GUI_TEST_REPORT_DIR= OCIS=false -SQUISH_REPORT_DIR= \ No newline at end of file +SCREEN_RECORD_ON_FAILURE=false \ No newline at end of file diff --git a/test/gui/drone/log_reports.sh b/test/gui/drone/log_reports.sh index 921d833005e..cab3ad4a4ce 100644 --- a/test/gui/drone/log_reports.sh +++ b/test/gui/drone/log_reports.sh @@ -38,6 +38,20 @@ check_log "stacktrace.log" "Stacktrace" if [[ -d "${REPORT_DIR}/screenshots" ]]; then echo -e "Screenshots:" for i in "${REPORT_DIR}"/screenshots/*.png; do - echo -e "\t - ${LOG_URL_PATH}/screenshots/$(basename "$i")" + filename=$(basename "$i") + if [ "$filename" != "*.png" ]; then + echo -e "\t - ${LOG_URL_PATH}/screenshots/$filename" + fi + done +fi + +# check screenrecords +if [[ -d "${REPORT_DIR}/screenrecords" ]]; then + echo -e "Videos:" + for i in "${REPORT_DIR}"/screenrecords/*.mp4; do + filename=$(basename "$i") + if [ "$filename" != "*.mp4" ]; then + echo -e "\t - ${LOG_URL_PATH}/screenrecords/$filename" + fi done fi diff --git a/test/gui/shared/scripts/bdd_hooks.py b/test/gui/shared/scripts/bdd_hooks.py index 00680e2199f..e03496eaec2 100644 --- a/test/gui/shared/scripts/bdd_hooks.py +++ b/test/gui/shared/scripts/bdd_hooks.py @@ -150,6 +150,33 @@ def get_screenrecord_name(title): return title.replace(" ", "_").replace("/", "_").strip(".") + ".mp4" +def save_screenrecord(filename): + try: + # do not throw if stopVideoCapture() fails + test.stopVideoCapture() + except: + test.log("Failed to stop screen recording") + + if not (video_dir := squishinfo.resultDir): + video_dir = squishinfo.testCase + else: + test_case = "/".join(squishinfo.testCase.split("/")[-2:]) + video_dir = os.path.join(video_dir, test_case) + video_dir = os.path.join(video_dir, "attachments") + + if scenario_failed(): + video_files = glob.glob(f"{video_dir}/**/*.mp4", recursive=True) + screenrecords_dir = os.path.join( + get_config("guiTestReportDir"), "screenrecords" + ) + if not os.path.exists(screenrecords_dir): + os.makedirs(screenrecords_dir) + if video_files: + shutil.move(video_files[0], os.path.join(screenrecords_dir, filename)) + + shutil.rmtree(prefix_path_namespace(video_dir)) + + # runs after every scenario # Order: 1 @OnScenarioEnd @@ -170,23 +197,9 @@ def hook(context): test.log("Failed to save screenshot") # check video report - test.stopVideoCapture() - squish_test_report_dir = os.path.join(get_config("squishReportDir"), "Test Results") - for entry in os.scandir(squish_test_report_dir): - if entry.is_dir(): - if scenario_failed(): - video_files = glob.glob( - squish_test_report_dir + "/**/*.mp4", recursive=True - ) - if video_files: - filename = get_screenrecord_name(context.title) - video_dir = os.path.join( - get_config("guiTestReportDir"), "screenrecords" - ) - if not os.path.exists(video_dir): - os.makedirs(video_dir) - shutil.move(video_files[0], os.path.join(video_dir, filename)) - shutil.rmtree(prefix_path_namespace(entry.path)) + if get_config("screenRecordOnFailure"): + filename = get_screenrecord_name(context.title) + save_screenrecord(filename) # teardown accounts and configs teardown_client() diff --git a/test/gui/shared/scripts/helpers/ConfigHelper.py b/test/gui/shared/scripts/helpers/ConfigHelper.py index 17350e346c3..06c4f812453 100644 --- a/test/gui/shared/scripts/helpers/ConfigHelper.py +++ b/test/gui/shared/scripts/helpers/ConfigHelper.py @@ -74,7 +74,7 @@ def get_default_home_dir(): 'clientConfigDir': 'CLIENT_CONFIG_DIR', 'guiTestReportDir': 'GUI_TEST_REPORT_DIR', 'ocis': 'OCIS', - 'squishReportDir': 'SQUISH_REPORT_DIR', + 'screenRecordOnFailure': 'SCREEN_RECORD_ON_FAILURE', } DEFAULT_PATH_CONFIG = { @@ -96,7 +96,7 @@ def get_default_home_dir(): 'clientConfigDir': getConfigHome(), 'guiTestReportDir': os.path.abspath('../reports'), 'ocis': False, - 'squishReportDir': os.environ.get("HOME") + '/.squish', + 'screenRecordOnFailure': False, } CONFIG.update(DEFAULT_PATH_CONFIG) @@ -117,7 +117,7 @@ def init_config(): if key in CONFIG_ENV_MAP: value = cfg.get('DEFAULT', CONFIG_ENV_MAP[key]) if value: - if key == 'ocis': + if key == 'ocis' or key == 'screenRecordOnFailure': CONFIG[key] = value == 'true' else: CONFIG[key] = value @@ -127,7 +127,7 @@ def init_config(): # read and override configs from environment variables for key, value in CONFIG_ENV_MAP.items(): if os.environ.get(value): - if key == 'ocis': + if key == 'ocis' or key == 'screenRecordOnFailure': CONFIG[key] = os.environ.get(value) == 'true' else: CONFIG[key] = os.environ.get(value) diff --git a/test/gui/shared/scripts/helpers/SetupClientHelper.py b/test/gui/shared/scripts/helpers/SetupClientHelper.py index fef9e6e6a0e..49c2bf3e07b 100644 --- a/test/gui/shared/scripts/helpers/SetupClientHelper.py +++ b/test/gui/shared/scripts/helpers/SetupClientHelper.py @@ -100,7 +100,8 @@ def startClient(): + " --logdebug" + " --logflush" ) - test.startVideoCapture() + if get_config("screenRecordOnFailure"): + test.startVideoCapture() def getPollingInterval():