Skip to content

Commit 3718f11

Browse files
Merge pull request #487 from AutomationSolutionz/exit_tc_2
[Add] Test case exit action is added
2 parents 81c998a + b4a81e0 commit 3718f11

5 files changed

Lines changed: 86 additions & 47 deletions

File tree

Framework/Built_In_Automation/Sequential_Actions/action_declarations/common.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
{ "name": "delete shared variables", "function": "delete_all_shared_variables", "screenshot": "none" },
1313
{ "name": "settings", "function": "sequential_actions_settings", "screenshot": "none" },
1414
{ "name": "step exit", "function": "step_exit", "screenshot": "none" },
15+
{ "name": "testcase exit", "function": "testcase_exit", "screenshot": "none" },
1516
{ "name": "save time", "function": "Save_Current_Time", "screenshot": "none" },
1617
{ "name": "create or append list into list", "function": "insert_list_into_another_list", "screenshot": "none" },
1718
{ "name": "validate order", "function": "validate_list_order", "screenshot": "none" },

Framework/Built_In_Automation/Sequential_Actions/common_functions.py

Lines changed: 72 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -546,26 +546,56 @@ def step_exit(data_set):
546546
try:
547547
action_value = ""
548548
msg = ""
549-
for row in data_set:
550-
if row[0] == "step exit" and row[1] == "action":
551-
action_value = row[2]
552-
elif row[0].strip().lower() == "message":
553-
msg = row[2]
549+
for left, mid, right in data_set:
550+
if left.lower().strip() == "step exit":
551+
action_value = right.strip().lower()
552+
elif left.strip().lower() == "message":
553+
msg = right
554+
554555
except:
555556
return CommonUtil.Exception_Handler(sys.exc_info())
556557

557-
if (
558-
action_value in failed_tag_list
559-
): # Convert user specified pass/fail into standard result
560-
if msg:
561-
CommonUtil.ExecLog(sModuleInfo, f'{msg}', 3)
558+
if msg:
559+
CommonUtil.ExecLog(sModuleInfo, msg, 3 if "fail" in action_value else 1)
560+
if "fail" in action_value:
562561
return "zeuz_failed"
563-
elif action_value in skipped_tag_list:
564-
return "skipped"
565-
elif action_value in passed_tag_list:
566-
if msg:
567-
CommonUtil.ExecLog(sModuleInfo, f'{msg}', 1)
562+
elif "pass" in action_value:
563+
return "passed"
564+
else:
565+
CommonUtil.ExecLog(sModuleInfo, "Step Result action has invalid VALUE", 3)
566+
return "zeuz_failed"
567+
568+
569+
def testcase_exit(data_set):
570+
""" Exits a Test Step wtih passed/failed in the standard format, when the user specifies it in the step data """
571+
572+
sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME
573+
574+
try:
575+
action_value = ""
576+
for left, mid, right in data_set:
577+
if left.lower().strip() == "testcase exit":
578+
action_value = right.strip().lower()
579+
except:
580+
return CommonUtil.Exception_Handler(sys.exc_info())
581+
582+
583+
if "skip" in action_value:
584+
CommonUtil.testcase_exit = "Skipped"
585+
CommonUtil.ExecLog(sModuleInfo, "The testcase will be force Skipped", 2)
586+
return "passed"
587+
elif "fail" in action_value:
588+
CommonUtil.ExecLog(sModuleInfo, "The testcase will be force Failed", 2)
589+
CommonUtil.testcase_exit = "Failed"
590+
return "zeuz_failed"
591+
elif "pass" in action_value:
592+
CommonUtil.ExecLog(sModuleInfo, "The testcase will be force Passed", 2)
593+
CommonUtil.testcase_exit = "Passed"
568594
return "passed"
595+
elif "block" in action_value:
596+
CommonUtil.ExecLog(sModuleInfo, "The testcase will be force Blocked", 2)
597+
CommonUtil.testcase_exit = "Blocked"
598+
return "zeuz_failed"
569599
else:
570600
CommonUtil.ExecLog(sModuleInfo, "Step Result action has invalid VALUE", 3)
571601
return "zeuz_failed"
@@ -4608,7 +4638,7 @@ def upload_attachment_to_testcase(data_set):
46084638
CommonUtil.ExecLog(sModuleInfo, "Please insert attachment path ", 3)
46094639
return "zeuz_failed"
46104640
headers = RequestFormatter.add_api_key_to_headers({})
4611-
res = RequestFormatter.request("post",
4641+
res = RequestFormatter.request("post",
46124642
RequestFormatter.form_uri("test_case_file_upload/"),
46134643
files={"file": open(var_path, 'rb')},
46144644
data={"file_upload_tc": var_id},
@@ -4706,7 +4736,7 @@ def upload_attachment_to_step(data_set):
47064736
CommonUtil.ExecLog(sModuleInfo, "Please insert attachment path ", 3)
47074737
return "zeuz_failed"
47084738
headers = RequestFormatter.add_api_key_to_headers({})
4709-
res = RequestFormatter.request("post",
4739+
res = RequestFormatter.request("post",
47104740
RequestFormatter.form_uri("step_file_upload/"),
47114741
files={"file": open(var_path,'rb')},
47124742
data={"file_upload_step": var_id, },
@@ -4800,7 +4830,7 @@ def upload_attachment_to_global(data_set):
48004830
return "zeuz_failed"
48014831

48024832
headers = RequestFormatter.add_api_key_to_headers({})
4803-
res = RequestFormatter.request("post",
4833+
res = RequestFormatter.request("post",
48044834
RequestFormatter.form_uri("global_file_upload/"),
48054835
files={"file": open(var_path,'rb')},
48064836
verify=False,
@@ -5905,7 +5935,7 @@ def data_store_read(data_set):
59055935
headers = RequestFormatter.add_api_key_to_headers({})
59065936
headers['headers']['content-type'] = 'application/json'
59075937
headers['headers']['X-API-KEY'] = ConfigModule.get_config_value("Authentication", "api-key")
5908-
res = RequestFormatter.request("get",
5938+
res = RequestFormatter.request("get",
59095939
RequestFormatter.form_uri('data_store/data_store/custom_operation/'),
59105940
params=json.dumps(params),
59115941
verify=False,
@@ -5938,19 +5968,19 @@ def data_store_get_data(data_set):
59385968
columns = right.strip()
59395969
if 'get data' in left.lower().strip():
59405970
variable_name = right.strip()
5941-
5971+
59425972
if table_name == None or variable_name == None:
59435973
CommonUtil.ExecLog(sModuleInfo, f"Table name and Variable Name both needs to be provided", 3)
59445974
return "zeuz failed"
5945-
5975+
59465976
headers = RequestFormatter.add_api_key_to_headers({})
59475977
headers['headers']['content-type'] = 'application/json'
59485978
headers['headers']['X-API-KEY'] = ConfigModule.get_config_value("Authentication", "api-key")
59495979
params = dict()
59505980
params['table'] = table_name
59515981
if columns:
59525982
params['columns'] = columns
5953-
res = RequestFormatter.request("get",
5983+
res = RequestFormatter.request("get",
59545984
RequestFormatter.form_uri('data_store/get_datastore/'),
59555985
params=params,
59565986
verify=False,
@@ -5977,17 +6007,17 @@ def data_store_get_stats(data_set):
59776007
table_name = right.strip()
59786008
if 'stats' in left.lower().strip():
59796009
variable_name = right.strip()
5980-
6010+
59816011
if table_name == None or variable_name == None:
59826012
CommonUtil.ExecLog(sModuleInfo, f"Table name and Variable Name both needs to be provided", 3)
59836013
return "zeuz_failed"
5984-
6014+
59856015
headers = RequestFormatter.add_api_key_to_headers({})
59866016
headers['headers']['content-type'] = 'application/json'
59876017
headers['headers']['X-API-KEY'] = ConfigModule.get_config_value("Authentication", "api-key")
59886018
params = dict()
59896019
params['table'] = table_name
5990-
res = RequestFormatter.request("get",
6020+
res = RequestFormatter.request("get",
59916021
RequestFormatter.form_uri('data_store/get_datastore_stats/'),
59926022
params=params,
59936023
verify=False,
@@ -6191,7 +6221,7 @@ def data_store_insert(data_set):
61916221
headers['headers']['content-type'] = 'application/json'
61926222
headers['headers']['X-API-KEY'] = ConfigModule.get_config_value("Authentication", "api-key")
61936223

6194-
res = RequestFormatter.request("post",
6224+
res = RequestFormatter.request("post",
61956225
RequestFormatter.form_uri('data_store/data_store/data_store_list/'),
61966226
data=json.dumps(data),
61976227
verify=False,
@@ -6289,25 +6319,25 @@ def xml_to_json(data_set):
62896319
filepath = Path(CommonUtil.path_parser(filepath))
62906320
if "xml to json" in left:
62916321
json_var_name = right.strip()
6292-
6322+
62936323
if None in (filepath,json_var_name):
62946324
CommonUtil.ExecLog(sModuleInfo, "Please specify both filename and json variable name", 3)
62956325

62966326
if filepath != None and filepath.is_file():
62976327
try:
62986328
with open(filepath) as xml_file:
62996329
data_dict = xmltodict.parse(xml_file.read())
6300-
result = sr.Set_Shared_Variables(json_var_name, data_dict)
6330+
result = sr.Set_Shared_Variables(json_var_name, data_dict)
63016331
return result
63026332
except:
63036333
CommonUtil.ExecLog(sModuleInfo, "Couldn't read and convert the xml file", 3)
63046334
return "zeuz_failed"
6305-
63066335

6307-
6336+
6337+
63086338
else:
63096339
CommonUtil.ExecLog(sModuleInfo, "Specified file couldn't be found or downloaded from attachment", 3)
6310-
return "zeuz_failed"
6340+
return "zeuz_failed"
63116341

63126342
except:
63136343
return CommonUtil.Exception_Handler(sys.exc_info())
@@ -6384,7 +6414,7 @@ def connect_to_S3(data_set):
63846414
credentials_source = right.strip()
63856415
if "file path" in left:
63866416
cred_file_path = right.strip()
6387-
6417+
63886418
if credentials_source == "default":
63896419
try:
63906420
s3_client = boto3.client('s3')
@@ -6438,7 +6468,7 @@ def upload_to_S3(data_set):
64386468
if "s3 resource variable":
64396469
s3_resource_var = right.strip()
64406470

6441-
6471+
64426472
if None in (bucket_name, file_name):
64436473
CommonUtil.ExecLog(sModuleInfo, "Bucket, file and key names should be provided", 3)
64446474

@@ -6470,7 +6500,7 @@ def connect_to_bigquery_client(data_set):
64706500
if left.strip().lower() == 'connect to bigquery client':
64716501
client_var_name = right.strip()
64726502

6473-
6503+
64746504
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = cred_path
64756505

64766506
try:
@@ -6489,7 +6519,7 @@ def execute_bigquery_query(data_set):
64896519
output variable | input parameter | output variable name
64906520
execute bigquery query | common action | client variable name
64916521
"""
6492-
6522+
64936523
from google.cloud import bigquery
64946524

64956525
sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME
@@ -6505,7 +6535,7 @@ def execute_bigquery_query(data_set):
65056535
client_var_name = right.strip()
65066536
if left.strip().lower() == 'output variable':
65076537
output_var_name = right.strip()
6508-
6538+
65096539
if None in (query,client_var_name,output_var_name):
65106540
CommonUtil.ExecLog(sModuleInfo, "Incorrect Dataset", 3)
65116541
return "zeuz_failed"
@@ -6527,7 +6557,7 @@ def connect_to_google_service_account(data_set):
65276557
credentials path | input parameter | path to credentails json file
65286558
connect to google service client | common action | client variable name
65296559
"""
6530-
6560+
65316561
sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME
65326562
CommonUtil.ExecLog(sModuleInfo, "Actions involving the Google service account may not function correctly without a virtual environment.", 2)
65336563
cred_path = None
@@ -6538,7 +6568,7 @@ def connect_to_google_service_account(data_set):
65386568
if left.strip().lower() == 'connect to google service client':
65396569
client_var_name = right.strip()
65406570

6541-
try:
6571+
try:
65426572
from google.cloud import storage
65436573
client = storage.Client.from_service_account_json(json_credentials_path=cred_path)
65446574
sr.Set_Shared_Variables(client_var_name, client)
@@ -6552,7 +6582,7 @@ def upload_to_google_storage_bucket(data_set):
65526582
"""
65536583
data_set:
65546584
filepath | input parameter | filepath
6555-
bucket | input parameter | bucket name
6585+
bucket | input parameter | bucket name
65566586
upload to google storage bucket | common action | client variable name
65576587
"""
65586588

@@ -6569,7 +6599,7 @@ def upload_to_google_storage_bucket(data_set):
65696599
client_var_name = right.strip()
65706600
if left.strip().lower() == 'bucket':
65716601
bucket = right.strip()
6572-
6602+
65736603
if None in (filepath,client_var_name,bucket):
65746604
CommonUtil.ExecLog(sModuleInfo, "Incorrect Dataset", 3)
65756605
return "zeuz_failed"
@@ -6583,7 +6613,7 @@ def upload_to_google_storage_bucket(data_set):
65836613
return "passed"
65846614
except:
65856615
return CommonUtil.Exception_Handler(sys.exc_info())
6586-
6616+
65876617
@logger
65886618
def text_to_speech(data_set):
65896619
"""
@@ -6611,7 +6641,7 @@ def text_to_speech(data_set):
66116641
language = right.strip()
66126642
if "accent" in left:
66136643
top_level_domain = right.strip()
6614-
6644+
66156645
if None in (dialogue_data, speaker, output_filename):
66166646
CommonUtil.ExecLog(sModuleInfo, "Incorrect dataset", 3)
66176647
return "zeuz_failed"

Framework/Built_In_Automation/Sequential_Actions/sequential_actions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,7 @@ def Run_Sequential_Actions(
11201120
table.add_column("Field", justify="left", max_width=20)
11211121
table.add_column("Sub-field", justify="left", max_width=15)
11221122
table.add_column("Value", justify="left", max_width=35)
1123-
1123+
11241124
data_set_to_print = sr.Hide_Secretive_Text(text_value=data_set)
11251125
for row in data_set_to_print:
11261126
table.add_row(*row, style=_color)
@@ -1329,9 +1329,9 @@ def Run_Sequential_Actions(
13291329
# If middle column = action, call action handler
13301330
elif "action" in action_name: # Must be last, since it's a single word that also exists in other action types
13311331
result = Action_Handler(data_set, row) # Pass data set, and action_name to action handler
1332-
if row[0].lower().strip() == "step exit":
1332+
if row[0].lower().strip() in ("step exit", "testcase exit"):
13331333
global step_exit_fail_called, step_exit_pass_called
1334-
CommonUtil.ExecLog(sModuleInfo, "Step Exit called. Stopping Test Step.", 1)
1334+
CommonUtil.ExecLog(sModuleInfo, f"{row[0].lower().strip()} Exit called. Stopping Test Step.", 1)
13351335
if result == "zeuz_failed":
13361336
step_exit_fail_called = True
13371337
else:
@@ -2319,7 +2319,7 @@ def Action_Handler(_data_set, action_row, _bypass_bug=True):
23192319
+ python_location \
23202320
+"\n3.Go to this link and download python https://www.python.org/ftp/python/3.11.4/python-3.11.4-amd64.exe"\
23212321
+"\n4.During installation, give uncheck 'for all user' and check 'Add Python to Path'. This is very important."\
2322-
+"\n5.Relaunch zeuz node_cli.py"
2322+
+"\n5.Relaunch zeuz node_cli.py"
23232323
CommonUtil.ExecLog(sModuleInfo, error_msg, 3)
23242324
return "zeuz_failed"
23252325

Framework/MainDriverApi.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,9 @@ def run_all_test_steps_in_a_test_case(
605605
if StepSeq in CommonUtil.disabled_step or not all_step_info[StepSeq - 1]['step_enable']:
606606
CommonUtil.ExecLog(sModuleInfo, "STEP-%s is disabled" % StepSeq, 2)
607607
sStepResult = "skipped"
608+
elif CommonUtil.testcase_exit:
609+
CommonUtil.ExecLog(sModuleInfo, "STEP-%s is skipped" % StepSeq, 2)
610+
sStepResult = "skipped"
608611
else:
609612
sStepResult = call_driver_function_of_test_step(
610613
sModuleInfo,
@@ -698,7 +701,10 @@ def run_all_test_steps_in_a_test_case(
698701

699702
# from the returned step results, it finds out the test case result
700703
def calculate_test_case_result(sModuleInfo, TestCaseID, run_id, sTestStepResultList, testcase_info):
701-
if "BLOCKED" in sTestStepResultList:
704+
if CommonUtil.testcase_exit:
705+
CommonUtil.ExecLog(sModuleInfo, f"Test Case {CommonUtil.testcase_exit}", 1)
706+
return CommonUtil.testcase_exit
707+
elif "BLOCKED" in sTestStepResultList:
702708
CommonUtil.ExecLog(sModuleInfo, "Test Case Blocked", 3)
703709
return "Blocked"
704710
elif "CANCELLED" in sTestStepResultList or "Cancelled" in sTestStepResultList:
@@ -1929,6 +1935,7 @@ def main(device_dict, all_run_id_info):
19291935
}
19301936
set_device_info_according_to_user_order(device_order, device_dict, test_case_no, test_case_name, user_info_object, Userid, run_id=run_id)
19311937
CommonUtil.disabled_step = []
1938+
CommonUtil.testcase_exit = ""
19321939

19331940
# Download test case and step attachments
19341941
download_attachments(testcase_info)

Framework/Utilities/CommonUtil.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@
143143
run_cancel = ""
144144
run_cancelled = False
145145
disabled_step = [] # 1 based indexing
146+
testcase_exit = ""
146147
max_char = 0
147148
compare_action_varnames = {"left":"Left", "right":"Right"} # for labelling left and right variable names of compare action
148149

0 commit comments

Comments
 (0)