Created
March 15, 2025 09:17
-
-
Save s4l1h/f54e0f517308c0a23770ba31164238ba to your computer and use it in GitHub Desktop.
SeleniumBase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
echo Removing Selenium Grid Hub and Node services... | |
echo Current date and time: %DATE% %TIME% | |
REM Set variables | |
set NSSM_PATH=C:\nssm\nssm.exe | |
REM Check if NSSM exists | |
if not exist "%NSSM_PATH%" ( | |
echo ERROR: NSSM not found at %NSSM_PATH%. Please update NSSM_PATH or install NSSM. | |
pause | |
exit /b 1 | |
) | |
REM Stop and remove Selenium Grid Hub service | |
echo Stopping and removing SeleniumGridHub service... | |
"%NSSM_PATH%" stop SeleniumGridHub | |
"%NSSM_PATH%" remove SeleniumGridHub confirm | |
if %ERRORLEVEL% EQU 0 ( | |
echo SeleniumGridHub service removed successfully. | |
) else ( | |
echo WARNING: Failed to remove SeleniumGridHub. It may not exist. | |
) | |
REM Stop and remove Selenium Grid Node service | |
echo Stopping and removing SeleniumGridNode service... | |
"%NSSM_PATH%" stop SeleniumGridNode | |
"%NSSM_PATH%" remove SeleniumGridNode confirm | |
if %ERRORLEVEL% EQU 0 ( | |
echo SeleniumGridNode service removed successfully. | |
) else ( | |
echo WARNING: Failed to remove SeleniumGridNode. It may not exist. | |
) | |
echo Removal process complete! | |
echo Note: This only removes the services. Files in C:\SeleniumGrid remain. | |
pause |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
echo Setting up SeleniumBase with Selenium Grid Hub, Node, and NSSM services using a virtual environment... | |
echo Current date and time: %DATE% %TIME% | |
REM Set variables (adjusted for your Python path) | |
set PYTHON_PATH=C:\Users\Administrator\AppData\Local\Programs\Python\Python313\python.exe | |
set NSSM_PATH=C:\nssm\nssm.exe | |
REM Adjust NSSM_PATH above if NSSM is installed elsewhere (e.g., C:\Tools\nssm.exe) | |
set BASE_DIR=C:\SeleniumGrid | |
set VENV_DIR=%BASE_DIR%\venv | |
set HUB_PORT=4444 | |
set NODE_PORT=5555 | |
set HUB_IP=127.0.0.1 | |
REM Check if NSSM exists | |
if not exist "%NSSM_PATH%" ( | |
echo ERROR: NSSM not found at %NSSM_PATH%. Please update NSSM_PATH or install NSSM. | |
pause | |
exit /b 1 | |
) | |
REM Check if Java is installed | |
java -version >nul 2>&1 | |
if %ERRORLEVEL% NEQ 0 ( | |
echo ERROR: Java is not installed or not in PATH. Install Java JDK and add it to PATH. | |
pause | |
exit /b 1 | |
) | |
REM Create base directory if it doesn't exist | |
if not exist "%BASE_DIR%" mkdir "%BASE_DIR%" | |
REM Step 1: Create and activate virtual environment | |
echo Creating and activating virtual environment... | |
"%PYTHON_PATH%" -m venv "%VENV_DIR%" | |
call "%VENV_DIR%\Scripts\activate.bat" | |
REM Step 2: Install SeleniumBase in the virtual environment | |
echo Installing SeleniumBase in virtual environment... | |
"%VENV_DIR%\Scripts\python.exe" -m pip install --upgrade pip | |
"%VENV_DIR%\Scripts\python.exe" -m pip install --upgrade seleniumbase | |
REM Step 3: Download Selenium Server JAR for Grid | |
echo Downloading Selenium Server JAR... | |
"%VENV_DIR%\Scripts\python.exe" -m seleniumbase download server | |
move selenium_server_*.jar "%BASE_DIR%\selenium-server.jar" | |
REM Step 4: Pre-install browser drivers | |
echo Pre-installing browser drivers... | |
"%VENV_DIR%\Scripts\python.exe" -m seleniumbase get chromedriver | |
"%VENV_DIR%\Scripts\python.exe" -m seleniumbase get geckodriver | |
"%VENV_DIR%\Scripts\python.exe" -m seleniumbase get edgedriver | |
REM Step 5: Configure Selenium Grid Hub as a service using NSSM | |
echo Configuring Selenium Grid Hub as a service... | |
( | |
echo @echo off | |
echo cd "%BASE_DIR%" | |
echo call "%VENV_DIR%\Scripts\activate.bat" | |
echo seleniumbase grid-hub start | |
) > "%BASE_DIR%\start_hub.bat" | |
"%NSSM_PATH%" install SeleniumGridHub "%BASE_DIR%\start_hub.bat" | |
"%NSSM_PATH%" set SeleniumGridHub Description "Selenium Grid Hub Service (SeleniumBase in venv)" | |
"%NSSM_PATH%" set SeleniumGridHub Start SERVICE_AUTO_START | |
"%NSSM_PATH%" set SeleniumGridHub AppStdout "%BASE_DIR%\hub.log" | |
"%NSSM_PATH%" set SeleniumGridHub AppStderr "%BASE_DIR%\hub_err.log" | |
"%NSSM_PATH%" set SeleniumGridHub AppDirectory "%BASE_DIR%" | |
"%NSSM_PATH%" start SeleniumGridHub | |
REM Step 6: Configure Selenium Grid Node with multiple drivers as a service | |
echo Configuring Selenium Grid Node as a service... | |
( | |
echo @echo off | |
echo cd "%BASE_DIR%" | |
echo call "%VENV_DIR%\Scripts\activate.bat" | |
echo seleniumbase grid-node start --hub=%HUB_IP% | |
) > "%BASE_DIR%\start_node.bat" | |
"%NSSM_PATH%" install SeleniumGridNode "%BASE_DIR%\start_node.bat" | |
"%NSSM_PATH%" set SeleniumGridNode Description "Selenium Grid Node with multiple drivers (venv)" | |
"%NSSM_PATH%" set SeleniumGridNode Start SERVICE_AUTO_START | |
"%NSSM_PATH%" set SeleniumGridNode AppStdout "%BASE_DIR%\node.log" | |
"%NSSM_PATH%" set SeleniumGridNode AppStderr "%BASE_DIR%\node_err.log" | |
"%NSSM_PATH%" set SeleniumGridNode AppDirectory "%BASE_DIR%" | |
"%NSSM_PATH%" start SeleniumGridNode | |
REM Step 7: Verify services | |
echo Verifying services... | |
"%NSSM_PATH%" status SeleniumGridHub | |
"%NSSM_PATH%" status SeleniumGridNode | |
REM Deactivate virtual environment | |
call "%VENV_DIR%\Scripts\deactivate.bat" | |
echo Setup complete! | |
echo - Selenium Grid Hub is running on http://%HUB_IP%:%HUB_PORT%/grid/console | |
echo - Node is connected to the Hub with Chrome, Firefox, and Edge support. | |
echo To test, run: pytest your_test.py --server=%HUB_IP% --port=%HUB_PORT% | |
pause |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
echo Stopping Selenium Grid Hub and Node services... | |
echo Current date and time: %DATE% %TIME% | |
REM Set variables | |
set NSSM_PATH=C:\nssm\nssm.exe | |
REM Check if NSSM exists | |
if not exist "%NSSM_PATH%" ( | |
echo ERROR: NSSM not found at %NSSM_PATH%. Please update NSSM_PATH or install NSSM. | |
pause | |
exit /b 1 | |
) | |
REM Stop Selenium Grid Hub service | |
echo Stopping SeleniumGridHub service... | |
"%NSSM_PATH%" stop SeleniumGridHub | |
if %ERRORLEVEL% EQU 0 ( | |
echo SeleniumGridHub stopped successfully. | |
) else ( | |
echo WARNING: Failed to stop SeleniumGridHub. It may not be running. | |
) | |
REM Stop Selenium Grid Node service | |
echo Stopping SeleniumGridNode service... | |
"%NSSM_PATH%" stop SeleniumGridNode | |
if %ERRORLEVEL% EQU 0 ( | |
echo SeleniumGridNode stopped successfully. | |
) else ( | |
echo WARNING: Failed to stop SeleniumGridNode. It may not be running. | |
) | |
REM Verify services are stopped | |
echo Verifying service status... | |
"%NSSM_PATH%" status SeleniumGridHub | |
"%NSSM_PATH%" status SeleniumGridNode | |
echo Stop process complete! | |
pause |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment