testzeus-hercules 0.0.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- testzeus_hercules/__init__.py +1 -0
- testzeus_hercules/__main__.py +188 -0
- testzeus_hercules/config.py +326 -0
- testzeus_hercules/core/__init__.py +8 -0
- testzeus_hercules/core/agents/__init__.py +1 -0
- testzeus_hercules/core/agents/browser_nav_agent.py +180 -0
- testzeus_hercules/core/agents/high_level_planner_agent.py +78 -0
- testzeus_hercules/core/agents_llm_config.py +224 -0
- testzeus_hercules/core/autogen_simple_wrapper.py +398 -0
- testzeus_hercules/core/memory/__init__.py +0 -0
- testzeus_hercules/core/memory/prompt_compressor.py +21 -0
- testzeus_hercules/core/memory/static_ltm.py +63 -0
- testzeus_hercules/core/notification_manager.py +53 -0
- testzeus_hercules/core/playwright_manager.py +910 -0
- testzeus_hercules/core/post_process_responses.py +50 -0
- testzeus_hercules/core/prompts.py +184 -0
- testzeus_hercules/core/runner.py +182 -0
- testzeus_hercules/core/tools/__init__.py +20 -0
- testzeus_hercules/core/tools/api_calls.py +215 -0
- testzeus_hercules/core/tools/captcha_solver.py +31 -0
- testzeus_hercules/core/tools/click_using_selector.py +496 -0
- testzeus_hercules/core/tools/dropdown_using_selector.py +289 -0
- testzeus_hercules/core/tools/enter_date_time.py +250 -0
- testzeus_hercules/core/tools/enter_text_and_click.py +167 -0
- testzeus_hercules/core/tools/enter_text_using_selector.py +430 -0
- testzeus_hercules/core/tools/get_dom_with_content_type.py +180 -0
- testzeus_hercules/core/tools/get_url.py +40 -0
- testzeus_hercules/core/tools/get_user_input.py +29 -0
- testzeus_hercules/core/tools/hover.py +226 -0
- testzeus_hercules/core/tools/open_url.py +75 -0
- testzeus_hercules/core/tools/pdf_text_extractor.py +92 -0
- testzeus_hercules/core/tools/press_key_combination.py +110 -0
- testzeus_hercules/core/tools/set_slider_value.py +354 -0
- testzeus_hercules/core/tools/sql_calls.py +136 -0
- testzeus_hercules/core/tools/tool_registry.py +34 -0
- testzeus_hercules/core/tools/upload_file.py +250 -0
- testzeus_hercules/core/ui_manager.py +220 -0
- testzeus_hercules/interactive.py +7 -0
- testzeus_hercules/js/injectOverlay.js +802 -0
- testzeus_hercules/telemetry.py +134 -0
- testzeus_hercules/utils/__init__.py +0 -0
- testzeus_hercules/utils/autogen_sequential_function_call.py +83 -0
- testzeus_hercules/utils/cli_helper.py +34 -0
- testzeus_hercules/utils/detect_llm_loops.py +46 -0
- testzeus_hercules/utils/dom_helper.py +64 -0
- testzeus_hercules/utils/dom_mutation_observer.py +138 -0
- testzeus_hercules/utils/formatting_helper.py +57 -0
- testzeus_hercules/utils/get_detailed_accessibility_tree.py +996 -0
- testzeus_hercules/utils/gherkin_helper.py +145 -0
- testzeus_hercules/utils/js_helper.py +44 -0
- testzeus_hercules/utils/junit_helper.py +341 -0
- testzeus_hercules/utils/logger.py +70 -0
- testzeus_hercules/utils/response_parser.py +69 -0
- testzeus_hercules/utils/ui_messagetype.py +14 -0
- testzeus_hercules-0.0.3.dist-info/LICENSE +661 -0
- testzeus_hercules-0.0.3.dist-info/METADATA +735 -0
- testzeus_hercules-0.0.3.dist-info/RECORD +59 -0
- testzeus_hercules-0.0.3.dist-info/WHEEL +4 -0
- testzeus_hercules-0.0.3.dist-info/entry_points.txt +3 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from testzeus_hercules import core # type: ignore # noqa: F401
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import json
|
|
3
|
+
import os
|
|
4
|
+
|
|
5
|
+
from junit2htmlreport.runner import run as prepare_html
|
|
6
|
+
from testzeus_hercules.config import (
|
|
7
|
+
get_input_gherkin_file_path,
|
|
8
|
+
get_junit_xml_base_path,
|
|
9
|
+
get_source_log_folder_path,
|
|
10
|
+
set_default_test_id,
|
|
11
|
+
)
|
|
12
|
+
from testzeus_hercules.core.runner import SingleCommandInputRunner
|
|
13
|
+
from testzeus_hercules.telemetry import EventData, EventType, add_event
|
|
14
|
+
from testzeus_hercules.utils.gherkin_helper import (
|
|
15
|
+
process_feature_file,
|
|
16
|
+
serialize_feature_file,
|
|
17
|
+
)
|
|
18
|
+
from testzeus_hercules.utils.junit_helper import JUnitXMLGenerator, build_junit_xml
|
|
19
|
+
from testzeus_hercules.utils.logger import logger
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def sequential_process() -> None:
|
|
23
|
+
"""
|
|
24
|
+
sequential_process function to process feature files, run test cases, and generate JUnit XML results.
|
|
25
|
+
|
|
26
|
+
This function performs the following steps:
|
|
27
|
+
1. Processes the feature file to get a list of features.
|
|
28
|
+
2. Retrieves the input Gherkin file path and extracts the feature file name.
|
|
29
|
+
3. Initializes an empty list to store test results.
|
|
30
|
+
4. Constructs the final result file name for the JUnit XML output.
|
|
31
|
+
5. Iterates over each feature in the list of features:
|
|
32
|
+
a. Extracts the file path, feature name, and scenario ID.
|
|
33
|
+
b. Serializes the feature file into a command.
|
|
34
|
+
c. Logs the start of the test case execution.
|
|
35
|
+
d. Runs the test case using SingleCommandInputRunner.
|
|
36
|
+
e. Collects the test result, execution time, and cost metrics.
|
|
37
|
+
f. Parses the JSON content from the runner's chat history.
|
|
38
|
+
g. Logs the completion of the test case.
|
|
39
|
+
h. Builds the JUnit XML for the test case and appends it to the results list.
|
|
40
|
+
6. Merges all JUnit XML results into a single file.
|
|
41
|
+
7. Logs the location of the final result file.
|
|
42
|
+
"""
|
|
43
|
+
list_of_feats = process_feature_file()
|
|
44
|
+
input_gherkin_file_path = get_input_gherkin_file_path()
|
|
45
|
+
# get name of the feature file using os package
|
|
46
|
+
feature_file_name = os.path.basename(input_gherkin_file_path)
|
|
47
|
+
|
|
48
|
+
result_of_tests = []
|
|
49
|
+
final_result_file_name = (
|
|
50
|
+
f"{get_junit_xml_base_path()}/{feature_file_name}_result.xml"
|
|
51
|
+
)
|
|
52
|
+
add_event(EventType.RUN, EventData(detail="Total Runs: " + str(len(list_of_feats))))
|
|
53
|
+
for feat in list_of_feats:
|
|
54
|
+
file_path = feat["output_file"]
|
|
55
|
+
feature_name = feat["feature"]
|
|
56
|
+
scenario = feat["scenario"]
|
|
57
|
+
# sanatise stake_id
|
|
58
|
+
stake_id = scenario.replace(" ", "_").replace(":", "_")
|
|
59
|
+
|
|
60
|
+
# TODO: remove the following set default hack later.
|
|
61
|
+
set_default_test_id(stake_id)
|
|
62
|
+
|
|
63
|
+
cmd = serialize_feature_file(file_path)
|
|
64
|
+
|
|
65
|
+
logger.info(f"Running testcase: {stake_id}")
|
|
66
|
+
logger.info(f"testcase details: {cmd}")
|
|
67
|
+
runner = SingleCommandInputRunner(
|
|
68
|
+
stake_id=stake_id,
|
|
69
|
+
command=cmd,
|
|
70
|
+
)
|
|
71
|
+
asyncio.run(runner.start())
|
|
72
|
+
|
|
73
|
+
runner_result = {}
|
|
74
|
+
cost_metrics = runner.result.cost or {}
|
|
75
|
+
execution_time = runner.execution_time
|
|
76
|
+
if runner.result and runner.result.chat_history:
|
|
77
|
+
s_rr = runner.result.chat_history[-1]["content"]
|
|
78
|
+
s_rr = runner.result.chat_history[-1]["content"]
|
|
79
|
+
json_content = s_rr.replace("```json\n", "").replace("\n```", "").strip()
|
|
80
|
+
try:
|
|
81
|
+
runner_result = json.loads(json_content)
|
|
82
|
+
except json.JSONDecodeError:
|
|
83
|
+
logger.error(f"Failed to decode JSON: {json_content}")
|
|
84
|
+
|
|
85
|
+
logger.info(f"Run completed for testcase: {scenario}")
|
|
86
|
+
result_of_tests.append(
|
|
87
|
+
build_junit_xml(
|
|
88
|
+
runner_result,
|
|
89
|
+
execution_time,
|
|
90
|
+
cost_metrics,
|
|
91
|
+
feature_name,
|
|
92
|
+
scenario,
|
|
93
|
+
feature_file_path=file_path,
|
|
94
|
+
output_file_path="",
|
|
95
|
+
proofs_screenshot_path=runner.browser_manager._screenshots_dir,
|
|
96
|
+
proofs_video_path=runner.browser_manager.get_latest_video_path(),
|
|
97
|
+
network_logs_path=runner.browser_manager.request_response_log_file,
|
|
98
|
+
logs_path=get_source_log_folder_path(stake_id),
|
|
99
|
+
planner_thoughts_path=get_source_log_folder_path(stake_id)
|
|
100
|
+
+ "/chat_messages.json",
|
|
101
|
+
)
|
|
102
|
+
)
|
|
103
|
+
JUnitXMLGenerator.merge_junit_xml(result_of_tests, final_result_file_name)
|
|
104
|
+
logger.info(f"Results published in junitxml file: {final_result_file_name}")
|
|
105
|
+
|
|
106
|
+
# building html from junitxml
|
|
107
|
+
final_result_html_file_name = (
|
|
108
|
+
f"{get_junit_xml_base_path()}/{feature_file_name}_result.html"
|
|
109
|
+
)
|
|
110
|
+
prepare_html([final_result_file_name, final_result_html_file_name])
|
|
111
|
+
logger.info(f"Results published in html file: {final_result_html_file_name}")
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def main() -> None:
|
|
115
|
+
"""
|
|
116
|
+
Main function to run the sequential_process function.
|
|
117
|
+
"""
|
|
118
|
+
|
|
119
|
+
def is_width_gt_120() -> bool:
|
|
120
|
+
try:
|
|
121
|
+
columns = os.get_terminal_size().columns
|
|
122
|
+
except OSError:
|
|
123
|
+
columns = 120
|
|
124
|
+
return columns >= 120
|
|
125
|
+
|
|
126
|
+
if is_width_gt_120():
|
|
127
|
+
print(
|
|
128
|
+
"""
|
|
129
|
+
/$$ /$$/$$ /$$
|
|
130
|
+
| $$ /$ | $| $$ | $$
|
|
131
|
+
| $$ /$$$| $| $$$$$$$ /$$$$$$ /$$$$$$
|
|
132
|
+
| $$/$$ $$ $| $$__ $$|____ $|_ $$_/
|
|
133
|
+
==+=+#### | $$$$_ $$$| $$ \ $$ /$$$$$$$ | $$
|
|
134
|
+
+=+ ## ## | $$$/ \ $$| $$ | $$/$$__ $$ | $$ /$$
|
|
135
|
+
#* %*+ ### | $$/ \ $| $$ | $| $$$$$$$ | $$$$/
|
|
136
|
+
#----=+**##***#**##%% |__/ \__|__/ |__/\_______/ \___/
|
|
137
|
+
#===============------*=*
|
|
138
|
+
*=====+%#%+===========*==#
|
|
139
|
+
*===##%###%###*=======*=+-=
|
|
140
|
+
+==##=*#%@%%%##%======+=*=--+ /$$
|
|
141
|
+
##==+%-+%@@#*%%%%%#=======*===-+ |__/
|
|
142
|
+
*+*==*#+#@@%---@%%##====+==*=*****# /$$ /$$$$$$$ /$$$$$$/$$$$ /$$ /$$
|
|
143
|
+
+*==+%=*%@@*=%%%%##====+==+*===*## | $$/$$_____/ | $$_ $$_ $| $$ | $$
|
|
144
|
+
#===#####%@%##%#%=====+=+=**+*### | $| $$$$$$ | $$ \ $$ \ $| $$ | $$
|
|
145
|
+
*====+#%%##%#%%#======+=+==#**#%% | $$\____ $$ | $$ | $$ | $| $$ | $$
|
|
146
|
+
+=========++==========+=+==#**##% | $$/$$$$$$$/ | $$ | $$ | $| $$$$$$$
|
|
147
|
+
+=====================+=+==***##% |__|_______/ |__/ |__/ |__/\____ $$
|
|
148
|
+
%#++++++++***+===++==+==+==***#%% /$$ | $$
|
|
149
|
+
%**%%*+***************#+==+***%% | $$$$$$/
|
|
150
|
+
%#*%#% %**********###*++++=#**%%@ \______/
|
|
151
|
+
###%%%#%**********######++*%**#%@
|
|
152
|
+
%++=+###@**********####% #+++*##
|
|
153
|
+
#***##% #*********#### #+++#%# /$$$$$$ /$$ /$$ /$$$$$$ /$$$$$$ /$$$$$$ /$$$$$$$ /$$$$$$
|
|
154
|
+
%#**%% #*********#### %#*#@%% /$$__ $| $$ | $$/$$__ $$/$$__ $$/$$__ $$/$$_____//$$__ $$
|
|
155
|
+
%#**%% @%%%%%%%%%%% %**#%% | $$ \ $| $$ | $| $$ \__| $$ \ $| $$ \ $| $$$$$$| $$$$$$$$
|
|
156
|
+
%**#% %####%##% #**##% | $$ | $| $$ | $| $$ | $$ | $| $$ | $$\____ $| $$_____/
|
|
157
|
+
%**%% %####%##% #**##% | $$$$$$$| $$$$$$| $$ | $$$$$$$| $$$$$$//$$$$$$$| $$$$$$$
|
|
158
|
+
#*#%% #####%##% #**%% | $$____/ \______/|__/ | $$____/ \______/|_______/ \_______/
|
|
159
|
+
#*##% ####%##@ #**%% | $$ | $$
|
|
160
|
+
#*#%@ ####%##@ #*#%@ | $$ | $$
|
|
161
|
+
%#*%% %###%%%% #*%% |__/ |__/
|
|
162
|
+
+##%@ %###%%% ###*# /$$$$
|
|
163
|
+
+*+* %###%#% @%*+# /$$ $$
|
|
164
|
+
**#+**#% @ %###%#% %%%%%*+# |__/\ $$
|
|
165
|
+
@@@@@@@%###%#% #*++++# /$$/
|
|
166
|
+
@@@@@@@@@@%###%#% /$$/
|
|
167
|
+
@@@@@@@@@@%+=####%##==++*%@@% |__/
|
|
168
|
+
@@@@@@@@@@@*=====++*%*=====%@@@@@@@@ /$$
|
|
169
|
+
@@@@@@@@@@@*===============*@@@@@@@@@@@ |__/
|
|
170
|
+
@@@@@@@@@*================%@@@@@@@@@+%@@
|
|
171
|
+
@@@@@@@@+=++*+=========*%@@@@@@@@%%%%@@@
|
|
172
|
+
@@@@@@@%**+=====++*++%@@@@@@@@@@*%@@@@
|
|
173
|
+
@@@@@@@%###****++==+@@@@@@@@@@%%%@@@ /$$$$$$$ /$$$$$$ /$$$$$$ /$$
|
|
174
|
+
@@@ %%%#####**@@@@@@@@%*#@@@@ | $$__ $$ /$$__ $$/$$__ $| $$
|
|
175
|
+
%%%#@@@@@@@%%%%@@ | $$ \ $$ /$$$$$$ | $$ \ $| $$ \ $| $$
|
|
176
|
+
@@@@@@@@@@@ | $$ | $$/$$__ $$ | $$ | $| $$$$$$$| $$
|
|
177
|
+
@@@@@@@ | $$ | $| $$ \ $$ | $$ | $| $$__ $| __/
|
|
178
|
+
| $$ | $| $$ | $$ | $$/$$ $| $$ | $$
|
|
179
|
+
| $$$$$$$| $$$$$$/ | $$$$$$| $$ | $$ /$$
|
|
180
|
+
|_______/ \______/ \____ $$|__/ |__| __/
|
|
181
|
+
\__/
|
|
182
|
+
"""
|
|
183
|
+
)
|
|
184
|
+
sequential_process()
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
if __name__ == "__main__": # pragma: no cover
|
|
188
|
+
main()
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
# config.py at the project source code root
|
|
2
|
+
import os
|
|
3
|
+
import argparse
|
|
4
|
+
from typing import Optional
|
|
5
|
+
|
|
6
|
+
from dotenv import load_dotenv
|
|
7
|
+
|
|
8
|
+
IS_TEST_ENV = os.environ.get("IS_TEST_ENV", "false").lower() == "true"
|
|
9
|
+
|
|
10
|
+
if not IS_TEST_ENV:
|
|
11
|
+
env_file_path: str = ".env"
|
|
12
|
+
load_dotenv(env_file_path, verbose=True, override=True)
|
|
13
|
+
|
|
14
|
+
from testzeus_hercules.telemetry import EventData, EventType, add_event
|
|
15
|
+
from testzeus_hercules.utils.logger import logger
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def arguments() -> None:
|
|
19
|
+
parser = argparse.ArgumentParser(
|
|
20
|
+
description="Hercules: The World's First Open-Source AI Agent for End-to-End Testing"
|
|
21
|
+
)
|
|
22
|
+
parser.add_argument(
|
|
23
|
+
"--input-file", type=str, help="Path to the input file.", required=False
|
|
24
|
+
)
|
|
25
|
+
parser.add_argument(
|
|
26
|
+
"--output-path", type=str, help="Path to the output directory.", required=False
|
|
27
|
+
)
|
|
28
|
+
parser.add_argument(
|
|
29
|
+
"--test-data-path",
|
|
30
|
+
type=str,
|
|
31
|
+
help="Path to the test data directory.",
|
|
32
|
+
required=False,
|
|
33
|
+
)
|
|
34
|
+
parser.add_argument(
|
|
35
|
+
"--project-base",
|
|
36
|
+
type=str,
|
|
37
|
+
help="Path to the project base directory.",
|
|
38
|
+
required=False,
|
|
39
|
+
)
|
|
40
|
+
parser.add_argument(
|
|
41
|
+
"--llm-model",
|
|
42
|
+
type=str,
|
|
43
|
+
help="Name of the LLM model.",
|
|
44
|
+
required=False,
|
|
45
|
+
)
|
|
46
|
+
parser.add_argument(
|
|
47
|
+
"--llm-model-api-key",
|
|
48
|
+
type=str,
|
|
49
|
+
help="API key for the LLM model.",
|
|
50
|
+
required=False,
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
args = parser.parse_args()
|
|
54
|
+
|
|
55
|
+
if args.input_file:
|
|
56
|
+
os.environ["INPUT_GHERKIN_FILE_PATH"] = args.input_file
|
|
57
|
+
|
|
58
|
+
if args.output_path:
|
|
59
|
+
os.environ["JUNIT_XML_BASE_PATH"] = args.output_path
|
|
60
|
+
|
|
61
|
+
if args.test_data_path:
|
|
62
|
+
os.environ["TEST_DATA_PATH"] = args.test_data_path
|
|
63
|
+
|
|
64
|
+
if args.project_base:
|
|
65
|
+
os.environ["PROJECT_SOURCE_ROOT"] = args.project_base
|
|
66
|
+
|
|
67
|
+
if args.llm_model:
|
|
68
|
+
os.environ["LLM_MODEL_NAME"] = args.llm_model
|
|
69
|
+
|
|
70
|
+
if args.llm_model_api_key:
|
|
71
|
+
os.environ["LLM_MODEL_API_KEY"] = args.llm_model_api_key
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
# running argparser
|
|
75
|
+
arguments()
|
|
76
|
+
|
|
77
|
+
# Check that either LLM_MODEL_NAME and LLM_MODEL_API_KEY are set together,
|
|
78
|
+
# or AGENTS_LLM_CONFIG_FILE and AGENTS_LLM_CONFIG_FILE_REF_KEY are set together
|
|
79
|
+
llm_model_name = os.environ.get("LLM_MODEL_NAME")
|
|
80
|
+
llm_model_api_key = os.environ.get("LLM_MODEL_API_KEY")
|
|
81
|
+
agents_llm_config_file = os.environ.get("AGENTS_LLM_CONFIG_FILE")
|
|
82
|
+
agents_llm_config_file_ref_key = os.environ.get("AGENTS_LLM_CONFIG_FILE_REF_KEY")
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
if (llm_model_name and llm_model_api_key) and (
|
|
86
|
+
agents_llm_config_file or agents_llm_config_file_ref_key
|
|
87
|
+
):
|
|
88
|
+
logger.error(
|
|
89
|
+
"Provide either LLM_MODEL_NAME and LLM_MODEL_API_KEY together, or AGENTS_LLM_CONFIG_FILE and AGENTS_LLM_CONFIG_FILE_REF_KEY together, not both."
|
|
90
|
+
)
|
|
91
|
+
exit(1)
|
|
92
|
+
|
|
93
|
+
if (not llm_model_name or not llm_model_api_key) and (
|
|
94
|
+
not agents_llm_config_file or not agents_llm_config_file_ref_key
|
|
95
|
+
):
|
|
96
|
+
logger.error(
|
|
97
|
+
"Either LLM_MODEL_NAME and LLM_MODEL_API_KEY must be set together, or AGENTS_LLM_CONFIG_FILE and AGENTS_LLM_CONFIG_FILE_REF_KEY must be set together. user --llm-model and --llm-model-api-key in hercules command"
|
|
98
|
+
)
|
|
99
|
+
exit(1)
|
|
100
|
+
|
|
101
|
+
MODE = os.environ.get("MODE", "prod")
|
|
102
|
+
DEFAULT_TEST_ID = "default"
|
|
103
|
+
|
|
104
|
+
# Get the project source root path
|
|
105
|
+
PROJECT_SOURCE_ROOT = os.environ.get("PROJECT_SOURCE_ROOT", "./opt")
|
|
106
|
+
CDP_ENDPOINT_URL = os.environ.get("CDP_ENDPOINT_URL")
|
|
107
|
+
|
|
108
|
+
PROJECT_ROOT = PROJECT_SOURCE_ROOT
|
|
109
|
+
PROJECT_TEMP_PATH = os.path.join(PROJECT_ROOT, "temp")
|
|
110
|
+
PROJECT_TEST_ROOT = os.path.join(PROJECT_ROOT, "test")
|
|
111
|
+
|
|
112
|
+
INPUT_GHERKIN_FILE_PATH = os.environ.get("INPUT_GHERKIN_FILE_PATH") or os.path.join(
|
|
113
|
+
PROJECT_ROOT, "input/test.feature"
|
|
114
|
+
)
|
|
115
|
+
TMP_GHERKIN_PATH = os.path.join(PROJECT_ROOT, "gherkin_files")
|
|
116
|
+
JUNIT_XML_BASE_PATH = os.environ.get("JUNIT_XML_BASE_PATH") or os.path.join(
|
|
117
|
+
PROJECT_ROOT, "output"
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
SOURCE_LOG_FOLDER_PATH = os.path.join(PROJECT_ROOT, "log_files")
|
|
121
|
+
TEST_DATA_PATH = os.environ.get("TEST_DATA_PATH") or os.path.join(
|
|
122
|
+
PROJECT_ROOT, "test_data"
|
|
123
|
+
)
|
|
124
|
+
SCREEN_SHOT_PATH = os.path.join(PROJECT_ROOT, "proofs")
|
|
125
|
+
|
|
126
|
+
if "HF_HOME" not in os.environ:
|
|
127
|
+
os.environ["HF_HOME"] = "./.cache"
|
|
128
|
+
|
|
129
|
+
if "TOKENIZERS_PARALLELISM" not in os.environ:
|
|
130
|
+
os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def get_cdp_config() -> dict | None:
|
|
134
|
+
"""
|
|
135
|
+
Get the CDP config.
|
|
136
|
+
"""
|
|
137
|
+
if CDP_ENDPOINT_URL:
|
|
138
|
+
cdp_config = {
|
|
139
|
+
"endpoint_url": CDP_ENDPOINT_URL,
|
|
140
|
+
}
|
|
141
|
+
return cdp_config
|
|
142
|
+
return None
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def set_default_test_id(test_id: str) -> None:
|
|
146
|
+
"""
|
|
147
|
+
Set the default test ID.
|
|
148
|
+
|
|
149
|
+
Args:
|
|
150
|
+
test_id (str): The test ID.
|
|
151
|
+
"""
|
|
152
|
+
global DEFAULT_TEST_ID
|
|
153
|
+
DEFAULT_TEST_ID = test_id
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def reset_default_test_id() -> None:
|
|
157
|
+
"""
|
|
158
|
+
Reset the default test ID.
|
|
159
|
+
"""
|
|
160
|
+
global DEFAULT_TEST_ID
|
|
161
|
+
DEFAULT_TEST_ID = "default"
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def should_run_headless() -> bool:
|
|
165
|
+
"""
|
|
166
|
+
Check if the system should run in headless mode.
|
|
167
|
+
"""
|
|
168
|
+
return os.environ.get("HEADLESS", "true").lower().strip() == "true"
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def should_record_video() -> bool:
|
|
172
|
+
"""
|
|
173
|
+
Check if the system should record video.
|
|
174
|
+
"""
|
|
175
|
+
return os.environ.get("RECORD_VIDEO", "true").lower().strip() == "true"
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def should_take_screenshots() -> bool:
|
|
179
|
+
"""
|
|
180
|
+
Check if the system should take screenshots.
|
|
181
|
+
"""
|
|
182
|
+
return os.environ.get("TAKE_SCREENSHOTS", "true").lower().strip() == "true"
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def get_browser_type() -> str:
|
|
186
|
+
"""
|
|
187
|
+
Get the browser type to use.
|
|
188
|
+
|
|
189
|
+
Returns:
|
|
190
|
+
str: The browser type.
|
|
191
|
+
"""
|
|
192
|
+
return os.environ.get("BROWSER_TYPE", "chromium")
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def should_capture_network() -> bool:
|
|
196
|
+
"""
|
|
197
|
+
Check if the system should capture network traffic.
|
|
198
|
+
"""
|
|
199
|
+
return os.environ.get("CAPTURE_NETWORK", "true").lower().strip() == "true"
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def get_input_gherkin_file_path() -> str:
|
|
203
|
+
"""
|
|
204
|
+
Check if the INPUT_GHERKIN_FILE_PATH exists, and if not, create it.
|
|
205
|
+
|
|
206
|
+
Returns:
|
|
207
|
+
str: The input Gherkin file path.
|
|
208
|
+
"""
|
|
209
|
+
if not os.path.exists(INPUT_GHERKIN_FILE_PATH):
|
|
210
|
+
base_path = os.path.dirname(INPUT_GHERKIN_FILE_PATH)
|
|
211
|
+
if not os.path.exists(base_path):
|
|
212
|
+
os.makedirs(base_path)
|
|
213
|
+
logger.info(
|
|
214
|
+
f"Created INPUT_GHERKIN_FILE_PATH folder at: {INPUT_GHERKIN_FILE_PATH}"
|
|
215
|
+
)
|
|
216
|
+
return INPUT_GHERKIN_FILE_PATH
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def get_tmp_gherkin_path() -> str:
|
|
220
|
+
"""
|
|
221
|
+
Check if the TMP_GHERKIN_PATH exists, and if not, create it.
|
|
222
|
+
|
|
223
|
+
Returns:
|
|
224
|
+
str: The temporary Gherkin path.
|
|
225
|
+
"""
|
|
226
|
+
if not os.path.exists(TMP_GHERKIN_PATH):
|
|
227
|
+
os.makedirs(TMP_GHERKIN_PATH)
|
|
228
|
+
logger.info(f"Created TMP_GHERKIN_PATH folder at: {TMP_GHERKIN_PATH}")
|
|
229
|
+
return TMP_GHERKIN_PATH
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
def get_junit_xml_base_path() -> str:
|
|
233
|
+
"""
|
|
234
|
+
Check if the JUNIT_XML_BASE_PATH exists, and if not, create it.
|
|
235
|
+
|
|
236
|
+
Returns:
|
|
237
|
+
str: The JUnit XML base path.
|
|
238
|
+
"""
|
|
239
|
+
if not os.path.exists(JUNIT_XML_BASE_PATH):
|
|
240
|
+
os.makedirs(JUNIT_XML_BASE_PATH)
|
|
241
|
+
logger.info(f"Created JUNIT_XML_BASE_PATH folder at: {JUNIT_XML_BASE_PATH}")
|
|
242
|
+
return JUNIT_XML_BASE_PATH
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
def get_source_log_folder_path(test_id: Optional[str] = None) -> str:
|
|
246
|
+
"""
|
|
247
|
+
Check if the source log folder exists for the given test_id, and if not, create it.
|
|
248
|
+
|
|
249
|
+
Args:
|
|
250
|
+
test_id (Optional[str]): The test ID. Defaults to DEFAULT_TEST_ID.
|
|
251
|
+
|
|
252
|
+
Returns:
|
|
253
|
+
str: The source log folder path.
|
|
254
|
+
"""
|
|
255
|
+
test_id = test_id or DEFAULT_TEST_ID
|
|
256
|
+
source_log_folder_path = os.path.join(SOURCE_LOG_FOLDER_PATH, test_id)
|
|
257
|
+
if not os.path.exists(source_log_folder_path):
|
|
258
|
+
os.makedirs(source_log_folder_path)
|
|
259
|
+
logger.info(
|
|
260
|
+
f"Created source_log_folder_path folder at: {source_log_folder_path}"
|
|
261
|
+
)
|
|
262
|
+
return source_log_folder_path
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
def get_test_data_path() -> str:
|
|
266
|
+
"""
|
|
267
|
+
Check if the test data folder exists for the given test_id, and if not, create it.
|
|
268
|
+
Returns:
|
|
269
|
+
str: The test data folder path.
|
|
270
|
+
"""
|
|
271
|
+
test_data_path = TEST_DATA_PATH
|
|
272
|
+
if not os.path.exists(test_data_path):
|
|
273
|
+
os.makedirs(test_data_path)
|
|
274
|
+
logger.info(f"Created test data folder at: {test_data_path}")
|
|
275
|
+
return test_data_path
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
def get_screen_shot_path(test_id: Optional[str] = None) -> str:
|
|
279
|
+
"""
|
|
280
|
+
Check if the screenshot folder exists for the given test_id, and if not, create it.
|
|
281
|
+
|
|
282
|
+
Args:
|
|
283
|
+
test_id (Optional[str]): The test ID. Defaults to DEFAULT_TEST_ID.
|
|
284
|
+
|
|
285
|
+
Returns:
|
|
286
|
+
str: The screenshot folder path.
|
|
287
|
+
"""
|
|
288
|
+
test_id = test_id or DEFAULT_TEST_ID
|
|
289
|
+
screen_shot_path = os.path.join(SCREEN_SHOT_PATH, test_id)
|
|
290
|
+
if not os.path.exists(screen_shot_path):
|
|
291
|
+
os.makedirs(os.path.join(screen_shot_path, "screenshots"))
|
|
292
|
+
os.makedirs(os.path.join(screen_shot_path, "videos"))
|
|
293
|
+
logger.info(f"Created screen_shot_path folder at: {screen_shot_path}")
|
|
294
|
+
return screen_shot_path
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
def get_project_temp_path(test_id: Optional[str] = None) -> str:
|
|
298
|
+
"""
|
|
299
|
+
Check if the project temporary path exists for the given test_id, and if not, create it.
|
|
300
|
+
|
|
301
|
+
Args:
|
|
302
|
+
test_id (Optional[str]): The test ID. Defaults to DEFAULT_TEST_ID.
|
|
303
|
+
|
|
304
|
+
Returns:
|
|
305
|
+
str: The project temporary path.
|
|
306
|
+
"""
|
|
307
|
+
test_id = test_id or DEFAULT_TEST_ID
|
|
308
|
+
project_temp_path = os.path.join(PROJECT_TEMP_PATH, test_id)
|
|
309
|
+
if not os.path.exists(project_temp_path):
|
|
310
|
+
os.makedirs(project_temp_path)
|
|
311
|
+
logger.info(f"Created project_temp_path folder at: {project_temp_path}")
|
|
312
|
+
return project_temp_path
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
# send general config to telemetry, use get methods to get the values
|
|
316
|
+
config_brief = {
|
|
317
|
+
"MODE": MODE,
|
|
318
|
+
"HEADLESS": should_run_headless(),
|
|
319
|
+
"RECORD_VIDEO": should_record_video(),
|
|
320
|
+
"TAKE_SCREENSHOTS": should_take_screenshots(),
|
|
321
|
+
"BROWSER_TYPE": get_browser_type(),
|
|
322
|
+
"CAPTURE_NETWORK": should_capture_network(),
|
|
323
|
+
}
|
|
324
|
+
add_event(
|
|
325
|
+
EventType.CONFIG, EventData(detail="General Config", additional_data=config_brief)
|
|
326
|
+
)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
from testzeus_hercules.core import agents, memory, tools
|
|
2
|
+
from testzeus_hercules.core.autogen_simple_wrapper import AutogenSimpleWrapper
|
|
3
|
+
from testzeus_hercules.core.playwright_manager import PlaywrightManager
|
|
4
|
+
from testzeus_hercules.core.post_process_responses import (
|
|
5
|
+
final_reply_callback_user_proxy,
|
|
6
|
+
)
|
|
7
|
+
from testzeus_hercules.core.prompts import LLM_PROMPTS
|
|
8
|
+
from testzeus_hercules.core.ui_manager import UIManager
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from testzeus_hercules.core.agents.browser_nav_agent import BrowserNavAgent
|