This procedure is unsupported
Articles in the "Unsupported Community Documents" space are not supported by ITRS support.Version
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
Selenium automates browsers. It is for automating web applications for testing purposes, but is certainly not limited to just that.
Prerequisites
- Basic knowledge about Linux systems.
- Basic knowledge about Selenium. Needed to run automated web browser tests. http://docs.seleniumhq.org/docs/
- Basic knowledge about Xvfb. Needed to run firefox without a graphical environment. http://en.wikipedia.org/wiki/Xvfb
- Centos 6 / Redhat 6
- Firefox 52.8 with selenium IDE plugin (not on op5 Monitor). This is used to record and save selenium tests. http://docs.seleniumhq.org/docs/
- For newer browser versions, use https://addons.mozilla.org/en-US/firefox/addon/katalon-automation-record/
- Record & Save your test and export it to python format.
- Installed op5 license.
- Internet access.
- SSH and root access to the op5 Monitor system.
- Ongoing monitoring of the op5 Monitor system's CPU and memory resources. Unlike ordinary service checks, Selenium tests will use a lot of memory and CPU resources.
Install and configure necessary packages on op5 Monitor
Download and install java openjdk-1.8.0.
Used to run the selenium-server jar file.
yum install -y java-1.8.0
Download the Selenium-Server jar file.
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.
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.
yum install yum-plugin-versionlockyum versionlock firefox-*
Download the init scripts for selenium and Xvfb.
Create two new files in the /etc/init.d/ directory called xvfb and selenium containing the script data found below.
#!/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
#!/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
mkdir /var/log/selenium
Download the Python based selenium plugin.
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
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.
Used by the check_selenium.py plugin.
yum install python-pippip install selenium==2.53.1
Add xvfb and selenium start at boot.
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.
/etc/init.d/xvfb start/etc/init.d/selenium start
How to create test cases used by op5 Monitor
Option 1.
Download and install the selenium IDE plugin for firefox from http://release.seleniumhq.org/selenium-ide/2.5.0/selenium-ide-2.5.0.xpi
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.
Add the command on op5 Monitor
- Configure -> Commands
- command_name = check_selenium
-
command_line = $USER1$/custom/check_selenium.py -s $ARG1$ -w $ARG2$ -c $ARG3$
- Submit and then save the configuration.
Add the service on op5 Monitor
- Configure -> Edit host monitor -> Go -> Services for host monitor
- service description = check_selenium_op5 (a description related to what sort of test is performed)
- check_command = check_selenium
- check_command_args = script_name!sec-warn!sec-crit
- Submit and then save the configuration.
What it looks like in op5 Monitor
Troubleshooting and help
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 servers has a proxy but your tests are to a system that needs to bypass the proxy, try prepending you 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.
Comments
0 comments
Please sign in to leave a comment.