Skip to content

Commit 20f8b73

Browse files
Save port number in settings file
1 parent e105ffe commit 20f8b73

File tree

1 file changed

+39
-19
lines changed

1 file changed

+39
-19
lines changed

node_cli.py

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,38 @@ def adjust_python_path():
6565
from Framework.node_server_state import STATE # noqa: E402
6666
from server import main as node_server # noqa: E402
6767

68+
settings_conf_path = str(Path(__file__).parent / "Framework" / "settings.conf")
69+
print(f"Settings config path: {settings_conf_path}")
70+
def create_config_file():
71+
if not os.path.exists(settings_conf_path):
72+
config = ConfigObj()
73+
config["Authentication"] = {
74+
"username": "",
75+
"api-key": "",
76+
"server_address": ""
77+
}
78+
config["Advanced Options"] = {
79+
"module_update_interval": 30,
80+
"log_delete_interval": 7,
81+
"last_module_update_date": "2025-02-21",
82+
"last_log_delete_date": "2023-09-19",
83+
"element_wait": 10,
84+
"available_to_all_project": False,
85+
"_file": "temp_config.ini",
86+
"_file_upload_path": "TestExecutionLog",
87+
"stop_live_log": False
88+
}
89+
config["Inspector"] = {
90+
"Window": "",
91+
"No_of_level_to_skip": 0,
92+
"ai_plugin": True
93+
}
94+
config["server"] = {
95+
"port": 0
96+
}
97+
config.filename = settings_conf_path
98+
config.write()
99+
print(f"Created settings.conf at {settings_conf_path}")
68100

69101
def start_server():
70102
def is_port_in_use(port):
@@ -78,14 +110,18 @@ def run():
78110
while is_port_in_use(node_server_port) and tries < 99:
79111
node_server_port += 1
80112
tries += 1
113+
config = ConfigObj(settings_conf_path)
114+
config["server"]["port"] = node_server_port
115+
config.write()
81116
uvicorn.run(
82117
node_server.main(),
83118
host="127.0.0.1",
84119
port=node_server_port,
85120
log_level="warning",
86121
)
87-
except Exception:
88-
print("[WARN] Failed to launch node-server. Seamless connect feature is disabled.")
122+
123+
except Exception as e:
124+
print(f"[WARN] Failed to launch node-server: {str(e)}")
89125

90126
t = threading.Thread(target=run, daemon=True)
91127
t.start()
@@ -146,6 +182,7 @@ def main():
146182

147183
kill_old_process(Path.cwd().parent / "pid.txt")
148184
check_min_python_version(min_python_version="3.11", show_warning=True)
185+
create_config_file()
149186
update_outdated_modules()
150187
monkeypatch_fromisoformat()
151188
start_server()
@@ -531,23 +568,6 @@ def PreProcess(log_dir=None):
531568
current_path_file = TMP_INI_FILE
532569
ConfigModule.clean_config_file(current_path_file)
533570
ConfigModule.add_section("sectionOne", current_path_file)
534-
535-
if not ConfigModule.has_section("Selenium_driver_paths"):
536-
ConfigModule.add_section("Selenium_driver_paths")
537-
ConfigModule.add_config_value("Selenium_driver_paths", "chrome_path", "")
538-
ConfigModule.add_config_value("Selenium_driver_paths", "firefox_path", "")
539-
ConfigModule.add_config_value("Selenium_driver_paths", "edge_path", "")
540-
ConfigModule.add_config_value("Selenium_driver_paths", "opera_path", "")
541-
ConfigModule.add_config_value("Selenium_driver_paths", "ie_path", "")
542-
if not ConfigModule.get_config_value(
543-
"Selenium_driver_paths", "electron_chrome_path"
544-
):
545-
ConfigModule.add_config_value(
546-
"Selenium_driver_paths", "electron_chrome_path", ""
547-
)
548-
549-
# If `log_dir` is not specified, then store all logs inside Zeuz Node's
550-
# "AutomationLog" folder
551571
if log_dir is None:
552572
log_dir = TMP_INI_FILE.parent
553573

0 commit comments

Comments
 (0)