diff --git a/Vagrantfile b/Vagrantfile index 818d7b8..6913fe5 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -12,16 +12,23 @@ supported_ubuntu = ["14.04", "16.04"] supported_webservers = ["apache", "nginx"] supported_php = ["5.5", "5.6", "7.0", "7.1"] supported_mysql = ["5.5", "5.6", "5.7"] +supported_java = ["8", "9"] default_ubuntu = "16.04" default_webserver = "nginx" default_php = "7.1" default_mysql = "5.7" +default_java = "8" +default_selenium = "3.8.1" +default_chromedriver = "latest" ubuntu_ver = settings["ubuntu-ver"] ||= default_ubuntu webserver = settings["webserver"] ||= default_webserver php_ver = settings["php-ver"] ||= default_php mysql_ver = settings["mysql-ver"] ||= default_mysql +java_ver = settings["java-ver"] ||= default_java +selenium_ver = settings["selenium-ver"] ||= default_selenium +chromedriver_ver = settings["chromedriver-ver"] ||= default_chromedriver enable_ssl = settings["ssl"] ||= false unless supported_ubuntu.include?(ubuntu_ver) @@ -52,6 +59,10 @@ if ubuntu_ver == "16.04" && mysql_ver == "5.6" abort("MySQL 5.6 isn't supported on Ubuntu 16.04.") end +unless supported_java.include?(java_ver) + abort("Java version #{java_ver} not supported. Only versions #{supported_java} are currently supported.") +end + # Set which devbox version to use if ubuntu_ver == "14.04" if php_ver == "5.5" @@ -151,6 +162,26 @@ Vagrant.configure("2") do |config| end end + # Install Google Chrome, ChromeDriver and Selenium Server + if settings.has_key?("selenium") && settings["selenium"] == true + config.vm.provision "shell" do |s| + s.name = "Installing Selenium Server" + s.path = script_dir + "/install-selenium.sh" + s.args = [java_ver, selenium_ver] + end + + config.vm.provision "shell" do |s| + s.name = "Installing Google Chrome and ChromeDriver" + s.path = script_dir + "/install-chrome+chromedriver.sh" + s.args = [chromedriver_ver != "latest" ? chromedriver_ver : ""] + end + + config.vm.provision "shell" do |s| + s.name = "Adding Selenium Server bash commands" + s.path = script_dir + "/add-selenium-commands.sh" + end + end + # Install Laravel Envoy if settings.has_key?("envoy") && settings["envoy"] == true config.vm.provision "shell" do |s| diff --git a/devbox.yaml b/devbox.yaml index 2b5be28..cde76ad 100644 --- a/devbox.yaml +++ b/devbox.yaml @@ -3,5 +3,7 @@ ip: "192.168.10.10" site: site.test root: /vagrant -databases: - - dbname \ No newline at end of file +#selenium: true + +#databases: +# - dbname \ No newline at end of file diff --git a/scripts/add-selenium-commands.sh b/scripts/add-selenium-commands.sh new file mode 100644 index 0000000..d8fe8f1 --- /dev/null +++ b/scripts/add-selenium-commands.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +profile_file='/home/vagrant/.profile' + +source="\n\n# Run Chrome via Selenium Server +start-chrome() { + xvfb-run java -Dwebdriver.chrome.driver=/usr/local/bin/chromedriver -jar /usr/local/bin/selenium-server-standalone.jar +} + +start-chrome-debug() { + xvfb-run java -Dwebdriver.chrome.driver=/usr/local/bin/chromedriver -jar /usr/local/bin/selenium-server-standalone.jar -debug +} + +# Run Chrome Headless +start-chrome-headless() { + chromedriver --url-base=/wd/hub +}" + +# Append Selenium Server commands to ~/.profile +if ! grep -cqs 'chromedriver' ${profile_file} +then + printf "$source" >> "$profile_file" +fi + +# Re-source user profiles +source ${profile_file} diff --git a/scripts/install-chrome+chromedriver.sh b/scripts/install-chrome+chromedriver.sh new file mode 100644 index 0000000..fafcbb6 --- /dev/null +++ b/scripts/install-chrome+chromedriver.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash + +[[ -n "$1" ]] && chromedriver_ver=$1 || chromedriver_ver=`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE` +is_updated=0 + +# Install Google Chrome. +if [[ -f "/usr/bin/google-chrome-stable" ]] +then + echo 'Google Chrome already installed' +else + curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add > /dev/null 2>&1 + echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list + apt-get update > /dev/null 2>&1 + is_updated=1 + apt-get -y install google-chrome-stable > /dev/null 2>&1 +fi + +# Install ChromeDriver. +if [[ -f "/usr/local/bin/chromedriver" ]] +then + echo 'ChromeDriver already installed' +else + if [[ ${is_updated} == 0 ]] + then + apt-get update > /dev/null 2>&1 + is_updated=1 + fi + apt-get -y install unzip > /dev/null 2>&1 + wget -N http://chromedriver.storage.googleapis.com/${chromedriver_ver}/chromedriver_linux64.zip -P ~/ > /dev/null 2>&1 + unzip ~/chromedriver_linux64.zip -d ~/ > /dev/null 2>&1 + rm ~/chromedriver_linux64.zip + mv -f ~/chromedriver /usr/local/bin/chromedriver +fi + +# Install Xvfb. +if [[ -f "/usr/bin/Xvfb" ]] +then + echo "Xvfb already installed" +else + if [[ ${is_updated} == 0 ]] + then + apt-get update > /dev/null 2>&1 + fi + apt-get -y install xvfb > /dev/null 2>&1 +fi \ No newline at end of file diff --git a/scripts/install-envoy.sh b/scripts/install-envoy.sh index 0c084ae..07af803 100644 --- a/scripts/install-envoy.sh +++ b/scripts/install-envoy.sh @@ -3,7 +3,7 @@ composer_bin_path='/home/vagrant/.config/composer/vendor/bin' # Check if Envoy has been installed -if [ -h "$composer_bin_path/envoy" ] +if [[ -h "$composer_bin_path/envoy" ]] then echo 'Laravel Envoy already installed' exit 0 diff --git a/scripts/install-selenium.sh b/scripts/install-selenium.sh new file mode 100644 index 0000000..6a63536 --- /dev/null +++ b/scripts/install-selenium.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +java_ver=$1 +selenium_ver=$2 +selenium_sub_dir=$(echo "$selenium_ver" | cut -d"." -f-2) + +# Install Java JRE +if [[ -f "/usr/bin/java" ]] +then + echo 'Java already installed' +else + apt-get update > /dev/null 2>&1 + apt-get -y install openjdk-${java_ver}-jre-headless > /dev/null 2>&1 +fi + +# Install Selenium Server Standalone +if [[ -f "/usr/local/bin/selenium-server-standalone.jar" ]] +then + echo 'Selenium Server Standalone already installed' +else + wget -N http://selenium-release.storage.googleapis.com/${selenium_sub_dir}/selenium-server-standalone-${selenium_ver}.jar -P ~/ > /dev/null 2>&1 + mv -f ~/selenium-server-standalone-${selenium_ver}.jar /usr/local/bin/selenium-server-standalone.jar +fi \ No newline at end of file