This script automates the setup of a Selenium testing environment on a Linux machine by installing required dependencies, configuring the system, and setting up the Selenium server and ChromeDriver.
npm run import -- "selenium vnc server"
echo "deb http://archive.ubuntu.com/ubuntu xenial main restricted universe multiverse \n" > /etc/apt/sources.list \
&& echo "deb http://archive.ubuntu.com/ubuntu xenial-updates main restricted universe multiverse \n" >> /etc/apt/sources.list \
&& echo "deb http://security.ubuntu.com/ubuntu xenial-security main restricted universe multiverse \n" >> /etc/apt/sources.list \
&& apt-get -qqy update \
&& apt-get -qqy --no-install-recommends install \
bzip2 \
ca-certificates \
openjdk-8-jre-headless \
tzdata \
sudo \
unzip \
wget \
x11vnc \
locales \
xvfb \
&& echo "UTC" > /etc/timezone \
&& dpkg-reconfigure --frontend noninteractive tzdata \
&& useradd seluser \
--shell /bin/bash \
--create-home \
&& usermod -a -G sudo seluser \
&& echo 'ALL ALL = (ALL) NOPASSWD: ALL' >> /etc/sudoers \
&& echo 'seluser:secret' | chpasswd \
&& sudo mkdir -p /opt/selenium \
&& sudo chown seluser:seluser /opt/selenium \
&& wget --no-verbose https://selenium-release.storage.googleapis.com/3.8/selenium-server-standalone-3.8.1.jar \
-O /opt/selenium/selenium-server-standalone.jar \
&& wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list \
&& apt-get update -qqy \
&& apt-get -qqy install \
google-chrome-stable \
&& CD_VERSION=$(wget -qO- https://chromedriver.storage.googleapis.com/LATEST_RELEASE) \
&& echo "Using chromedriver version: "$CD_VERSION \
&& wget --no-verbose -O /tmp/chromedriver_linux64.zip https://chromedriver.storage.googleapis.com/$CD_VERSION/chromedriver_linux64.zip \
&& rm -rf /opt/selenium/chromedriver \
&& unzip /tmp/chromedriver_linux64.zip -d /opt/selenium \
&& rm /tmp/chromedriver_linux64.zip \
&& mv /opt/selenium/chromedriver /opt/selenium/chromedriver-$CD_VERSION \
&& chmod 755 /opt/selenium/chromedriver-$CD_VERSION \
&& ln -fs /opt/selenium/chromedriver-$CD_VERSION /usr/bin/chromedriver \
&& locale-gen en_US.UTF-8 \
&& dpkg-reconfigure --frontend noninteractive locales \
&& apt-get update -qqy \
&& apt-get -qqy --no-install-recommends install \
language-pack-en \
fonts-ipafont-gothic \
xfonts-100dpi \
xfonts-75dpi \
xfonts-cyrillic \
xfonts-scalable \
fluxbox
bash
#!/bin/bash
# Define environment variables
DEBIAN_DISTRO=xenial
SECURITY_SOURCE=security.ubuntu.com
UPDATES_SOURCE=xenial-updates
RECOMMENDATIONS=false
# Function to update package list
update_packages() {
apt-get update -qqy
}
# Function to install packages
install_packages() {
apt-get install -qqy --no-install-recommends "$@"
}
# Function to make directory
make_directory() {
sudo mkdir -p "$1"
}
# Function to change ownership
change_ownership() {
sudo chown "$1" "$2"
}
# Function to download file
download_file() {
wget --no-verbose -O "$1" "$2"
}
# Function to add key to apt
add_key() {
apt-key add - <<< "$1"
}
# Function to generate locales
generate_locales() {
locale-gen "$1"
}
# Update package list
update_packages
# Install base packages
install_packages \
bzip2 \
ca-certificates \
openjdk-8-jre-headless \
tzdata \
sudo \
unzip \
wget \
x11vnc \
locales \
xvfb
# Configure timezone
echo "UTC" > /etc/timezone
dpkg-reconfigure --frontend noninteractive tzdata
# Create user
useradd seluser --shell /bin/bash --create-home
# Add user to sudo group
usermod -a -G sudo seluser
# Add sudo rules
echo 'ALL ALL = (ALL) NOPASSWD: ALL' >> /etc/sudoers
# Set user password
echo'seluser:secret' | chpasswd
# Create selenium directory
make_directory /opt/selenium
change_ownership seluser:seluser /opt/selenium
# Download selenium server
download_file /opt/selenium/selenium-server-standalone.jar \
https://selenium-release.storage.googleapis.com/3.8/selenium-server-standalone-3.8.1.jar
# Add Google Chrome repository
download_file - https://dl-ssl.google.com/linux/linux_signing_key.pub
add_key
echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list
update_packages
install_packages google-chrome-stable
# Download chromedriver
CD_VERSION=$(download_file - https://chromedriver.storage.googleapis.com/LATEST_RELEASE)
echo "Using chromedriver version: $CD_VERSION"
download_file /tmp/chromedriver_linux64.zip \
https://chromedriver.storage.googleapis.com/$CD_VERSION/chromedriver_linux64.zip
rm /opt/selenium/chromedriver
unzip /tmp/chromedriver_linux64.zip -d /opt/selenium
rm /tmp/chromedriver_linux64.zip
mv /opt/selenium/chromedriver /opt/selenium/chromedriver-$CD_VERSION
chmod 755 /opt/selenium/chromedriver-$CD_VERSION
ln -fs /opt/selenium/chromedriver-$CD_VERSION /usr/bin/chromedriver
# Generate locales
generate_locales en_US.UTF-8
dpkg-reconfigure --frontend noninteractive locales
# Install additional packages
install_packages \
language-pack-en \
fonts-ipafont-gothic \
xfonts-100dpi \
xfonts-75dpi \
xfonts-cyrillic \
xfonts-scalable \
fluxbox
This code snippet automates the setup of a Selenium testing environment on a Linux machine.
Here's a breakdown:
System Configuration:
xenial
(Ubuntu 16.04 LTS).bzip2
, ca-certificates
, openjdk-8-jre-headless
, tzdata
, sudo
, unzip
, wget
, x11vnc
, locales
, xvfb
seluser
with specific permissions (sudo access).Selenium Environment Setup:
/opt/selenium
for Selenium-related files.Purpose:
This script automates the process of setting up a complete Selenium testing environment on a Linux machine, including necessary dependencies, a user account for running tests, and the Selenium server and ChromeDriver.