This Bash script sets up a headless environment with a virtual display, starts Selenium, a window manager, and a VNC server for remote Selenium testing.
npm run import -- "vnc entry point"
#!/bin/bash
#
# IMPORTANT: Change this file only in directory StandaloneDebug!
function shutdown {
kill -s SIGTERM $NODE_PID
wait $NODE_PID
}
if [ ! -z "$SE_OPTS" ]; then
echo "appending selenium options: ${SE_OPTS}"
fi
rm -f /tmp/.X*lock
export DISPLAY=:99
xvfb-run --server-args="-screen 0 8160x6120x24 -ac +extension RANDR" \
java -Dwebdriver.chrome.chromedriver=/opt/selenium/chromedriver-* -jar /opt/selenium/selenium-server-standalone.jar &
NODE_PID=$!
trap shutdown SIGTERM SIGINT
for i in $(seq 1 10)
do
xdpyinfo -display $DISPLAY >/dev/null 2>&1
if [ $? -eq 0 ]; then
break
fi
echo Waiting xvfb...
sleep 0.5
done
fluxbox -display $DISPLAY &
x11vnc -scale 2700x2048 -noxdamage -forever -nopw -shared -rfbport 5900 -display $DISPLAY &
wait $NODE_PID
bash
#!/bin/bash
#
# IMPORTANT: Change this file only in directory StandaloneDebug!
# Function to shutdown the process
shutdown() {
# Send SIGTERM signal to the process
kill -s SIGTERM $NODE_PID
# Wait for the process to exit
wait $NODE_PID
}
# Check if selenium options are provided
if [ -n "$SE_OPTS" ]; then
# Log the selenium options
echo "Appending selenium options: ${SE_OPTS}"
fi
# Clean up X11 locks
rm -f /tmp/.X*lock
# Set the display environment variable
export DISPLAY=:99
# Run xvfb with custom screen arguments
xvfb-run --server-args="-screen 0 8160x6120x24 -ac +extension RANDR" \
java -Dwebdriver.chrome.chromedriver=/opt/selenium/chromedriver-* -jar /opt/selenium/selenium-server-standalone.jar &
NODE_PID=$!
# Trap SIGTERM and SIGINT signals to call the shutdown function
trap shutdown SIGTERM SIGINT
# Wait for xvfb to start
for i in $(seq 1 10); do
# Check if xvfb is running using xdpyinfo
xdpyinfo -display $DISPLAY >/dev/null 2>&1
if [ $? -eq 0 ]; then
# If xvfb is running, break out of the loop
break
fi
# Log a message to indicate that xvfb is still starting
echo "Waiting for xvfb..."
# Wait for 0.5 seconds before checking again
sleep 0.5
done
# Run fluxbox on the display
fluxbox -display $DISPLAY &
# Run x11vnc on the display with custom settings
x11vnc -scale 2700x2048 -noxdamage -forever -nopw -shared -rfbport 5900 -display $DISPLAY &
# Wait for the xvfb process to exit
wait $NODE_PID
This Bash script sets up a remote desktop environment with a VNC server for Selenium testing. Here's a breakdown:
Initialization:
shutdown
function: Defines a function to gracefully shut down the Node.js process running Selenium.SE_OPTS
: Checks for any Selenium options passed as arguments and prints them.rm -f /tmp/.X*lock
: Removes any existing X server lock files.Environment Setup:
export DISPLAY=:99
: Sets the DISPLAY environment variable to :99
, which is used by Xvfb.xvfb-run
: Starts an Xvfb server with specific resolution (8160x6120x24) and arguments.java ...
: Launches the Selenium server in the background, specifying the ChromeDriver path.NODE_PID=$!
: Stores the process ID of the Selenium server.Waiting for Xvfb:
trap shutdown SIGTERM SIGINT
: Sets up signal handlers to call the shutdown
function when receiving SIGTERM or SIGINT signals.xdpyinfo
.Starting Applications:
fluxbox -display $DISPLAY &
: Starts the Fluxbox window manager on the virtual display.x11vnc ...
: Starts the x11vnc server to enable remote access via VNC, with specified options.Cleanup:
wait $NODE_PID
: Waits for the Selenium server to finish.In essence, this script creates a headless environment with a virtual display, starts Selenium, a window manager, and a VNC server, allowing remote control and Selenium testing.