@@ -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
@@ -831,9 +833,9 @@ def click_chain(
831
833
"""This method clicks on a list of elements in succession.
832
834
@Params
833
835
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" ).
835
837
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)."""
837
839
self.__check_scope()
838
840
if not timeout:
839
841
timeout = settings.SMALL_TIMEOUT
@@ -855,11 +857,11 @@ def update_text(
855
857
* Types in the new text.
856
858
* Hits Enter/Submit (if the text ends in "\n").
857
859
@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. """
863
865
self.__check_scope()
864
866
if not timeout:
865
867
timeout = settings.LARGE_TIMEOUT
@@ -1037,11 +1039,11 @@ def type(
1037
1039
* Types in the new text.
1038
1040
* Hits Enter/Submit (if the text ends in "\n").
1039
1041
@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.
1045
1047
DO NOT confuse self.type() with Python type()! They are different!
1046
1048
"""
1047
1049
self.__check_scope()
@@ -1083,9 +1085,9 @@ def clear(self, selector, by="css selector", timeout=None):
1083
1085
In case websites trigger an autofill after clearing a field,
1084
1086
add backspaces to make sure autofill doesn't undo the clear.
1085
1087
@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. """
1089
1091
self.__check_scope()
1090
1092
if not timeout:
1091
1093
timeout = settings.LARGE_TIMEOUT
@@ -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.
@@ -6580,7 +6625,9 @@ def append_data_to_file(self, data, file_name, destination_folder=None):
6580
6625
def get_file_data(self, file_name, folder=None):
6581
6626
"""Gets the data from the file specified.
6582
6627
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
6584
6631
Use "." as the folder for the current directory."""
6585
6632
if not folder:
6586
6633
folder = constants.Files.DOWNLOADS_FOLDER
@@ -8292,7 +8339,7 @@ def post_message_and_highlight(self, message, selector, by="css selector"):
8292
8339
Arguments:
8293
8340
message: The message to display.
8294
8341
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" )"""
8296
8343
self.__check_scope()
8297
8344
self.__highlight_with_assert_success(message, selector, by=by)
8298
8345
@@ -14389,6 +14436,7 @@ def __process_dashboard(self, has_exception, init=False):
14389
14436
has_exception
14390
14437
or self.save_screenshot_after_test
14391
14438
or self.__screenshot_count > 0
14439
+ or self.__logs_data_count > 0
14392
14440
or self.__level_0_visual_f
14393
14441
or self.__will_be_skipped
14394
14442
):
0 commit comments