Skip to content

Commit

Permalink
[gui-tests][full-ci] configurable capture video for GUI tests (#11857)
Browse files Browse the repository at this point in the history
* test: generate screenrecords on test failure

* test: make screenrecord configurable

test: log video reports

test: fix report dir path
  • Loading branch information
saw-jan authored Sep 9, 2024
1 parent b48c08b commit 7041dcd
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 5 deletions.
1 change: 1 addition & 0 deletions .drone.star
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
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
3 changes: 2 additions & 1 deletion test/gui/config.sample.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ CLIENT_LOG_FILE=
TEMP_FOLDER_PATH=
CLIENT_CONFIG_DIR=
GUI_TEST_REPORT_DIR=
OCIS=false
OCIS=false
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/$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
43 changes: 42 additions & 1 deletion test/gui/shared/scripts/bdd_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# manual for a complete reference of the available API.
import shutil
import os
import glob
from urllib import request, error
from datetime import datetime

Expand Down Expand Up @@ -141,6 +142,41 @@ def scenario_failed():
)


def get_screenshot_name(title):
return title.replace(" ", "_").replace("/", "_").strip(".") + ".png"


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
Expand All @@ -151,7 +187,7 @@ def hook(context):
# capture a screenshot if there is error or test failure in the current scenario execution
if scenario_failed() and os.getenv("CI") and isLinux():
# scenario name can have "/" which is invalid filename
filename = context.title.replace(" ", "_").replace("/", "_").strip(".") + ".png"
filename = get_screenshot_name(context.title)
directory = os.path.join(get_config("guiTestReportDir"), "screenshots")
if not os.path.exists(directory):
os.makedirs(directory)
Expand All @@ -160,6 +196,11 @@ def hook(context):
except:
test.log("Failed to save screenshot")

# check video report
if get_config("screenRecordOnFailure"):
filename = get_screenrecord_name(context.title)
save_screenrecord(filename)

# teardown accounts and configs
teardown_client()

Expand Down
6 changes: 4 additions & 2 deletions test/gui/shared/scripts/helpers/ConfigHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def get_default_home_dir():
'clientConfigDir': 'CLIENT_CONFIG_DIR',
'guiTestReportDir': 'GUI_TEST_REPORT_DIR',
'ocis': 'OCIS',
'screenRecordOnFailure': 'SCREEN_RECORD_ON_FAILURE',
}

DEFAULT_PATH_CONFIG = {
Expand All @@ -95,6 +96,7 @@ def get_default_home_dir():
'clientConfigDir': getConfigHome(),
'guiTestReportDir': os.path.abspath('../reports'),
'ocis': False,
'screenRecordOnFailure': False,
}
CONFIG.update(DEFAULT_PATH_CONFIG)

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


def getPollingInterval():
Expand Down

0 comments on commit 7041dcd

Please sign in to comment.