Created
April 10, 2020 17:57
-
-
Save dvwright/9f25242833786eed07677aaab9d33000 to your computer and use it in GitHub Desktop.
Install headless browser environment on AWS linux, google chrome, chromedriver, xvfb
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
#!/usr/bin/env bash | |
## Install packages required by headless browser testing on AWS linux | |
## * Google Chrome Browser | |
## * chromedriver | |
## * Xvfb | |
## * xclip | |
# Google Chrome Browser (google-chrome-stable) | |
# This installs Chrome on any RHEL/CentOS/Amazon Linux variant. | |
# NOTE: takes several minutes... | |
curl https://intoli.com/install-google-chrome.sh | bash | |
# chromedriver | |
# Must correspond to the Chrome Browser version installed | |
# https://chromedriver.chromium.org/downloads | |
# Both chromedriver and Chrome must be in your PATH. | |
echo "Try to downlad and install needed chromedriver version" | |
chromedriver_base_url='https://chromedriver.storage.googleapis.com/' | |
echo $chromedriver_base_url | |
chromedriver_package='chromedriver_linux64.zip' | |
echo $chromedriver_package | |
chrome_version=$(`which google-chrome-stable` --version|grep -Po '[0-9]{2}'|head -n1) | |
echo $chrome_version | |
chromedriver_page=$(echo ${chrome_version} |\ | |
curl -v https://chromedriver.chromium.org/downloads 2>&1 |\ | |
grep -Po "(https://chromedriver.storage.googleapis.com/index.html\?path=[0-9]{2,3}\.[0-9.\/]*)"| | |
head -n1) | |
echo $chromedriver_page | |
chromedriver_version=$(echo $chromedriver_page|sed -e 's/.*path=//g') | |
echo $chromedriver_version | |
chromedriver_link=${chromedriver_base_url}${chromedriver_version}${chromedriver_package} | |
echo "Downloading and installing ${chromedriver_link}" | |
# download and install | |
#sudo wget -qO- $(chromedriver_link) | tar -xvf - -C /usr/local/bin/ | |
cd /tmp/ \ | |
&& wget ${chromedriver_link} \ | |
&& unzip chromedriver_linux64.zip \ | |
&& mv chromedriver /usr/local/bin/ | |
if [ ! -x /usr/local/bin/chromedriver ] | |
then | |
echo "Fallback download and install needed chromedriver version" | |
cd /tmp/ \ | |
&& wget 'https://chromedriver.storage.googleapis.com/81.0.4044.69/chromedriver_linux64.zip' \ | |
&& unzip chromedriver_linux64.zip \ | |
&& mv chromedriver /usr/local/bin/ | |
fi | |
# Xvfb | |
# Chrome must be run in xvfb (native headless mode tests dont pass) | |
yum -y install xorg-x11-server-Xvfb.x86_64 | |
# xclip | |
yum-config-manager --enable epel | |
yum install xclip -y |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment