rem We have Phyton but let's check if it's in the PATH
:HASPYTHON
@echo %version% Phyton is found, checking PATH variable
rem Check Phyton install path
set install_path=
for /f "tokens=2,*" %%a in ('reg query "hklm\SOFTWARE\%python_registry%Python\PythonCore\%version%\InstallPath"') do (
set install_path=%%b
)
set test=%install_path:~0,-1%
call %running_directory%inPath test && (@echo %test% is already in PATH) || (call %running_directory%addPath test & setx PATH "%PATH%;%test%" & @echo %test% set to local PATH)
set test=%install_path%Scripts
call %running_directory%inPath test && (@echo %test% is already in PATH) || (call %running_directory%addPath test & setx PATH "%PATH%;%test%" & @echo %test% set to local PATH)
GOTO PIP_CHECK
rem Check whether PIP is installed or not
:PIP_CHECK
@echo.
@echo Checking if PIP is installed
IF EXIST %install_path%Scripts/PIP.exe GOTO PIP_VERSION_CHECK
@echo No PIP found, commencing PIP install
call phyton %running_directory%get-pip.py
rem Try to update the PIP
:PIP_VERSION_CHECK
@echo PIP is found
@echo Checking whether the latest PIP is installed
call python -m pip install --upgrade pip
SET "pip_program=selenium"
GOTO PIP_PACKAGE_CHECK
rem Check if the PIP package is installed or not
:PIP_PACKAGE_CHECK
@echo.
@echo Check whether !pip_program! is installed
for /f "tokens=1,2 delims===" %%a in ('call python -m pip freeze') do (
if "%%a"=="!pip_program!" (
@echo %%b !pip_program! is found
GOTO PIP_PACKAGE_UPDATE
)
)
@echo No !pip_program! version is found, commencing install
for /f tokens^=3^ delims^=^" %%B in ('type "%Temp%\BROW5.reg" ^| find "@"') do (
set "default=%%B"
rem removing double slashes
set "default=!default:\\=\!"
rem removing end slash
set "default=!default:~0,-1!"
rem get the name
for %%D in ("!default!") do (
call :SUB_DEFAULTBROWSER %%~nD
)
)
del /Q /F "%Temp%\BROW5.reg"
)
) else (
rem Registry location depends of the architecture
if "!architecture!"=="64" (
set "browser_architect=Wow6432Node\"
set "architecture_name=x64"
) else (
if "!architecture!"=="32" (
set "browser_architect="
set "architecture_name=x86"
) else (
GOTO ERR
)
)
rem Registry names for the different browsers out there
if "!browserToUse!"=="firefox" (
set "browser_path_name=FIREFOX.EXE"
set "selenium_driver_name="
)
if "!browserToUse!"=="chrome" (
set "browser_path_name=Google Chrome"
set "selenium_driver_name=chromedriver.exe"
)
if "!browserToUse!"=="iexplore" (
set "browser_path_name=IEXPLORE.EXE"
set "selenium_driver_name=IEDriverServer.exe"
)
rem Opera have to versions (in the registry) Opera and OperaStable, we try to Stable first
if "!browserToUse!"=="opera" (
set "browser_path_name=OperaStable"
set "selenium_driver_name="
)
set "browser_path="
@echo Check if !browserToUse!.exe is in PATH
:get_browser_path
set browser_path=
set query="hklm\SOFTWARE\%browser_architect%Clients\StartMenuInternet\%browser_path_name%\shell\open\command"
reg>nul query %query% 2>nul
if ERRORLEVEL 1 (
if "%browser_path%"=="" (
if "%browser_architect%"=="" (
rem If the Stable failed check out the simple Opera
if "%browser_path_name%"=="OperaStable" (
SET "browser_path_name=Opera"
SET "browser_architect=Wow6432Node\"
goto get_browser_path
)
@echo Location not found^^! Please add !browserToUse!.exe to PATH manually
pause
) else (
set "browser_architect="
goto get_browser_path
)
)
)
rem Get the installation path for the selected browser
for /f "tokens=2,*" %%a in ('reg query %query%') do (
set browser_path=%%b
)
set browser_path=%browser_path:"=%
call :Split "%browser_path%" test
set myTest=!test:~0,-1!
rem Set that path in the PATH environment variable
call %running_directory%inPath myTest && (@echo !myTest! is already in PATH) || (call %running_directory%addPath myTest & setx PATH "%PATH%;!myTest!" & @echo !myTest! set to local PATH)
if NOT "!selenium_driver_name!"=="" (
@echo Installing the !browserToUse! Selenium driver
call %running_directory%inPath install_location && (@echo !install_location! is already in PATH) || (call %running_directory%addPath install_location & setx PATH "%PATH%;!install_location!" & @echo !install_location! set to local PATH)