-
Notifications
You must be signed in to change notification settings - Fork 667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[gui-tests][full-ci] retry failed scenario #11920
Open
saw-jan
wants to merge
2
commits into
master
Choose a base branch
from
tests/retry-failed-test
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+122
−74
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -73,12 +73,14 @@ def get_default_home_dir(): | |||||
'clientConfigDir': 'CLIENT_CONFIG_DIR', | ||||||
'guiTestReportDir': 'GUI_TEST_REPORT_DIR', | ||||||
'ocis': 'OCIS', | ||||||
'screenRecordOnFailure': 'SCREEN_RECORD_ON_FAILURE', | ||||||
'recordVideoOnFailure': 'RECORD_VIDEO_ON_FAILURE', | ||||||
} | ||||||
|
||||||
DEFAULT_PATH_CONFIG = { | ||||||
'custom_lib': os.path.abspath('../shared/scripts/custom_lib'), | ||||||
'home_dir': get_default_home_dir(), | ||||||
# allow to record first 5 videos | ||||||
'videoRecordLimit': 5, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
|
||||||
# default config values | ||||||
|
@@ -95,20 +97,24 @@ def get_default_home_dir(): | |||||
'clientConfigDir': get_config_home(), | ||||||
'guiTestReportDir': os.path.abspath('../reports'), | ||||||
'ocis': False, | ||||||
'screenRecordOnFailure': False, | ||||||
'recordVideoOnFailure': False, | ||||||
'retrying': False, | ||||||
'videoRecordingStarted': False, | ||||||
} | ||||||
CONFIG.update(DEFAULT_PATH_CONFIG) | ||||||
|
||||||
READONLY_CONFIG = list(CONFIG_ENV_MAP.keys()) + list(DEFAULT_PATH_CONFIG.keys()) | ||||||
|
||||||
SCENARIO_CONFIGS = {} | ||||||
|
||||||
|
||||||
def read_cfg_file(cfg_path): | ||||||
cfg = ConfigParser() | ||||||
if cfg.read(cfg_path): | ||||||
for key, _ in CONFIG.items(): | ||||||
if key in CONFIG_ENV_MAP: | ||||||
if value := cfg.get('DEFAULT', CONFIG_ENV_MAP[key]): | ||||||
if key in ('ocis', 'screenRecordOnFailure'): | ||||||
if key in ('ocis', 'recordVideoOnFailure'): | ||||||
CONFIG[key] = value == 'true' | ||||||
else: | ||||||
CONFIG[key] = value | ||||||
|
@@ -128,7 +134,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 in ('ocis', 'screenRecordOnFailure'): | ||||||
if key in ('ocis', 'recordVideoOnFailure'): | ||||||
CONFIG[key] = os.environ.get(value) == 'true' | ||||||
else: | ||||||
CONFIG[key] = os.environ.get(value) | ||||||
|
@@ -154,22 +160,19 @@ def init_config(): | |||||
CONFIG[key] = value.rstrip('/') + '/' | ||||||
|
||||||
|
||||||
def get_config(key=None): | ||||||
if key: | ||||||
return CONFIG[key] | ||||||
return CONFIG | ||||||
def get_config(key): | ||||||
return CONFIG[key] | ||||||
|
||||||
|
||||||
def set_config(key, value): | ||||||
if key in READONLY_CONFIG: | ||||||
raise KeyError(f'Cannot set read-only config: {key}') | ||||||
# save the initial config value | ||||||
if key not in SCENARIO_CONFIGS: | ||||||
SCENARIO_CONFIGS[key] = CONFIG.get(key) | ||||||
CONFIG[key] = value | ||||||
|
||||||
|
||||||
def clear_scenario_config(): | ||||||
global CONFIG | ||||||
initial_config = {} | ||||||
for key in READONLY_CONFIG: | ||||||
initial_config[key] = CONFIG[key] | ||||||
|
||||||
CONFIG = initial_config | ||||||
for key, value in SCENARIO_CONFIGS.items(): | ||||||
CONFIG[key] = value |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import os | ||
import glob | ||
import shutil | ||
import test | ||
import squish | ||
import squishinfo | ||
|
||
from helpers.ConfigHelper import get_config | ||
from helpers.FilesHelper import prefix_path_namespace | ||
|
||
|
||
def get_screenrecords_path(): | ||
return os.path.join(get_config("guiTestReportDir"), "screenrecords") | ||
|
||
|
||
def get_screenshots_path(): | ||
return os.path.join(get_config("guiTestReportDir"), "screenshots") | ||
|
||
|
||
def is_video_enabled(): | ||
return ( | ||
get_config("recordVideoOnFailure") | ||
or get_config("retrying") | ||
and not reached_video_limit() | ||
) | ||
|
||
|
||
def reached_video_limit(): | ||
video_report_dir = get_screenrecords_path() | ||
if not os.path.exists(video_report_dir): | ||
return False | ||
entries = [f for f in os.scandir(video_report_dir) if f.is_file()] | ||
return len(entries) >= get_config("videoRecordLimit") | ||
|
||
|
||
def save_video_recording(filename, test_failed): | ||
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 the test failed | ||
# move videos to the screenrecords directory | ||
if test_failed: | ||
video_files = glob.glob(f"{video_dir}/**/*.mp4", recursive=True) | ||
screenrecords_dir = get_screenrecords_path() | ||
if not os.path.exists(screenrecords_dir): | ||
os.makedirs(screenrecords_dir) | ||
# reverse the list to get the latest video first | ||
video_files.reverse() | ||
for idx, video in enumerate(video_files): | ||
if idx: | ||
file_parts = filename.rsplit(".", 1) | ||
filename = f"{file_parts[0]}_{idx+1}.{file_parts[1]}" | ||
shutil.move(video, os.path.join(screenrecords_dir, filename)) | ||
# remove the video directory | ||
shutil.rmtree(prefix_path_namespace(video_dir)) | ||
|
||
|
||
def take_screenshot(filename): | ||
directory = get_screenshots_path() | ||
if not os.path.exists(directory): | ||
os.makedirs(directory) | ||
try: | ||
squish.saveDesktopScreenshot(os.path.join(directory, filename)) | ||
except: | ||
test.log("Failed to save screenshot") |
This file contains 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about writing these attributes in snake_case?