Back to OP5 Monitor FAQ

How to add Selenium tests to op5 Monitor

This procedure is unsupported Copied

Articles in the “Unsupported Community Documents” space are not supported by ITRS support.

Version Copied

This article was written for version 6.2 of op5 Monitor, it could work on both lower and higher version if nothing else is stated. The op5 Monitor 6.2 appliance was downloaded from www.op5.com. This article also assumes that you have installed the op5 license so that you have access to the op5 repos.

Purpose Copied

Selenium automates browsers. It is for automating web applications for testing purposes, but is certainly not limited to just that.

Prerequisites Copied

Install and configure necessary packages on op5 Monitor Copied

Download and install java openjdk-1.8.0 Copied

Used to run the selenium-server jar file.

yum install -y java-1.8.0

Download the Selenium-Server jar file Copied

This jar file is the selenium-server itself.

mkdir -p /opt/plugins/custom/selenium/testscurl https://selenium-release.storage.googleapis.com/2.53/selenium-server-standalone-2.53.1.jar -o /opt/plugins/custom/selenium/selenium-server-standalone.jar

Download and install Xvfb Copied

You do not need a graphical to run selenium test when using Xvfb.

yum install -y xorg-x11-server-Xvfb

Download and install Firefox.

Used together with Xvfb and selenium to start Firefox with a virtual display.

yum install -y firefox-52.8.0-1.el6.centos.x86_64

Lock the version of Firefox Copied

yum install yum-plugin-versionlockyum versionlock firefox-*

Download the init scripts for selenium and Xvfb Copied

Create two new files in the /etc/init.d/ directory called xvfband selenium containing the script data found below.

xvfb

#!/bin/bash
## Thanks to Dan Straw
## http://www.danstraw.com/ #
## listOfProcesses   Start Xvfb
## chkconfig: 2345 95 05
## description: Starts Xvfb, needed by Selenium
## processname: Xvfb
### BEGIN INIT INFO
## Provides: Xvfb
## Required-Start:
## Required-Stop:
## Default-Start: 2 3 4 5
## Default-Stop: 0 1 6
## Short-Description: Xvfb
## Description:      Xvfb
### END INIT INFO
XVFB=/usr/bin/Xvfb
XVFBARGS=":99 -nolisten tcp -fbdir /var/run"
PIDFILE=/var/run/xvfb.pid
case "$1" in
    start)
        echo -n "Starting virtual X frame buffer: Xvfb"
        nohup $XVFB $XVFBARGS &
    ;;
    stop)
        echo -n "Stopping virtual X frame buffer: Xvfb"
        pkill -9 Xvfb
        echo "."
    ;;
    restart)
        $0 stop
        $0 start
    ;;
    *)
        echo "Usage: /etc/init.d/xvfb {start|stop|restart}"
        exit 1
esac
exit 0

selenium

#!/bin/bash
### BEGIN INIT INFO
## Provides: selenium
## Required-Start: $local_fs $network $syslog selenium
## Required-Stop: $local_fs $syslog
## Default-Start: 2 3 4 5
## Default-Stop: 0 1 6
## Short-Description: Selenium
## Description:       Selenium
### END INIT INFO
export CLASSPATH=/opt/plugins/custom/selenium
case "${1:-''}" in
'start')
        nohup env DISPLAY=:99 /usr/bin/java -jar /opt/plugins/custom/selenium/selenium-server-standalone.jar > /var/log/selenium/selenium-output.log 2> /var/log/selenium/selenium-error.log &
        echo "Starting Selenium..."
#####env DISPLAY=:0.0 firefox &
env DISPLAY=:99 firefox &
        error=$?
        if test $error -gt 0
        then
            echo "${bon}Error $error! Couldn't start Selenium!${boff}"
        fi
    ;;
    'stop')
        echo "Stopping Selenium..."
pkill -9 java
pkill -9 firefox
    ;;
    *)      # no parameter specified
        echo "Usage: $SELF start|stop|restart|reload|force-reload|status"
        exit 1
    ;;
esac

Make sure that the files are executable.

chmod 755 /etc/init.d/seleniumchmod 755 /etc/init.d/xvfb

Create log directory for Selenium Copied

mkdir /var/log/selenium

Download the Python based selenium plugin Copied

This plugin is run by op5 Monitor.

wget -O check_selenium.tar.gz https://exchange.icinga.org/exchange/check_selenium.py/files/526/check_selenium.tar-gztar -xzvf check_selenium.tar.gzmv check_selenium.py /opt/plugins/custom

Change test case directory Copied

The path to the directory storing the selenium test case files is set in the check_selenium.py check plugin script.

Edit the file /opt/plugins/custom/check_selenium.py using a text editor.

Locate the test_dir variable definition and update it like this:

test_dir="/opt/plugins/custom/selenium/tests"

Download and install the python selenium module Copied

Used by the check_selenium.py plugin.

yum install python-pippip install selenium==2.53.1

Add xvfb and selenium start at boot Copied

If for whatever reason you decide to reboot op5 Monitor.

chkconfig --add /etc/init.d/xvfbchkconfig --level 2345 xvfb onchkconfig --add /etc/init.d/seleniumchkconfig --level 2345 selenium on

Start xvfb and then selenium Copied

/etc/init.d/xvfb start/etc/init.d/selenium start

How to create test cases used by op5 Monitor Copied

Option 1.

Download and install the selenium IDE plugin for firefox from https://addons.mozilla.org/en-US/firefox/addon/selenium-ide/

You can do this on any machine running firefox in a graphical environment and then move the recordings to the op5 Monitor.

When you have recorded what you want to test go to File -> Export Test Case As -> Python 2 / unittest / Remote Control and save the file.

Copy the file to op5 Monitor and to your test_dir directory, default located at /opt/plugins/custom/selenium/tests/.

Option 2.

Install Katalon Automation recorder plugin for firefox.

You can do this on any machine running firefox in a graphical environment and then move the recordings to the op5 Monitor.

Create the recording and export it as Python 2 (Webdriver + unittest).

Copy the file to op5 Monitor and to your test_dir directory, default located at /opt/plugins/custom/selenium/tests/.

Configuring op5 Monitor to use the plugin and test case Copied

Add the command on op5 Monitor Copied

OP5 Monitor - How to add Selenium tests to op5 Monitor

Add the service on op5 Monitor Copied

OP5 Monitor - How to add Selenium tests to op5 Monitor

What it looks like in op5 Monitor Copied

OP5 Monitor - How to add Selenium tests to op5 Monitor

Troubleshooting and help Copied

If you have trouble getting the headless browser (i.e. Firefox) to work, try typing (in shell) export DISPLAY=:99 and manually re-run the test. If that works, add the following line (after imports) to your check_selenium.py

os.environ["DISPLAY"] = ":99"

If your monitor server has a proxy but your tests are to a system that needs to bypass the proxy, try prepending your manual check command in shell with http_proxy="", if that works, add the following line (after imports) to your check_selenium.py

os.environ["http_proxy"] = ""

For later versions of firefox you have to install ‘geckodriver’. Download the latest version from https://github.com/mozilla/geckodriver/releases, extract the geckodriver file, make it executable and move it to /usr/bin.

If you get this error message:

Failed to open connection to "session" message bus: /usr/bin/dbus-launch terminated abnormally without any error message

you need to install dbus (messaging bus system for linux) on your server. For centos - simply execute:

yum install dbus-x11

In some rare cases - you will need to manually start dbus-launch (https://dbus.freedesktop.org/doc/dbus-launch.1.html):

dbus-launch --autolaunch 609bbd29e32a4898e604f49bff82a88c --binary-syntax --close-stderr &

This will create a folder called /opt/monitor/.dbus.

["Geneos"] ["FAQ"]

Was this topic helpful?