Skip to content

Commit

Permalink
Browser testing via Selenium now supported
Browse files Browse the repository at this point in the history
  • Loading branch information
damianlewis committed May 3, 2018
1 parent f4f51c1 commit 01a61f9
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 3 deletions.
31 changes: 31 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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|
Expand Down
6 changes: 4 additions & 2 deletions devbox.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ ip: "192.168.10.10"
site: site.test
root: /vagrant

databases:
- dbname
#selenium: true

#databases:
# - dbname
26 changes: 26 additions & 0 deletions scripts/add-selenium-commands.sh
Original file line number Diff line number Diff line change
@@ -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}
45 changes: 45 additions & 0 deletions scripts/install-chrome+chromedriver.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion scripts/install-envoy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions scripts/install-selenium.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 01a61f9

Please sign in to comment.