Skip to content

Instantly share code, notes, and snippets.

@justudin
Last active June 3, 2021 09:04
Show Gist options
  • Save justudin/6a1154628e999e9b4f5e517613f03313 to your computer and use it in GitHub Desktop.
Save justudin/6a1154628e999e9b4f5e517613f03313 to your computer and use it in GitHub Desktop.
install-selenium-nodejs-linux.sh
#!/bin/bash
echo "Step 1: Download and install google-chrome-stable"
sudo curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add
sudo echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list
sudo apt-get -y update
sudo apt-get -y install google-chrome-stable
gchrome_installed=$(google-chrome --version 2>&1)
gchrome_version="$(cut -d' ' -f3 <<<"$gchrome_installed")"
echo -e "${gchrome_installed}already successfully installed."
gchrome_version_download="$(cut -d'.' -f1 <<<"$gchrome_version")"
echo "Step 2: Download and install chromedriver verison $gchrome_version_download"
linux64="chromedriver_linux64.zip"
download_version=$(curl -Ssk https://chromedriver.storage.googleapis.com | grep -oP '(?<=<Key>).*?(?=</Key>)' | grep "$gchrome_version_download.*/$linux64")
download_link="https://chromedriver.storage.googleapis.com/${download_version}"
wget $download_link
unzip chromedriver_linux64.zip
sudo mv chromedriver /usr/bin/chromedriver
sudo chown root:root /usr/bin/chromedriver
sudo chmod +x /usr/bin/chromedriver
# if you want to install display server
echo "Step 3: Install Xvfb is an in-memory display server for UNIX-like operating system"
sudo apt-get install xvfb
# install nodejs v14 for ubuntu
dist=`grep DISTRIB_ID /etc/*-release | awk -F '=' '{print $2}'`
if [ "$dist" == "Ubuntu" ]; then
echo "Install nodejs v14 for ubuntu"
curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs
elif [ "$dist" == "Debian" ]; then
# Using Debian
curl -fsSL https://deb.nodesource.com/setup_14.x | sudo bash -
sudo apt-get install -y nodejs
else
echo "Not supported"
fi
# Install selenium for NodeJS client
npm install selenium-webdriver
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment