Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
{ "name": "write into excel", "function": "excel_write", "screenshot": "none" },
{ "name": "excel comparison", "function": "excel_comparison", "screenshot": "none" },
{ "name": "read from excel", "function": "excel_read", "screenshot": "none" },
{ "name": "read from csv", "function": "csv_read", "screenshot": "none" }
) # yapf: disable

module_name = "common"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
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
"""

import inspect, sys, time, collections, ftplib, os, ast, copy
import inspect, sys, time, collections, ftplib, os, ast, copy, csv
from pathlib import Path

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

return "passed"


@logger
def csv_read(data_set):
sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME
try:
filepath = None
delimiter = ","
delimiter_support = {
"comma": ",",
"semicolon": ";",
"dot": ".",
"colon": ":",
"dash": "-",
"space": " ",
"tab": "\t",
"pipe": "|",
"asterisk": "*",
"plus": "+",
"slash": "/",
"backslash": "\\",
}
var_name = ""
structure = "list of dictionaries"
for left, mid, right in data_set:
left = left.lower().strip()
if "file path" in left:
filepath = right.strip()
# Expand ~ (home directory of user) to absolute path.
if "~" in filepath:
filepath = Path(os.path.expanduser(filepath))
filepath = Path(filepath)
elif "delimiter" in left:
right = right.strip()
if right in delimiter_support:
delimiter = delimiter_support[right]
else:
delimiter = right
elif "structure of the variable" in left:
pass
if "read from csv" in left:
var_name = right.strip()

with open(filepath, "r") as csv_file:
if structure == "list of dictionaries":
csv_read_data = csv.DictReader(csv_file, delimiter=delimiter)
data_to_save = [line for line in csv_read_data]

CommonUtil.ExecLog(sModuleInfo, "Extracted CSV data with '%s' delimiter and saved data as %s format" % (delimiter, structure), 1)
sr.Set_Shared_Variables(var_name, data_to_save)
return "passed"

except:
return CommonUtil.Exception_Handler(sys.exc_info())

Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,7 @@ def Run_Sequential_Actions(
if test_action_info:
Action_name = ": '" + test_action_info[dataset_cnt]["Action name"] + "'"
Action_disabled = test_action_info[dataset_cnt]["Action disabled"]
CommonUtil.current_action_no = str(dataset_cnt + 1)
else:
Action_name = ""
Action_disabled = False
Expand Down
2 changes: 1 addition & 1 deletion Framework/MainDriverApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ def run_all_test_steps_in_a_test_case(
run_id + "|" + test_case + "|" + str(current_step_id) + "|" + str(current_step_sequence),
temp_ini_file,
)

CommonUtil.current_step_no = str(current_step_sequence)
# add log
log_line = "STEP #%d: %s" % (StepSeq, current_step_name)
print("-"*len(log_line))
Expand Down
27 changes: 11 additions & 16 deletions Framework/Utilities/CommonUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@
previous_log_line = None
teardown = True

current_action_no = ""
current_action_name = ""
current_step_no = ""
current_step_name = ""

executor = concurrent.futures.ThreadPoolExecutor()
all_threads = {}

Expand Down Expand Up @@ -641,7 +646,9 @@ def TakeScreenShot(function_name, local_run=False):
"********** Capturing Screenshot for Action: %s Method: %s **********" % (function_name, Method),
4,
)
thread = executor.submit(Thread_ScreenShot, function_name, image_folder, Method, Driver)
image_name = "Step#" + current_step_no + "_Action#" + current_action_no + "_" + str(function_name)
print(image_name)
thread = executor.submit(Thread_ScreenShot, function_name, image_folder, Method, Driver, image_name)
SaveThread("screenshot", thread)

except:
Expand All @@ -655,7 +662,7 @@ def pil_image_to_bytearray(img):
return img_byte_array


def Thread_ScreenShot(function_name, image_folder, Method, Driver):
def Thread_ScreenShot(function_name, image_folder, Method, Driver, image_name):
""" Capture screen of mobile or desktop """
sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME
chars_to_remove = [
Expand All @@ -676,20 +683,8 @@ def Thread_ScreenShot(function_name, image_folder, Method, Driver):
trans_table = str.maketrans(
dict.fromkeys("".join(chars_to_remove))
) # python3 version of translate
ImageName = os.path.join(
image_folder,
TimeStamp("utc")
+ "_"
+ (function_name.translate(trans_table)).strip().replace(" ", "_")
+ ".png",
)
ExecLog(
sModuleInfo,
"Capturing screen on %s, with driver: %s, and saving to %s"
% (str(Method), str(Driver), ImageName),
0,
)

ImageName = os.path.join(image_folder, (image_name.translate(trans_table)).strip().replace(" ", "_") + ".png")
ExecLog(sModuleInfo, "Capturing screen on %s, with driver: %s, and saving to %s" % (str(Method), str(Driver), ImageName), 0)
try:
# Capture screenshot of desktop
if Method == "desktop":
Expand Down