From 79649ef7d56e379e8385977d62f7ae33469024a4 Mon Sep 17 00:00:00 2001 From: Shriyansh Agnihotri Date: Sat, 7 Dec 2024 01:24:23 +0530 Subject: [PATCH] Adding Windows helper to install all relevant items before running hercules, also fixing filename as it was failing in windows, fixing extension load in windows as extension downloading fails --- README.md | 32 +++++++++++ helper_scripts/hercules_windows_setup.ps1 | 55 +++++++++++++++++++ .../core/autogen_simple_wrapper.py | 2 +- testzeus_hercules/core/playwright_manager.py | 4 ++ 4 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 helper_scripts/hercules_windows_setup.ps1 diff --git a/README.md b/README.md index 9e078d0..44c1e67 100644 --- a/README.md +++ b/README.md @@ -121,6 +121,38 @@ testzeus-hercules --input-file opt/input/test.feature --output-path opt/output - ``` +## ⚙️ Running Hercules on a Windows Machine + +To set up and run Hercules on a Windows machine: + +1. **Open PowerShell in Administrator Mode:** + - Click on the **Start Menu**, search for **PowerShell**, and right-click on **Windows PowerShell**. + - Select **Run as Administrator** to open PowerShell in administrator mode. + +2. **Navigate to the Helper Scripts Folder:** + - Use the `cd` command to navigate to the folder containing the `hercules_windows_setup.ps1` script. For example: + ```powershell + cd path\to\helper_scripts + ``` + +3. **Run the Setup Script:** + - Execute the script to install and configure Hercules: + ```powershell + .\hercules_windows_setup.ps1 + ``` + +4. **Follow On-Screen Instructions:** + - The script will guide you through installing Python, Playwright, FFmpeg, and other required dependencies. + +5. **Run Hercules:** + - Once the setup is complete, you can run Hercules from PowerShell or Command Prompt using the following command: + ```bash + testzeus-hercules --input-file opt/input/test.feature --output-path opt/output --test-data-path opt/test_data --llm-model gpt-4o --llm-model-api-key sk-proj-k....... + ``` + +--- + + #### Supported AI Models for TestZeus-Hercules - Anthropic Haiku: Compatible with Haiku 3.5 and above. - Groq: Supports any version with function calling and coding capabilities. diff --git a/helper_scripts/hercules_windows_setup.ps1 b/helper_scripts/hercules_windows_setup.ps1 new file mode 100644 index 0000000..1baba80 --- /dev/null +++ b/helper_scripts/hercules_windows_setup.ps1 @@ -0,0 +1,55 @@ +# Ensure the script runs with administrator privileges +if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { + Write-Host "This script must be run as Administrator!" -ForegroundColor Red + Exit 1 +} + +# Step 0: Temporarily bypass execution policy for this session +Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force + +# Step 1: Install Python 3.11 from Microsoft Store +Write-Host "Installing Python 3.11 from Microsoft Store..." -ForegroundColor Green +Start-Process -NoNewWindow -Wait "ms-windows-store://pdp/?productid=9NRWMJP3717K" + +# Step 2: Verify Python Installation +Write-Host "Verifying Python installation..." -ForegroundColor Green +if (-not (Get-Command python -ErrorAction SilentlyContinue)) { + Write-Host "Python is not installed or not in PATH. Please restart and try again after installation." -ForegroundColor Red + Exit 1 +} + +# Step 3: Upgrade pip +Write-Host "Upgrading pip..." -ForegroundColor Green +Start-Process -NoNewWindow -Wait -FilePath "python" -ArgumentList "-m", "pip", "install", "--upgrade", "pip" + +# Step 4: Install Playwright and Other Dependencies +Write-Host "Installing Playwright and other Python dependencies..." -ForegroundColor Green +Start-Process -NoNewWindow -Wait -FilePath "python" -ArgumentList "-m", "pip", "install", "--upgrade", "testzeus-hercules" +Start-Process -NoNewWindow -Wait -FilePath "python" -ArgumentList "-m", "pip", "install", "playwright" + +# Step 5: Install Playwright Dependencies +Write-Host "Installing Playwright dependencies..." -ForegroundColor Green +try { + python -m playwright install --with-deps + Write-Host "Playwright installed successfully." +} catch { + Write-Host "Failed to install Playwright dependencies. Ensure Playwright is installed correctly." -ForegroundColor Red +} + +# Step 6: Install FFmpeg +Write-Host "Downloading and installing FFmpeg..." -ForegroundColor Green +try { + $ffmpegZipURL = "https://github.com/BtbN/FFmpeg-Builds/releases/latest/download/ffmpeg-master-latest-win64-gpl.zip" + $ffmpegZipPath = "$env:TEMP\ffmpeg.zip" + $ffmpegExtractPath = "C:\ffmpeg" + Invoke-WebRequest -Uri $ffmpegZipURL -OutFile $ffmpegZipPath + Expand-Archive -Path $ffmpegZipPath -DestinationPath $ffmpegExtractPath -Force + $ffmpegBinPath = "$ffmpegExtractPath\bin" + [Environment]::SetEnvironmentVariable("Path", $([Environment]::GetEnvironmentVariable("Path", "User") + ";$ffmpegBinPath"), "User") + Write-Host "FFmpeg installed and added to PATH successfully." +} catch { + Write-Host "Failed to download or install FFmpeg." -ForegroundColor Red +} + +# Step 7: Notify user to restart the terminal +Write-Host "Setup complete! Please restart your terminal to apply PATH changes." -ForegroundColor Yellow diff --git a/testzeus_hercules/core/autogen_simple_wrapper.py b/testzeus_hercules/core/autogen_simple_wrapper.py index c4c2bc5..6daf2c4 100644 --- a/testzeus_hercules/core/autogen_simple_wrapper.py +++ b/testzeus_hercules/core/autogen_simple_wrapper.py @@ -367,7 +367,7 @@ def __save_chat_log( else: chat_logs_file = os.path.join( self.get_chat_logs_dir() or "", - f"log_between_sender-{sender.name}->rec-{receiver.name}_{str(datetime.datetime.now().isoformat())}.json", + f"log_between_sender-{sender.name}-rec-{receiver.name}_{str(datetime.datetime.now().strftime('%Y-%m-%dT%H-%M-%S-%f'))}.json", ) # Save the chat log to a file with open(chat_logs_file, "w") as file: diff --git a/testzeus_hercules/core/playwright_manager.py b/testzeus_hercules/core/playwright_manager.py index 3e3e5b7..4fd5d73 100644 --- a/testzeus_hercules/core/playwright_manager.py +++ b/testzeus_hercules/core/playwright_manager.py @@ -185,6 +185,10 @@ async def prepare_extension(self) -> None: """ Prepares the browser extension by downloading and caching it if necessary. """ + if os.name == "nt": # Skip extension preparation on Windows + logger.info("Skipping extension preparation on Windows.") + return + if self.browser_type == "chromium": extension_url = "https://github.com/gorhill/uBlock/releases/download/1.61.0/uBlock0_1.61.0.chromium.zip" extension_file_name = "uBlock0_1.61.0.chromium.zip"