@@ -128,6 +128,8 @@ def __initialize_variables(self):
128128 self.__start_time_ms = int(time.time() * 1000.0)
129129 self.__requests_timeout = None
130130 self.__screenshot_count = 0
131+ self.__logs_data_count = 0
132+ self.__last_data_file = None
131133 self.__level_0_visual_f = False
132134 self.__will_be_skipped = False
133135 self.__passed_then_skipped = False
@@ -831,9 +833,9 @@ def click_chain(
831833 """This method clicks on a list of elements in succession.
832834 @Params
833835 selectors_list - The list of selectors to click on.
834- by - The type of selector to search by (Default: CSS_Selector ).
836+ by - The type of selector to search by (Default: "css selector" ).
835837 timeout - How long to wait for the selector to be visible.
836- spacing - The amount of time to wait between clicks (in seconds). """
838+ spacing - The amount of time to wait between clicks (in seconds)."""
837839 self.__check_scope()
838840 if not timeout:
839841 timeout = settings.SMALL_TIMEOUT
@@ -855,11 +857,11 @@ def update_text(
855857 * Types in the new text.
856858 * Hits Enter/Submit (if the text ends in "\n").
857859 @Params
858- selector - the selector of the text field
859- text - the new text to type into the text field
860- by - the type of selector to search by (Default: CSS Selector )
861- timeout - how long to wait for the selector to be visible
862- retry - if True, use JS if the Selenium text update fails """
860+ selector - The selector of the text field.
861+ text - The new text to type into the text field.
862+ by - The type of selector to search by. (Default: "css selector" )
863+ timeout - How long to wait for the selector to be visible.
864+ retry - If True, use JS if the Selenium text update fails. """
863865 self.__check_scope()
864866 if not timeout:
865867 timeout = settings.LARGE_TIMEOUT
@@ -1037,11 +1039,11 @@ def type(
10371039 * Types in the new text.
10381040 * Hits Enter/Submit (if the text ends in "\n").
10391041 @Params
1040- selector - the selector of the text field
1041- text - the new text to type into the text field
1042- by - the type of selector to search by (Default: CSS Selector )
1043- timeout - how long to wait for the selector to be visible
1044- retry - if True, use JS if the Selenium text update fails
1042+ selector - The selector of the text field.
1043+ text - The new text to type into the text field.
1044+ by - The type of selector to search by. (Default: "css selector" )
1045+ timeout - How long to wait for the selector to be visible.
1046+ retry - If True, use JS if the Selenium text update fails.
10451047 DO NOT confuse self.type() with Python type()! They are different!
10461048 """
10471049 self.__check_scope()
@@ -1083,9 +1085,9 @@ def clear(self, selector, by="css selector", timeout=None):
10831085 In case websites trigger an autofill after clearing a field,
10841086 add backspaces to make sure autofill doesn't undo the clear.
10851087 @Params
1086- selector - the selector of the text field
1087- by - the type of selector to search by (Default: CSS Selector )
1088- timeout - how long to wait for the selector to be visible """
1088+ selector - The selector of the text field.
1089+ by - The type of selector to search by. (Default: "css selector" )
1090+ timeout - How long to wait for the selector to be visible. """
10891091 self.__check_scope()
10901092 if not timeout:
10911093 timeout = settings.LARGE_TIMEOUT
@@ -4002,6 +4004,49 @@ def save_screenshot_to_logs(
40024004 sb_config._has_logs = True
40034005 return page_actions.save_screenshot(self.driver, name, test_logpath)
40044006
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+
40054050 def save_page_source(self, name, folder=None):
40064051 """Saves the page HTML to the current directory (or given subfolder).
40074052 If the folder specified doesn't exist, it will get created.
@@ -6580,7 +6625,9 @@ def append_data_to_file(self, data, file_name, destination_folder=None):
65806625 def get_file_data(self, file_name, folder=None):
65816626 """Gets the data from the file specified.
65826627 If no folder is specified, the default one is used.
6583- (The default folder = "./downloaded_files")
6628+ The default folder = "./downloaded_files"
6629+ For the "latest_logs/" test data folders, use:
6630+ self.data_path OR self.data_abspath
65846631 Use "." as the folder for the current directory."""
65856632 if not folder:
65866633 folder = constants.Files.DOWNLOADS_FOLDER
@@ -8292,7 +8339,7 @@ def post_message_and_highlight(self, message, selector, by="css selector"):
82928339 Arguments:
82938340 message: The message to display.
82948341 selector: The selector of the Element to highlight.
8295- by: The type of selector to search by. (Default: CSS Selector )"""
8342+ by: The type of selector to search by. (Default: "css selector" )"""
82968343 self.__check_scope()
82978344 self.__highlight_with_assert_success(message, selector, by=by)
82988345
@@ -14389,6 +14436,7 @@ def __process_dashboard(self, has_exception, init=False):
1438914436 has_exception
1439014437 or self.save_screenshot_after_test
1439114438 or self.__screenshot_count > 0
14439+ or self.__logs_data_count > 0
1439214440 or self.__level_0_visual_f
1439314441 or self.__will_be_skipped
1439414442 ):
0 commit comments