Skip to content

Commit

Permalink
test: make screenrecord configurable
Browse files Browse the repository at this point in the history
test: log video reports

test: fix report dir path
  • Loading branch information
saw-jan committed Sep 4, 2024
1 parent 8c67867 commit 2689b1d
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 24 deletions.
1 change: 1 addition & 0 deletions .drone.star
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,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,
},
Expand Down
1 change: 1 addition & 0 deletions test/gui/.pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ variable-naming-style=snake_case
[VARIABLES]
additional-builtins=
squish,
squishinfo,
test,
testSettings,
OnFeatureStart,
Expand Down
2 changes: 1 addition & 1 deletion test/gui/config.sample.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ TEMP_FOLDER_PATH=
CLIENT_CONFIG_DIR=
GUI_TEST_REPORT_DIR=
OCIS=false
SQUISH_REPORT_DIR=
SCREEN_RECORD_ON_FAILURE=false
16 changes: 15 additions & 1 deletion test/gui/drone/log_reports.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/$(basename "$i")"
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
47 changes: 30 additions & 17 deletions test/gui/shared/scripts/bdd_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
# cleanup spaces
Expand Down Expand Up @@ -179,23 +206,9 @@ def hook(context):
squish.saveDesktopScreenshot(os.path.join(directory, filename))

# 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()
Expand Down
8 changes: 4 additions & 4 deletions test/gui/shared/scripts/helpers/ConfigHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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)

Expand All @@ -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
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion test/gui/shared/scripts/helpers/SetupClientHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ def startClient():
+ " --logdebug"
+ " --logflush"
)
test.startVideoCapture()
if get_config("screenRecordOnFailure"):
test.startVideoCapture()


def getPollingInterval():
Expand Down

0 comments on commit 2689b1d

Please sign in to comment.