Skip to content

Instantly share code, notes, and snippets.

@lazypower
Last active February 17, 2020 22:20
Show Gist options
  • Save lazypower/8030755 to your computer and use it in GitHub Desktop.
Save lazypower/8030755 to your computer and use it in GitHub Desktop.
Setup headless chromium driver for selenium (vagrant flavor, but works with any ubuntu variant)
#!/bin/sh
set -e
if [ -e /.installed ]; then
echo 'Already installed.'
else
echo ''
echo 'INSTALLING'
echo '----------'
# Add Google public key to apt
wget -q -O - "https://dl-ssl.google.com/linux/linux_signing_key.pub" | sudo apt-key add -
# Add Google to the apt-get source list
echo 'deb http://dl.google.com/linux/chrome/deb/ stable main' >> /etc/apt/sources.list
# Update app-get
apt-get update
# Install Java, Chrome, Xvfb, and unzip
apt-get -y install openjdk-7-jre google-chrome-stable xvfb unzip
# Download and copy the ChromeDriver to /usr/local/bin
cd /tmp
wget "https://chromedriver.googlecode.com/files/chromedriver_linux64_2.2.zip"
wget "https://selenium.googlecode.com/files/selenium-server-standalone-2.35.0.jar"
unzip chromedriver_linux64_2.2.zip
mv chromedriver /usr/local/bin
mv selenium-server-standalone-2.35.0.jar /usr/local/bin
# So that running `vagrant provision` doesn't redownload everything
touch /.installed
fi
# Start Xvfb, Chrome, and Selenium in the background
export DISPLAY=:10
cd /vagrant
echo "Starting Xvfb ..."
Xvfb :10 -screen 0 1366x768x24 -ac &
echo "Starting Google Chrome ..."
google-chrome --remote-debugging-port=9222 &
echo "Starting Selenium ..."
cd /usr/local/bin
nohup java -jar ./selenium-server-standalone-2.35.0.jar &
# encoding: utf-8
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "precise64"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
config.ssh.forward_agent = true
config.vm.provider :aws do |aws, override|
aws.access_key_id = 'XXXX' # Replace this
aws.secret_access_key = 'XXXX' # Replace this
aws.keypair_name = 'XXXX' # Replace this
aws.ami = 'ami-7747d01e' # ubuntu 12.04
override.ssh.username = 'ubuntu'
override.ssh.private_key_path = '~/.ssh/amazon-ubuntu.pem'
end
config.vm.provision :shell, :path => "setup.sh"
config.vm.network :forwarded_port, guest:4444, host:4444
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment