Skip to content

Commit 11c3d92

Browse files
authored
Merge pull request #6 from AutomationSolutionz/save_web_elements
Save web elements
2 parents 0bf2201 + fa1c2f4 commit 11c3d92

File tree

5 files changed

+70
-18
lines changed

5 files changed

+70
-18
lines changed

Framework/Built_In_Automation/Sequential_Actions/action_declarations/common.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
{ "name": "write into excel", "function": "excel_write", "screenshot": "none" },
6060
{ "name": "excel comparison", "function": "excel_comparison", "screenshot": "none" },
6161
{ "name": "read from excel", "function": "excel_read", "screenshot": "none" },
62+
{ "name": "read from csv", "function": "csv_read", "screenshot": "none" }
6263
) # yapf: disable
6364

6465
module_name = "common"

Framework/Built_In_Automation/Sequential_Actions/common_functions.py

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Caveat: Functions common to multiple Built In Functions must have action names that are unique, because we search the common functions first, regardless of the module name passed by the user
66
"""
77

8-
import inspect, sys, time, collections, ftplib, os, ast, copy
8+
import inspect, sys, time, collections, ftplib, os, ast, copy, csv
99
from pathlib import Path
1010

1111
try:
@@ -2894,3 +2894,58 @@ def execute_python_code(data_set):
28942894
CommonUtil.ExecLog(sModuleInfo, "Executed the python code which was provided", 1)
28952895

28962896
return "passed"
2897+
2898+
2899+
@logger
2900+
def csv_read(data_set):
2901+
sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME
2902+
try:
2903+
filepath = None
2904+
delimiter = ","
2905+
delimiter_support = {
2906+
"comma": ",",
2907+
"semicolon": ";",
2908+
"dot": ".",
2909+
"colon": ":",
2910+
"dash": "-",
2911+
"space": " ",
2912+
"tab": "\t",
2913+
"pipe": "|",
2914+
"asterisk": "*",
2915+
"plus": "+",
2916+
"slash": "/",
2917+
"backslash": "\\",
2918+
}
2919+
var_name = ""
2920+
structure = "list of dictionaries"
2921+
for left, mid, right in data_set:
2922+
left = left.lower().strip()
2923+
if "file path" in left:
2924+
filepath = right.strip()
2925+
# Expand ~ (home directory of user) to absolute path.
2926+
if "~" in filepath:
2927+
filepath = Path(os.path.expanduser(filepath))
2928+
filepath = Path(filepath)
2929+
elif "delimiter" in left:
2930+
right = right.strip()
2931+
if right in delimiter_support:
2932+
delimiter = delimiter_support[right]
2933+
else:
2934+
delimiter = right
2935+
elif "structure of the variable" in left:
2936+
pass
2937+
if "read from csv" in left:
2938+
var_name = right.strip()
2939+
2940+
with open(filepath, "r") as csv_file:
2941+
if structure == "list of dictionaries":
2942+
csv_read_data = csv.DictReader(csv_file, delimiter=delimiter)
2943+
data_to_save = [line for line in csv_read_data]
2944+
2945+
CommonUtil.ExecLog(sModuleInfo, "Extracted CSV data with '%s' delimiter and saved data as %s format" % (delimiter, structure), 1)
2946+
sr.Set_Shared_Variables(var_name, data_to_save)
2947+
return "passed"
2948+
2949+
except:
2950+
return CommonUtil.Exception_Handler(sys.exc_info())
2951+

Framework/Built_In_Automation/Sequential_Actions/sequential_actions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,7 @@ def Run_Sequential_Actions(
725725
if test_action_info:
726726
Action_name = ": '" + test_action_info[dataset_cnt]["Action name"] + "'"
727727
Action_disabled = test_action_info[dataset_cnt]["Action disabled"]
728+
CommonUtil.current_action_no = str(dataset_cnt + 1)
728729
else:
729730
Action_name = ""
730731
Action_disabled = False

Framework/MainDriverApi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,7 @@ def run_all_test_steps_in_a_test_case(
946946
run_id + "|" + test_case + "|" + str(current_step_id) + "|" + str(current_step_sequence),
947947
temp_ini_file,
948948
)
949-
949+
CommonUtil.current_step_no = str(current_step_sequence)
950950
# add log
951951
log_line = "STEP #%d: %s" % (StepSeq, current_step_name)
952952
print("-"*len(log_line))

Framework/Utilities/CommonUtil.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@
104104
previous_log_line = None
105105
teardown = True
106106

107+
current_action_no = ""
108+
current_action_name = ""
109+
current_step_no = ""
110+
current_step_name = ""
111+
107112
executor = concurrent.futures.ThreadPoolExecutor()
108113
all_threads = {}
109114

@@ -641,7 +646,9 @@ def TakeScreenShot(function_name, local_run=False):
641646
"********** Capturing Screenshot for Action: %s Method: %s **********" % (function_name, Method),
642647
4,
643648
)
644-
thread = executor.submit(Thread_ScreenShot, function_name, image_folder, Method, Driver)
649+
image_name = "Step#" + current_step_no + "_Action#" + current_action_no + "_" + str(function_name)
650+
print(image_name)
651+
thread = executor.submit(Thread_ScreenShot, function_name, image_folder, Method, Driver, image_name)
645652
SaveThread("screenshot", thread)
646653

647654
except:
@@ -655,7 +662,7 @@ def pil_image_to_bytearray(img):
655662
return img_byte_array
656663

657664

658-
def Thread_ScreenShot(function_name, image_folder, Method, Driver):
665+
def Thread_ScreenShot(function_name, image_folder, Method, Driver, image_name):
659666
""" Capture screen of mobile or desktop """
660667
sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME
661668
chars_to_remove = [
@@ -676,20 +683,8 @@ def Thread_ScreenShot(function_name, image_folder, Method, Driver):
676683
trans_table = str.maketrans(
677684
dict.fromkeys("".join(chars_to_remove))
678685
) # python3 version of translate
679-
ImageName = os.path.join(
680-
image_folder,
681-
TimeStamp("utc")
682-
+ "_"
683-
+ (function_name.translate(trans_table)).strip().replace(" ", "_")
684-
+ ".png",
685-
)
686-
ExecLog(
687-
sModuleInfo,
688-
"Capturing screen on %s, with driver: %s, and saving to %s"
689-
% (str(Method), str(Driver), ImageName),
690-
0,
691-
)
692-
686+
ImageName = os.path.join(image_folder, (image_name.translate(trans_table)).strip().replace(" ", "_") + ".png")
687+
ExecLog(sModuleInfo, "Capturing screen on %s, with driver: %s, and saving to %s" % (str(Method), str(Driver), ImageName), 0)
693688
try:
694689
# Capture screenshot of desktop
695690
if Method == "desktop":

0 commit comments

Comments
 (0)