Skip to content

Commit

Permalink
test: generate screenrecords on test failure
Browse files Browse the repository at this point in the history
  • Loading branch information
saw-jan committed Sep 4, 2024
1 parent b48c08b commit 5f57355
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
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
SQUISH_REPORT_DIR=
30 changes: 29 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,14 @@ 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"


# runs after every scenario
# Order: 1
@OnScenarioEnd
Expand All @@ -151,7 +160,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 +169,25 @@ def hook(context):
except:
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))

# teardown accounts and configs
teardown_client()

Expand Down
2 changes: 2 additions & 0 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',
'squishReportDir': 'SQUISH_REPORT_DIR',
}

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

Expand Down
1 change: 1 addition & 0 deletions test/gui/shared/scripts/helpers/SetupClientHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def startClient():
+ " --logdebug"
+ " --logflush"
)
test.startVideoCapture()


def getPollingInterval():
Expand Down

0 comments on commit 5f57355

Please sign in to comment.