Automating browser activities using Selenium

While carrying out the OAM installation as mentioned in my preovious post, the challenge was to automate the installation in a single script. I have been automating installations of various components since long using the silent install response files. But this automation was different. This setup involves carring out various activites from the browser. Also it involves setup and configuration from browser at different stages in the installation.

This was a real challenge for me. I stated doing the automation for component level installation. Component level silent installation was very simple. We get a response file when we install OAM. The response files are present under $isntall_dir/oblix/config. The name of response file is install_options.txt. You will see this response file under every component installation directory.

Automation of browser task for OAM installation involves following steps

1) Creating perl script for browser activities.
You have to install OAM manually and record the browser activities in Selenium tool. From this you have to create perl scripts
2) Modifying the perl script for OAM browser task.
You have to modify the script and place the bounce script for OIS and Apache at appropriate location where the browser waits for the services to be bounced.
3) Installing selenium perl module and Selenium server on the Linux server where you want to run this perl scriptsFor browser automation, I used Selenium tool. I will show here the demo of what Selenium can do.

Selenium IDE:

Selenium is a tool for automating the browser activity. This client version of this tool is available in windows in the form of FireFox addon.
Download Selenium IDE and install in your firefox browser
Once downloaded following below steps to understand how Selenium works.

1) Open firefox browser and open
2) Tools -> Selenium IDE

3) Search for “Selenium IDE” or anything else in the google window and navigate to some pages. I used following test case
Search for “Selenium IDE”, click on first link, click on downloads tab on that page, click on documentation tab etc..
4) Once done turn off the record button on your selenium screen.

What ever steps that you have followed in the browser got recorded by selenium. Now you can click on play icon on Selenium tool and it will navigate exactly as you have done before.
Selenium also takes care of entering the information on a browser if you have entered before. Example login ID and password can also be recoreded and entered by Selenium when we play the record.

Creating perl script from Selenium:

The great utility of Selenium is that it allows creating a perl script automatically for the sequence that we have recoreded. This can be used very well for automating the browser activities of OAM.
We can record the sequence and create a perl script. We can run this perl script in Linux server where we are doing the OAM installation.

For creating perl script of the sequence, you can do Options -> Format -> Perl – Selenium RC.
Note that you can get the perl script after recording the sequence. The perl script for my recorded sequence looks as below

use strict;
use warnings;
use Time::HiRes qw(sleep);
use Test::WWW::Selenium;
use Test::More "no_plan";
use Test::Exception;

my $sel = Test::WWW::Selenium->new( host => "localhost", 
 port => 4444, 
 browser => "*chrome", 
 browser_url => "http://change-this-to-the-site-you-are-testing/" );

$sel->type_ok("q", "selenium IDE");

So like wise for each browser related step in OAM configuration, I created a perl script. You will end up creating 4 Perl script

Referring to OAM install post

Script 1 – Step 3) Setting up Identity System
Script 2 – Step 5) Setup Policy Manager
Script 3 – Step 6) Installing Oracle Access Manager
Script 4 – Step 7) Installing WebGate (browser part)

You also need to edit the perl script at appropriate place in order to bounce the services for OIS and Apache. I introduced following commands in respective perl scripts in order to take care of that.

system(‘$HOME/oam/Apache2063/bin/apachectl stop’);
system(‘$HOME/oam/Apache2063/bin/apachectl start’);

The next task that remains is, installing selenium perl module on linix server where you want to run this perl script for configuring OAM.

Installing Selenium perl module and Selenium server on Linux:

For installing Selenium perl module and Selenium server on Linux, you need to download Selenium Remote Control
This is a Selenium server setup. Once downloaded, ftp to linux server and unzip. You will see following directories

-bash-3.1$ cd selenium-remote-control-1.0-beta-2
-bash-3.1$ ls

selenium-perl-client-driver-1.0-beta-2 is the perl module which you want to install.
In order to install perl module locally you can use PREFIX=<path> argument while running Makefile.PL as shown below. Here <path> represent path to some local directory where you want install perl module.

perl Makefile.PL PREFIX=/slot/ems3170/oracle/oam/perl/install

When you try to install this perl module you will find that some other perl modules are missing. It depends on the perl installation that you have on your linux server. If some dependent perl modules are missing, make sure to download and install the same from
Once the perl module is installed, source the variable PERL5LIB to include all the libraries created by different perl modules.
Example in my case PERL5LIB was as shown below
export PERL5LIB=$HOME/oam/perl/install/lib/5.6.1:$HOME/oam/perl/install/lib/5.8.1:$HOME/oam/perl/install/lib/site_perl/5.6.1:$HOME/oam/perl/install/lib/site_perl/5.8.0:$HOME/oam/perl/install/local/perl5.8/lib/site_perl/5.8.0

Once the perl module is install, you can start the selenium server. You need JDK 1.6 to start selenium server so verify your jdk version.

-bash-3.1$ java -version
java version “1.6.0_07”
Java(TM) SE Runtime Environment (build 1.6.0_07-b06)
Java HotSpot(TM) Server VM (build 10.0-b23, mixed mode)

If your java is at 1.4 level, install 1.6 and then use 1.6 version

Following is command to start selenium server

go to the location where you have unzipped Selenium remote control and go inside selenium-server

-bash-3.1$ cd selenium-server-1.0-beta-2/
-bash-3.1$ pwd
-bash-3.1$ ls
javadoc                       selenium-server-sources.jar       sslSupport
selenium-server-coreless.jar  selenium-server-tests.jar
-bash-3.1$ java -jar selenium-server.jar &

The & at the end is important, you need to start the server in the backend, else you wont be able to use that session. Once selenium server is started, perl module installed and PERL5LIB is sourced correctly then try running the perl script that you created using Selenium IDE before. You will see that from Linux session a browser will get launched automatically and all the activities in browser will be done automatically.
Finally you can wrap all the installation and configuration steps in a shell script in correct sequence and have OAM installation automated.

Hope this helps !!


Click to access Selenium%20Report.pdf