Annotation
For a long time, I was looking for some tool that can automate some of my actions regarding a web browser. Like opening a browser, going to some address, login, do some actions, logout, exit. This way I could automate some activities which most of the time are done via the web browser and do not require much of a thinking to do them, but require a lot of attention of the data you enter.Current problem
My current project has two modes: running on my local machine, or running on a dedicated server - and for accessing both deployments I go to a single portal. When I am developing I want to be able to check the application against my local server, but when I am doing final tests I want to check it from the dedicated server. We are a team of around 10 people using the same dedicated server so those two modes of the application are changing quite often. Switching between them require a set of steps:- Opening a browser and going to the WebLogic configuration page
- Login
- Searching for my application, then some more searching for the module
- Going to the administration tab of the module and changing a set of 4 fields
- Values of those fields are not so simple so often I have to check in some other place their values just to be on the safe side.
Research
After some searching, I didn’t find a simple tool designed exactly for this purpose. There were some nice tools like AutoHotKey, which is intended to make various kind of automated scripts for Windows in general and has a support of Browser automation but at first it seemed to me like a lot of research to do it. I went then for Selenium. I know it is used for making automated UI tests, so why not use it here. It has a nice plugin for Firefox for generating the script. But if I want to run the script, I will have to open Firefox, open the plugin, navigate to the correct script and play it. So I started wondering if this could be made one click runnable.Solution
Let's start with creating a selenium script which will be run in Firefox. For setup the selenium IDE please refer to its official documentation here. Selenium IDE provides the recording option so, in general, you don’t have to write the script yourself, but it will record your actions over the browser and then generate the script for you. But as one can expect there are always exceptions you have to deal manually. So here is how a playback of the script looks like:
java -jar selenium-server-standalone-2.42.2.jar -htmlSuite "*firefox" "https://localhost" "myTestSuite.html" "results.html"
Even though we reached our aim we can go even further and make the test case parametrized. In my use case, I have to change the Hostname, Port and URI for the local machine and dedicated server deployment. I can make two different test cases, but since the only difference is the values entered in these 3 fields it is better to have one parametrized. In selenium, we can accomplish this by using user extension JavaScript.This will start the selenium server on localhost, bring up the firefox browser along with another window showing the status of the execution and perform the script. Then on the result.html we will have info about the outcome. Now we can put this line inside a .bat file (for Windows) and here is your double-click shortcut for performing the automation script. First we will create a file called user-extensions.js with content:
var _url=”localhost”; var _port =”7101”; var _URI = “/MyTestUri”;
Then to access these variables in the script itself we have to modify it like:

java -jar selenium-server-standalone-2.42.2.jar -htmlSuite "*firefox" "https://localhost" "myTestSuite.html" "results.html" -userExtensions user-extensions.js





