Skip to content

Commit 9149f56

Browse files
Merge pull request #612 from AutomationSolutionz/node-installer-2
Async Zeuz Node with Node-installer functions
2 parents ae71107 + 2dccf32 commit 9149f56

34 files changed

Lines changed: 919 additions & 623 deletions

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,7 @@ web_modules/
5858
custom_profiles/
5959

6060
# Security tools
61-
/tools/security/*
61+
/tools/security/*
62+
Apps/Windows/inspector.exe
63+
Apps/Windows/Element.xml
64+
Framework/settings.conf.lock

Framework/Built_In_Automation/Built_In_Utility/CrossPlatform/BuiltInUtilityFunction.py

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -857,60 +857,6 @@ def download_file_using_url(file_url, location_of_file, headers=dict()):
857857
sys.exc_info(), None, "Error downloading file"
858858
)
859859

860-
861-
# Method to download and unzip file
862-
# def download_and_unzip_file(file_url, location_of_file): #!!!change this to call download_file_using_url instead of duplicating work, or just remove download part, and whatever is calling this can call the two pieces separately
863-
#
864-
# sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME
865-
#
866-
#
867-
# try:
868-
# ''' Setting stream parameter to True will cause the download of response headers only and the connection remains open.
869-
# This avoids reading the content all at once into memory for large responses.
870-
# A fixed chunk will be loaded each time while r.iter_content is iterated.'''
871-
# r = requests.get(file_url, stream=True)
872-
#
873-
# list_the_parts_of_url = file_url.split("/") #get file name from the url
874-
# file_name = os.path.join(location_of_file, list_the_parts_of_url[len(list_the_parts_of_url) - 1])
875-
# actual_file_name = list_the_parts_of_url[len(list_the_parts_of_url) - 1]
876-
# with open(file_name, "wb") as f:
877-
# for chunk in r.iter_content(chunk_size=1024):
878-
#
879-
# # writing one chunk at a time to pdf file
880-
# if chunk:
881-
# f.write(chunk)
882-
# # after performing the download operation we have to check that if the file with new name exists in correct location.
883-
# # if the file exists in correct position then return passed
884-
# # if the file doesn't exist in correct position then return failed
885-
# if os.path.isfile(file_name):
886-
# CommonUtil.ExecLog(sModuleInfo, "file exists... downloading file using url function is done properly", 0)
887-
# else:
888-
# CommonUtil.ExecLog(sModuleInfo, "file doesn't exist... downloading file using url function is not done properly", 3)
889-
# return "zeuz_failed"
890-
# unzip_location = os.path.join(location_of_file,"latest_directory" )
891-
# CommonUtil.ExecLog(sModuleInfo, "Creating the directory '%s' " % unzip_location, 0)
892-
# result1 = CreateFolder(unzip_location)
893-
# if result1 in failed_tag_list:
894-
# CommonUtil.ExecLog(sModuleInfo, "Can't not create folder '%s' " % unzip_location, 3)
895-
# return "zeuz_failed"
896-
# CommonUtil.ExecLog(sModuleInfo, "Folder '%s' is created " % unzip_location, 1)
897-
# result = UnZip(file_name,unzip_location)
898-
# if result in failed_tag_list:
899-
# CommonUtil.ExecLog(sModuleInfo, "Can't not unzip file '%s' to '%s'" % (file_name, unzip_location), 3)
900-
# return "zeuz_failed"
901-
# CommonUtil.ExecLog(sModuleInfo, "Unzipping file '%s' to '%s' is complete" % (file_name, unzip_location), 0)
902-
# CommonUtil.ExecLog(sModuleInfo, "Saving directory location to shared resources" , 1)
903-
# #Shared_Resources.Set_Shared_Variables("latest_directory", unzip_location)
904-
# downloaded_file = os.path.join(unzip_location,actual_file_name )
905-
# Shared_Resources.Set_Shared_Variables("downloaded_file", downloaded_file)
906-
# Shared_Resources.Show_All_Shared_Variables()
907-
# return "passed"
908-
#
909-
#
910-
# except Exception:
911-
# return CommonUtil.Exception_Handler(sys.exc_info())
912-
913-
914860
# not done properly...need more works
915861
"""def change_path_for_windows(src):
916862
sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME

Framework/Built_In_Automation/Sequential_Actions/common_functions.py

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3754,28 +3754,31 @@ def execute_python_code(data_set):
37543754
try: exec(Code, sr.shared_variables)
37553755
except: return CommonUtil.Exception_Handler(sys.exc_info())
37563756

3757-
current_vars = set(sr.shared_variables)
3758-
new_variables = current_vars - previous_vars - {'__builtins__'}
3759-
removed_variables = previous_vars - current_vars - {'__builtins__'}
3757+
try:
3758+
current_vars = set(sr.shared_variables)
3759+
new_variables = current_vars - previous_vars - {'__builtins__'}
3760+
removed_variables = previous_vars - current_vars - {'__builtins__'}
37603761

3761-
text = ("Newly declared variables:\n" +
3762-
"\n".join([f"{str(i)[:50] + (' ...' if len(str(i)) > 50 else '')} = {str(sr.shared_variables[i])[:200] + (' ...' if len(str(sr.shared_variables[i])) > 200 else '')}" for i in new_variables]) if new_variables else ""
3763-
)
3764-
text += (
3765-
"\n\nBy default all the newly declared variables, functions are added in shared_variables\n" +
3766-
"and accessible in next python_code action or in %| |%.\n" +
3767-
"But if you dont want your newly declared variables accessible in next actions\n" +
3768-
"Cleanup the variables at the end of the code. Such as:\n" +
3769-
"del account_name\ndel function_name" if new_variables and CommonUtil.debug_status else ""
3770-
)
3771-
text += "\nRemoved variables:\n" + "\n".join([f"{i} = {str(sr.shared_variables[i])[:200]}" for i in removed_variables]) if removed_variables else ""
3772-
CommonUtil.ExecLog(sModuleInfo, text, 5)
3762+
text = ("Newly declared variables:\n" +
3763+
"\n".join([f"{str(i)[:50] + (' ...' if len(str(i)) > 50 else '')} = {str(sr.shared_variables[i])[:200] + (' ...' if len(str(sr.shared_variables[i])) > 200 else '')}" for i in new_variables]) if new_variables else ""
3764+
)
3765+
text += (
3766+
"\n\nBy default all the newly declared variables, functions are added in shared_variables\n" +
3767+
"and accessible in next python_code action or in %| |%.\n" +
3768+
"But if you dont want your newly declared variables accessible in next actions\n" +
3769+
"Cleanup the variables at the end of the code. Such as:\n" +
3770+
"del account_name\ndel function_name" if new_variables and CommonUtil.debug_status else ""
3771+
)
3772+
text += "\nRemoved variables:\n" + "\n".join([f"{i} = {str(sr.shared_variables[i])[:200]}" for i in removed_variables]) if removed_variables else ""
3773+
CommonUtil.ExecLog(sModuleInfo, text, 5)
37733774

3774-
for var in sr.shared_variables:
3775-
if var.startswith("zeuz_session_"):
3776-
CommonUtil.global_var[var] = sr.Get_Shared_Variables("run_id")
3777-
CommonUtil.ExecLog(sModuleInfo, "Executed the python code which was provided", 1)
3778-
return "passed"
3775+
for var in sr.shared_variables:
3776+
if var.startswith("zeuz_session_"):
3777+
CommonUtil.global_var[var] = sr.Get_Shared_Variables("run_id")
3778+
CommonUtil.ExecLog(sModuleInfo, "Executed the python code which was provided", 1)
3779+
return "passed"
3780+
except:
3781+
pass
37793782
except:
37803783
return CommonUtil.Exception_Handler(sys.exc_info())
37813784

Framework/Built_In_Automation/Web/Selenium/BuiltInFunctions.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,20 +1606,18 @@ def Enter_Text_In_Text_Box(step_data):
16061606
sModuleInfo, "Entering text without clicking the element", 2
16071607
)
16081608
if clear:
1609-
# Element.clear()
1610-
# Safari Keys are extremely slow and not working
1611-
if selenium_driver.capabilities["browserName"] == "Safari":
1612-
Element.clear()
1613-
else:
1614-
if sys.platform == "darwin":
1615-
Element.send_keys(Keys.COMMAND, "a")
1609+
try:
1610+
if selenium_driver.capabilities["browserName"] == "Safari":
1611+
Element.clear()
16161612
else:
1617-
Element.send_keys(Keys.CONTROL, "a")
1618-
Element.send_keys(Keys.DELETE)
1619-
try:
1613+
if sys.platform == "darwin":
1614+
Element.send_keys(Keys.COMMAND, "a")
1615+
else:
1616+
Element.send_keys(Keys.CONTROL, "a")
1617+
Element.send_keys(Keys.DELETE)
16201618
Element.clear() # some cases it works .. so adding it here just incase
1621-
except:
1622-
pass
1619+
except:
1620+
pass
16231621
if delay == 0:
16241622
Element.send_keys(text_value)
16251623
else:
@@ -1636,7 +1634,7 @@ def Enter_Text_In_Text_Box(step_data):
16361634
return "passed"
16371635
except Exception:
16381636
errMsg = "Could not select/click your element."
1639-
return CommonUtil.Exception_Handler(sys.exc_info(), None, errMsg)
1637+
return CommonUtil.Exception_Handler(sys.exc_info(), None)
16401638

16411639

16421640
@logger

Framework/Utilities/ConfigModule.py

Lines changed: 51 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
# -*- coding: utf-8 -*-
22
# -*- coding: cp1252 -*-
3-
3+
from filelock import FileLock
44
import configparser, os
55
from . import FileUtilities as FL
6+
from pathlib import Path
7+
from datetime import date
8+
from configobj import ConfigObj
9+
import traceback
610

711
"""constants"""
812
file_name = "settings.conf"
9-
13+
settings_file_lock = FileLock(os.getcwd().split("Framework")[0] + os.sep + "Framework" + os.sep + file_name + ".lock")
14+
settings_conf_path = os.getcwd().split("Framework")[0] + os.sep + "Framework" + os.sep + file_name
1015
remote_config = {
1116
"threading": False,
1217
"local_run": False,
@@ -15,7 +20,46 @@
1520
"upload_log_file_only_for_fail": True,
1621
}
1722

18-
23+
@settings_file_lock
24+
def create_settings_config_file():
25+
if Path(settings_conf_path).exists():
26+
return
27+
28+
today = date.today().strftime("%Y-%m-%d")
29+
30+
config = ConfigObj()
31+
config["Authentication"] = {"username": "", "api-key": "", "server_address": ""}
32+
config["Advanced Options"] = {
33+
"log_delete_interval": 7,
34+
"last_module_update_date": today,
35+
"last_log_delete_date": today,
36+
"element_wait": 10,
37+
"available_to_all_project": False,
38+
"_file": "temp_config.ini",
39+
"_file_upload_path": "TestExecutionLog",
40+
"stop_live_log": False,
41+
}
42+
config["Inspector"] = {
43+
"Window": "",
44+
"No_of_level_to_skip": 0,
45+
"ai_plugin": True,
46+
}
47+
config["server"] = {"port": 0}
48+
config.filename = str(settings_conf_path)
49+
config.write()
50+
print(f"Created settings.conf at {settings_conf_path}")
51+
52+
def remove_settings_lock_file():
53+
"""Remove stale lock file if the process that created it is no longer running."""
54+
try:
55+
lock_file_path = Path(settings_file_lock.lock_file)
56+
if not lock_file_path.exists():
57+
return
58+
lock_file_path.unlink(missing_ok=True)
59+
except Exception:
60+
traceback.print_exc()
61+
62+
@settings_file_lock
1963
def get_config_value(section, key, location: os.PathLike | None = None):
2064
"""
2165
:param section: name of section
@@ -30,7 +74,7 @@ def get_config_value(section, key, location: os.PathLike | None = None):
3074
config = configparser.ConfigParser()
3175
config.optionxform = str # Retain text case (default is to change to lowercase without this line)
3276
if not location:
33-
_file_name = os.getcwd() + os.sep + file_name
77+
_file_name = os.getcwd().split("Framework")[0] + os.sep + "Framework" + os.sep + file_name
3478
else:
3579
_file_name = location
3680
try:
@@ -46,7 +90,7 @@ def get_config_value(section, key, location: os.PathLike | None = None):
4690
# print "No option in that name: %s"%key
4791
return ""
4892

49-
93+
@settings_file_lock
5094
def remove_config_value(section, value, location=False):
5195
try:
5296
config = configparser.ConfigParser()
@@ -69,7 +113,7 @@ def remove_config_value(section, value, location=False):
69113
# print "No section in that name: %s"%section
70114
return ""
71115

72-
116+
@settings_file_lock
73117
def add_config_value(section, key, value, location: os.PathLike | None = None):
74118
try:
75119
config = configparser.ConfigParser()
@@ -98,44 +142,16 @@ def add_config_value(section, key, value, location: os.PathLike | None = None):
98142
else:
99143
config.set(section, key, value)
100144

101-
with (open(_file_name, "w")) as open_file:
145+
with open(_file_name, "w") as open_file:
102146
config.write(open_file) # Write all configuration to file
103147
open_file.close()
104148
return True
105149
except configparser.NoSectionError:
106-
# print "No section in that name: %s"%section
107150
return ""
108151
except configparser.NoOptionError:
109-
# print "No option in that name: %s"%key
110152
return ""
111153

112154

113-
def get_all_option(section_name, location: os.PathLike | None = None):
114-
"""
115-
:param section_name: given section name
116-
:return: list of all option on that section
117-
"""
118-
try:
119-
config = configparser.ConfigParser()
120-
config.optionxform = str # Retain text case (default is to change to lowercase without this line)
121-
if not location:
122-
_file_name = os.getcwd() + os.sep + file_name
123-
else:
124-
_file_name = location
125-
try:
126-
config.read(_file_name) # Read current configuration, if the file exists
127-
except:
128-
FL.DeleteFile(location)
129-
config.read(_file_name)
130-
return config.options(section_name)
131-
except configparser.NoSectionError as e:
132-
# print("Found no section with name %s" % section_name)
133-
return []
134-
except configparser.NoOptionError as e:
135-
# print("Found no options on the section %s" % section_name)
136-
return []
137-
138-
139155
def add_section(section_name, location: os.PathLike | None = None):
140156
"""
141157
:param section_name: name of the section to add
@@ -184,46 +200,3 @@ def clean_config_file(location: os.PathLike | None = None):
184200
except Exception as e:
185201
print(e)
186202
return False
187-
188-
189-
def get_all_sections(location: os.PathLike | None = None):
190-
try:
191-
config = configparser.ConfigParser()
192-
config.optionxform = str # Retain text case (default is to change to lowercase without this line)
193-
if not location:
194-
_file_name = os.getcwd() + os.sep + file_name
195-
else:
196-
_file_name = location
197-
try:
198-
config.read(_file_name) # Read current configuration, if the file exists
199-
except:
200-
FL.DeleteFile(location)
201-
config.read(_file_name)
202-
return config.sections()
203-
except configparser.NoSectionError as e:
204-
print("found no sections")
205-
return []
206-
except configparser.NoOptionError as e:
207-
print("found no options")
208-
return []
209-
210-
def has_section(section_name, location: os.PathLike | None = None):
211-
try:
212-
config = configparser.ConfigParser()
213-
config.optionxform = str # Retain text case (default is to change to lowercase without this line)
214-
if not location:
215-
_file_name = os.getcwd() + os.sep + file_name
216-
else:
217-
_file_name = location
218-
try:
219-
config.read(_file_name) # Read current configuration, if the file exists
220-
except:
221-
FL.DeleteFile(location)
222-
config.read(_file_name)
223-
return config.has_section(section_name)
224-
except configparser.NoSectionError as e:
225-
print("found no sections")
226-
return []
227-
except configparser.NoOptionError as e:
228-
print("found no options")
229-
return []

0 commit comments

Comments
 (0)