Selenium Grid Extras helps with keeping your selenium drivers up to date and nodes stable
Fortunately, there's a pretty neat open source project that adds a few maintenance extras on top of Selenium Grid.https://github.com/groupon/Selenium-Grid-Extras
Selenium Grid Extras gives you the following
- Rebooting nodes upon running 10 (or a configurable number of tests)
- auto updating Selenium Server and Selenium drivers such as IEDriverServer and ChromeDriver to the latest upon each machine boot.
- Test recording
Installing it using BoxStarter
Of course, as a small group of test engineer that needs to support multiple OS and Browsers, you'll quickly find yourself out numbered by the machines you need to manage on the day to day basis. Wouldn't it be great to simply wipe out your VMs, and apply a install script that installs things you need and have a box ready to join the grid? However the annoying thing is you have a fresh machine on the network, and you need to copy over installation files, deploy, and configure.
Using boxstarter, http://boxstarter.org/, you can use gists, to help accelerate you setup. Boxstarter is a unique project in that you can use GitHubs gists to store PowerShell commands that call Chocolatey installs, https://chocolatey.org/. Using a simple Boxstarter formula, you can automate installing all your browsers, copying over Selenium Grid Extras, and writing config files to disk so they're ready to go.
Here's a sample of how I did mine, I have 2 configs, 1 for Hub, and 1 for Node. It installs SeleniumGridExtras on the machine, with a configuration file, and Selenium Grid Extra using it's autoupgrade feature will download the latest WebDrivers.
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
############################################################################################## | |
# Powershell script for installing Selenium Grid Extras in Hub Mode | |
# Navigate with internet explorer to: | |
# http://boxstarter.org/package/nr/url? + raw gist url | |
# | |
############################################################################################## | |
# Boxstarter options | |
$Boxstarter.RebootOk=$true # Allow reboots? | |
$Boxstarter.NoPassword=$false # Is this a machine with no login password? | |
$Boxstarter.AutoLogin=$true # Save my password securely and auto-login after a reboot | |
# install powershell | |
choco install powershell | |
if (Test-PendingReboot) { Invoke-Reboot } | |
$seleniumGridPath = "c:\SeleniumGrid" | |
$seleniumGridExtraDownloadUrl = "https://github.com/groupon/Selenium-Grid-Extras/releases/download/v1.7.1/SeleniumGridExtras-1.7.1-SNAPSHOT-jar-with-dependencies.jar" | |
#install dependencies | |
choco install javaruntime | |
# Creating Dir | |
New-Item -Force -ItemType directory -Path $seleniumGridPath | |
# Downloading Selenium Grid Extra | |
Invoke-WebRequest $seleniumGridExtraDownloadUrl -OutFile $seleniumGridPath\selenium-grid-extras.jar | |
# Create selenium_grid_extras_config.json file using decoded base64 version of our desired settings. | |
$Base64EncodedGridExtrasConfig = "ewogICJ0aGVDb25maWdNYXAiOiB7CiAgICAiYXV0b19zdGFydF9odWIiOiAiMSIsCiAgICAiZGVmYXVsdF9yb2xlIjogImh1YiIsCiAgICAidmlkZW9fcmVjb3JkaW5nX29wdGlvbnMiOiB7CiAgICAgICJ2aWRlb3NfdG9fa2VlcCI6ICI0MCIKICAgIH0sCiAgICAibm9kZV9jb25maWdfZmlsZXMiOiBbCiAgICAgICJub2RlXzU1NTUuanNvbiIKICAgIF0sCiAgICAiaHViX2NvbmZpZyI6IHt9LAogICAgImh1Yl9jb25maWdfZmlsZXMiOiBbCiAgICAgICJodWJfNDQ0NC5qc29uIgogICAgXSwKICAgICJpZWRyaXZlciI6IHsKICAgICAgInZlcnNpb24iOiAiMi40NC4wIgogICAgfSwKICAgICJhdXRvX3N0YXJ0X25vZGUiOiAiMSIsCiAgICAiYXV0b191cGRhdGVfZHJpdmVycyI6ICIxIiwKICAgICJjaHJvbWVkcml2ZXIiOiB7CiAgICAgICJ2ZXJzaW9uIjogIjIuMTIiCiAgICB9LAogICAgIndlYmRyaXZlciI6IHsKICAgICAgInZlcnNpb24iOiAiMi40NC4wIgogICAgfQogIH0KfQ==" | |
$DecodedGridExtrasConfig = [System.Convert]::FromBase64String($Base64EncodedGridExtrasConfig) | |
Set-Content -Path $seleniumGridPath\selenium_grid_extras_config.json -Value $DecodedGridExtrasConfig -Encoding Byte | |
# create hub config | |
$Base64EncodedHubConfig = "ewogICJwb3J0IjogNDQ0NCwKICAibmV3U2Vzc2lvbldhaXRUaW1lb3V0IjogMjUwMDAsCiAgInNlcnZsZXRzIjogWwogICAgImNvbS5ncm91cG9uLnNlbGVuaXVtZ3JpZGV4dHJhcy5ncmlkLnNlcnZsZXRzLlNlbGVuaXVtR3JpZEV4dHJhc1NlcnZsZXQiLAogICAgImNvbS5ncm91cG9uLnNlbGVuaXVtZ3JpZGV4dHJhcy5ncmlkLnNlcnZsZXRzLlByb3h5U3RhdHVzSnNvblNlcnZsZXQiCiAgXSwKICAiY2FwYWJpbGl0eU1hdGNoZXIiOiAib3JnLm9wZW5xYS5ncmlkLmludGVybmFsLnV0aWxzLkRlZmF1bHRDYXBhYmlsaXR5TWF0Y2hlciIsCiAgInRocm93T25DYXBhYmlsaXR5Tm90UHJlc2VudCI6IHRydWUsCiAgIm5vZGVQb2xsaW5nIjogNTAwMCwKICAiY2xlYW5VcEN5Y2xlIjogNTAwMCwKICAiYnJvd3NlclRpbWVvdXQiOiAxMjAwMDAsCiAgInRpbWVvdXQiOiAxMjAwMDAsCiAgIm1heFNlc3Npb24iOiA1Cn0=" | |
$DecodedHubConfig = [System.Convert]::FromBase64String($Base64EncodedHubConfig) | |
Set-Content -Path $seleniumGridPath\hub_4444.json -Value $DecodedHubConfig -Encoding Byte | |
# create node config | |
$Base64EncodedNodeConfig = "ewogICJjYXBhYmlsaXRpZXMiOiBbCiAgICB7CiAgICAgICJwbGF0Zm9ybSI6ICJWSVNUQSIsCiAgICAgICJzZWxlbml1bVByb3RvY29sIjogIldlYkRyaXZlciIsCiAgICAgICJicm93c2VyTmFtZSI6ICJjaHJvbWUiLAogICAgICAibWF4SW5zdGFuY2VzIjogMwogICAgfSwKICAgIHsKICAgICAgInBsYXRmb3JtIjogIlZJU1RBIiwKICAgICAgInNlbGVuaXVtUHJvdG9jb2wiOiAiV2ViRHJpdmVyIiwKICAgICAgImJyb3dzZXJOYW1lIjogImludGVybmV0IGV4cGxvcmVyIiwKICAgICAgIm1heEluc3RhbmNlcyI6IDEKICAgIH0sCiAgICB7CiAgICAgICJwbGF0Zm9ybSI6ICJWSVNUQSIsCiAgICAgICJzZWxlbml1bVByb3RvY29sIjogIldlYkRyaXZlciIsCiAgICAgICJicm93c2VyTmFtZSI6ICJmaXJlZm94IiwKICAgICAgIm1heEluc3RhbmNlcyI6IDMKICAgIH0KICBdLAogICJjb25maWd1cmF0aW9uIjogewogICAgInByb3h5IjogImNvbS5ncm91cG9uLnNlbGVuaXVtZ3JpZGV4dHJhcy5ncmlkLnByb3hpZXMuU2V0dXBUZWFyZG93blByb3h5IiwKICAgICJtYXhTZXNzaW9uIjogMywKICAgICJwb3J0IjogNTU1NSwKICAgICJyZWdpc3RlciI6IHRydWUsCiAgICAidW5yZWdpc3RlcklmU3RpbGxEb3duQWZ0ZXIiOiAxMDAwMCwKICAgICJodWJQb3J0IjogNDQ0NCwKICAgICJodWJIb3N0IjogIjEyNy4wLjAuMSIsCiAgICAibm9kZVN0YXR1c0NoZWNrVGltZW91dCI6IDEwMDAwLAogICAgImRvd25Qb2xsaW5nTGltaXQiOiAwCiAgfQp9" | |
$DecodedNodeConfig = [System.Convert]::FromBase64String($Base64EncodedNodeConfig) | |
Set-Content -Path $seleniumGridPath\node_5555.json -Value $DecodedNodeConfig -Encoding Byte | |
# Create Start.bat file | |
Set-Content -Path $seleniumGridPath\starthub.bat -Value "cd $seleniumGridPath&java -jar selenium-grid-extras.jar" | |
schtasks.exe /Create /SC ONLOGON /TN "StartSeleniumHub" /TR "cmd /c ""C:\SeleniumGrid\starthub.bat""" | |
cd $seleniumGridPath | |
java -jar selenium-grid-extras.jar | |
if (Test-PendingReboot) { Invoke-Reboot } |
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
############################################################################################## | |
# Powershell script for installing Selenium Grid Extras in Node Mode with latest version | |
# of Chrome and Firefox | |
# Navigate with internet explorer to: | |
# http://boxstarter.org/package/nr/url? + raw gist url | |
# | |
############################################################################################## | |
choco install powershell | |
if (Test-PendingReboot) { Invoke-Reboot } | |
$seleniumGridPath = "c:\SeleniumGrid" | |
$seleniumGridExtraDownloadUrl = "https://github.com/groupon/Selenium-Grid-Extras/releases/download/v1.7.1/SeleniumGridExtras-1.7.1-SNAPSHOT-jar-with-dependencies.jar" | |
# install dependencies and browsers | |
choco install javaruntime | |
choco install Firefox | |
choco install GoogleChrome | |
# Creating Dir | |
New-Item -Force -ItemType directory -Path $seleniumGridPath | |
# Downloading Selenium Grid Extra | |
Invoke-WebRequest $seleniumGridExtraDownloadUrl -OutFile $seleniumGridPath\selenium-grid-extras.jar | |
# Create grid extras config | |
$Base64EncodedGridExtrasConfig = "ewogICJ0aGVDb25maWdNYXAiOiB7CiAgICAiYXV0b19zdGFydF9odWIiOiAiMCIsCiAgICAicmVib290X2FmdGVyX3Nlc3Npb25zIjogIjEwIiwKICAgICJkZWZhdWx0X3JvbGUiOiAibm9kZSIsCiAgICAidmlkZW9fcmVjb3JkaW5nX29wdGlvbnMiOiB7CiAgICAgICJ2aWRlb3NfdG9fa2VlcCI6ICI0MCIKICAgIH0sCiAgICAibm9kZV9jb25maWdfZmlsZXMiOiBbCiAgICAgICJub2RlXzU1NTUuanNvbiIKICAgIF0sCiAgICAiaHViX2NvbmZpZyI6IHt9LAogICAgImh1Yl9jb25maWdfZmlsZXMiOiBbXSwKICAgICJpZWRyaXZlciI6IHsKICAgICAgInZlcnNpb24iOiAiMi40NC4wIgogICAgfSwKICAgICJhdXRvX3N0YXJ0X25vZGUiOiAiMSIsCiAgICAiYXV0b191cGRhdGVfZHJpdmVycyI6ICIxIiwKICAgICJjaHJvbWVkcml2ZXIiOiB7CiAgICAgICJ2ZXJzaW9uIjogIjIuMTMiCiAgICB9LAogICAgIndlYmRyaXZlciI6IHsKICAgICAgInZlcnNpb24iOiAiMi40NC4wIgogICAgfQogIH0KfQ==" | |
$DecodedGridExtrasConfig = [System.Convert]::FromBase64String($Base64EncodedGridExtrasConfig) | |
Set-Content -Path $seleniumGridPath\selenium_grid_extras_config.json -Value $DecodedGridExtrasConfig -Encoding Byte | |
# create node config | |
$Base64EncodedNodeConfig = "ewogICJjYXBhYmlsaXRpZXMiOiBbCiAgICB7CiAgICAgICJwbGF0Zm9ybSI6ICJWSVNUQSIsCiAgICAgICJzZWxlbml1bVByb3RvY29sIjogIldlYkRyaXZlciIsCiAgICAgICJicm93c2VyTmFtZSI6ICJjaHJvbWUiLAogICAgICAibWF4SW5zdGFuY2VzIjogMwogICAgfSwKICAgIHsKICAgICAgInBsYXRmb3JtIjogIlZJU1RBIiwKICAgICAgInNlbGVuaXVtUHJvdG9jb2wiOiAiV2ViRHJpdmVyIiwKICAgICAgImJyb3dzZXJOYW1lIjogImludGVybmV0IGV4cGxvcmVyIiwKICAgICAgIm1heEluc3RhbmNlcyI6IDEKICAgIH0sCiAgICB7CiAgICAgICJwbGF0Zm9ybSI6ICJWSVNUQSIsCiAgICAgICJzZWxlbml1bVByb3RvY29sIjogIldlYkRyaXZlciIsCiAgICAgICJicm93c2VyTmFtZSI6ICJmaXJlZm94IiwKICAgICAgIm1heEluc3RhbmNlcyI6IDMKICAgIH0KICBdLAogICJjb25maWd1cmF0aW9uIjogewogICAgInByb3h5IjogImNvbS5ncm91cG9uLnNlbGVuaXVtZ3JpZGV4dHJhcy5ncmlkLnByb3hpZXMuU2V0dXBUZWFyZG93blByb3h5IiwKICAgICJtYXhTZXNzaW9uIjogMywKICAgICJwb3J0IjogNTU1NSwKICAgICJyZWdpc3RlciI6IHRydWUsCiAgICAidW5yZWdpc3RlcklmU3RpbGxEb3duQWZ0ZXIiOiAxMDAwMCwKICAgICJodWJQb3J0IjogNDQ0NCwKICAgICJodWJIb3N0IjogInNlbGVuaXVtaHViIiwKICAgICJub2RlU3RhdHVzQ2hlY2tUaW1lb3V0IjogMTAwMDAsCiAgICAiZG93blBvbGxpbmdMaW1pdCI6IDAKICB9Cn0=" | |
$DecodedNodeConfig = [System.Convert]::FromBase64String($Base64EncodedNodeConfig) | |
Set-Content -Path $seleniumGridPath\node_5555.json -Value $DecodedNodeConfig -Encoding Byte | |
# Create Start.bat file | |
Set-Content -Path $seleniumGridPath\startnode.bat -Value "cd $seleniumGridPath&java -jar selenium-grid-extras.jar" | |
schtasks.exe /Create /SC ONLOGON /TN "StartSeleniumNode" /TR "cmd /c ""C:\SeleniumGrid\startnode.bat""" | |
cd $seleniumGridPath | |
java -jar selenium-grid-extras.jar | |
if (Test-PendingReboot) { Invoke-Reboot } |
The end result is you can use the URL of either gist to instantly setup a Selenium Grid machine.
No comments:
Post a Comment