Skip to content

Downloading and running Selenium Grid with Powershell

Jakub Raczek edited this page Apr 30, 2019 · 2 revisions

Download, start in background and stop Selenium Grid with Powershell

Selenium Grid must be downloaded to the folder with Selenium Drivers. More details here

    $url = 'http://selenium-release.storage.googleapis.com/3.141/selenium-server-standalone-3.141.59.jar'
    
    $grid = 'selenium-server-standalone-3.141.59.jar'
    
    $output = ".\Ocaramba.Tests.NUnit\bin\Release\$grid"
    
    $outputLogs = ".\Ocaramba.Tests.NUnit\bin\Release\"
    
    $start_time = Get-Date

    echo "Downloading Selenium Grid from:" $url
    
    (New-Object System.Net.WebClient).DownloadFile($url, $output)
    
    echo "Selenium Grid downloaded to:" $output
    
    echo "Time taken to download $($grid): $((Get-Date).Subtract($start_time).Seconds) second(s)"
    
    echo '********************************Start Selenium Grid in background****************************************' 

    $appHub=Start-Process java -ArgumentList '-jar', $output' -role hub' -RedirectStandardOutput $outputLogs'console_hub.out' -RedirectStandardError $outputLogs'console_hub.err' -passthru`

    Start-Sleep -s 5
    
    echo "Selenium Grid hub started"

    $appNode=Start-Process java -ArgumentList '-jar', $output' -role node  -hub http://localhost:4444/grid/register' -RedirectStandardOutput $outputLogs'console_node.out' -RedirectStandardError $outputLogs'console_node.err' -passthru 
    
    Start-Sleep -s 5

    echo '*****************************Stop Selenium Grid****************************'

    echo "Stop Selenium Grid node" 
      
    Stop-Process -Id $appNode.Id
    
    echo "Stop Selenium Grid hub" 
    
    Stop-Process -Id $appHub.Id
Clone this wiki locally