Created
July 1, 2017 04:57
-
-
Save anjunatl/4ce7043ede9236aa9e7713c6d4c8ffe1 to your computer and use it in GitHub Desktop.
A modified version of a provision script used by Vagrant to set up a selenium and chromedriver environment to be used by webdriver IO
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
#! /bin/bash | |
## | |
## A modified version of https://github.com/fanatique/vagrant-selenium-vm/blob/master/script.sh | |
## to support running selenium-server-standalone with chromedriver w/ dbus | |
## | |
## If Chrome and WDIO are on separate environments (vagrant, docker, etc) you'll need to run | |
## Chrome with the `--no-sandbox` option to enable WDIO to connect from outside. | |
## | |
## Example accompanying WDIO configuration: | |
## | |
## capabilities: [{ | |
## browserName: 'chrome', | |
## "chromeOptions": { | |
## args: ['--no-sandbox'] | |
## } | |
## }], | |
set -e | |
if [ -e /.installed ]; then | |
echo 'Already installed.' | |
else | |
echo '' | |
echo 'Installing basic packages' | |
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 | |
add-apt-repository ppa:openjdk-r/ppa | |
apt-get update | |
# Install Java, Chrome, Xvfb, and unzip | |
apt-get -y install openjdk-8-jre google-chrome-stable xvfb unzip | |
# | |
# install dbus - chromedriver needs this to talk to google-chrome | |
apt-get -y install dbus --fix-missing | |
apt-get -y install dbus-x11 --fix-missing | |
ln -s /bin/dbus-daemon /usr/bin/dbus-daemon # /etc/init.d/dbus has the wrong location | |
ln -s /bin/dbus-uuidgen /usr/bin/dbus-uuidgen # /etc/init.d/dbus has the wrong location | |
# Download and copy the ChromeDriver to /usr/local/bin | |
cd /tmp | |
echo "Download latest selenium server..." | |
SELENIUM_VERSION=$(curl "https://selenium-release.storage.googleapis.com/" | perl -n -e'/.*<Key>([^>]+selenium-server-standalone[^<]+)/ && print $1') | |
wget "https://selenium-release.storage.googleapis.com/${SELENIUM_VERSION}" -O selenium-server-standalone.jar | |
chown vagrant:vagrant selenium-server-standalone.jar | |
mv selenium-server-standalone.jar /usr/local/bin | |
echo "Download latest chrome driver..." | |
CHROMEDRIVER_VERSION=$(curl "http://chromedriver.storage.googleapis.com/LATEST_RELEASE") | |
wget "http://chromedriver.storage.googleapis.com/${CHROMEDRIVER_VERSION}/chromedriver_linux64.zip" | |
unzip chromedriver_linux64.zip | |
sudo rm chromedriver_linux64.zip | |
chown vagrant:vagrant chromedriver | |
mv chromedriver /usr/local/bin | |
echo "Done downloading and installing basic packages" | |
echo "Writing entries into the host file" | |
for var in "$@" | |
do | |
echo "192.168.33.1 $var" >> /etc/hosts | |
done | |
# 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 | |
# export DBUS_SESSION_BUS_ADDRESS=/dev/null ## Ended up not needing this, but you might if dbus won't install | |
# whitelist IPs - https://stackoverflow.com/a/37616667/823435 | |
nohup java -Dwebdriver.chrome.driver=/usr/local/bin/chromedriver \ | |
-Dwebdriver.chrome.bin="/usr/bin/google-chrome" \ | |
-Dwebdriver.chrome.args="--whitelisted-ips=\"\"" \ | |
-jar ./selenium-server-standalone.jar & |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment