@@ -128,6 +128,8 @@ def __initialize_variables(self):
128
128
self.__start_time_ms = int(time.time() * 1000.0)
129
129
self.__requests_timeout = None
130
130
self.__screenshot_count = 0
131
+ self.__logs_data_count = 0
132
+ self.__last_data_file = None
131
133
self.__level_0_visual_f = False
132
134
self.__will_be_skipped = False
133
135
self.__passed_then_skipped = False
@@ -4002,6 +4004,49 @@ def save_screenshot_to_logs(
4002
4004
sb_config._has_logs = True
4003
4005
return page_actions.save_screenshot(self.driver, name, test_logpath)
4004
4006
4007
+ def save_data_to_logs(self, data, file_name=None):
4008
+ """Saves data to the "latest_logs/" data folder of the current test.
4009
+ If no file_name, file_name becomes: "data_1.txt", "data_2.txt", etc.
4010
+ Useful variables for getting the "latest_logs/" or test data folders:
4011
+ self.log_path OR self.log_abspath (For the top-level folder)
4012
+ self.data_path OR self.data_abspath (Individual test folders)
4013
+ If a file_name is given with no extension, adds ".txt" to the end."""
4014
+ test_logpath = os.path.join(self.log_path, self.__get_test_id())
4015
+ self.__create_log_path_as_needed(test_logpath)
4016
+ if file_name:
4017
+ file_name = str(file_name)
4018
+ if not file_name or len(file_name) == 0:
4019
+ self.__logs_data_count += 1
4020
+ file_name = "data_%s.txt" % self.__logs_data_count
4021
+ elif "." not in file_name:
4022
+ file_name = "%s.txt" % file_name
4023
+ self.__last_data_file = file_name
4024
+ sb_config._has_logs = True
4025
+ destination_folder = test_logpath
4026
+ page_utils._save_data_as(data, destination_folder, file_name)
4027
+
4028
+ def append_data_to_logs(self, data, file_name=None):
4029
+ """Saves data to the "latest_logs/" folder of the current test.
4030
+ If no file_name, file_name becomes the last data file used in
4031
+ save_data_to_logs() or append_data_to_logs().
4032
+ If neither method was called before, creates "data_1.txt"."""
4033
+ test_logpath = os.path.join(self.log_path, self.__get_test_id())
4034
+ self.__create_log_path_as_needed(test_logpath)
4035
+ if file_name:
4036
+ file_name = str(file_name)
4037
+ if (not file_name or len(file_name) == 0) and self.__last_data_file:
4038
+ file_name = self.__last_data_file
4039
+ elif not file_name or len(file_name) == 0:
4040
+ if self.__logs_data_count == 0:
4041
+ self.__logs_data_count += 1
4042
+ file_name = "data_%s.txt" % self.__logs_data_count
4043
+ elif "." not in file_name:
4044
+ file_name = "%s.txt" % file_name
4045
+ self.__last_data_file = file_name
4046
+ sb_config._has_logs = True
4047
+ destination_folder = test_logpath
4048
+ page_utils._append_data_to_file(data, destination_folder, file_name)
4049
+
4005
4050
def save_page_source(self, name, folder=None):
4006
4051
"""Saves the page HTML to the current directory (or given subfolder).
4007
4052
If the folder specified doesn't exist, it will get created.
@@ -14389,6 +14434,7 @@ def __process_dashboard(self, has_exception, init=False):
14389
14434
has_exception
14390
14435
or self.save_screenshot_after_test
14391
14436
or self.__screenshot_count > 0
14437
+ or self.__logs_data_count > 0
14392
14438
or self.__level_0_visual_f
14393
14439
or self.__will_be_skipped
14394
14440
):
0 commit comments