Skip to content

Instantly share code, notes, and snippets.

@RobDWaller
Created March 21, 2018 15:04
Show Gist options
  • Save RobDWaller/47c18c12c28ac581d413aa655cbcb261 to your computer and use it in GitHub Desktop.
Save RobDWaller/47c18c12c28ac581d413aa655cbcb261 to your computer and use it in GitHub Desktop.
Add Selenium and Chrome to Vagrant for testing
# If you need to add Selenium and Chrome to a Vagrant box for testing purposes the below deployment script should help.
# Currently works with Scotchbox, but should be fine on any Ubuntu Vagrant.
# -*- mode: ruby -*-
# vi: set ft=ruby :
$script = <<SCRIPT
# Install Java and accept terms and conditions
sudo add-apt-repository ppa:webupd8team/java -y
sudo apt-get update -y
echo debconf shared/accepted-oracle-license-v1-1 select true | sudo debconf-set-selections
echo debconf shared/accepted-oracle-license-v1-1 seen true | sudo debconf-set-selections
sudo apt-get install -y oracle-java8-installer
# Install Selenium: Remember to update the version
sudo mkdir /usr/local/share/selenium
sudo wget http://selenium-release.storage.googleapis.com/3.11/selenium-server-standalone-3.11.0.jar -P /usr/local/share/selenium
# Install Chrome Driver: Remember to update the version
sudo wget https://chromedriver.storage.googleapis.com/2.37/chromedriver_linux64.zip -P /usr/local/share
sudo unzip /usr/local/share/chromedriver_linux64.zip -d /usr/local/share
sudo rm /usr/local/share/chromedriver_linux64.zip
# Install Chrome Browser
sudo apt-get install -y libxss1 libappindicator1 libindicator7
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb -P ~/
sudo dpkg -i ~/google-chrome*.deb
sudo apt-get install -f -y
# Turn on Selenium
java -jar -Dwebdriver.chrome.driver="/usr/local/share/chromedriver" /usr/local/share/selenium/selenium-server-standalone-3.11.0.jar >/dev/null 2>&1 &
SCRIPT
Vagrant.configure("2") do |config|
config.vm.box = "scotch/box"
config.vm.network "private_network", ip: "192.168.33.10"
config.vm.hostname = "scotchbox"
# Optional NFS. Make sure to remove other synced_folder line too
config.vm.synced_folder ".", "/var/www", :mount_options => ["dmode=777","fmode=777"]
config.vm.provision "shell", inline: $script
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment