Skip to main content

Posts

“Try-Catch-Finally” vs Throws

Its really confusing sometimes when different people ask me to use “try-catch” or throws in my code while they religiously do the code reviews… Some ask me to stick to try-catch and others suggest just throwing all exceptions         After getting frustrated for a couple of times, I finally decided to read through various resources and find out for myself what’s best! Below is the gist of my findings:   What’s a Try-Catch Block? Oh yes the answer lies in its definition. A try-catch block helps us handle an exception. So basically its our own Exception Handling Construct…So use it when you would want your program to handle its exceptions by itself.   Thus we should fall back to using Throws when your program/function isn’t handling the exceptions it raises. You simply pass on the exceptions to its higher layer Pass the ball!!!   Hope this helps!

Simulating Keyboard strokes using Selenium1

Many a times we want to simulate keyboard strokes in our selenium tests. Here is how you can do this using Selenium1.   Command: selenium.keyPressNative(<KeyEvent_TobePassed>);   For Ex: If you want to simulate pressing Tab then you need to pass the command: selenium.keyPressNative(java.awt.event.KeyEvent.VK_TAB+"");   View the list of KeyEvents here: http://docs.oracle.com/javase/1.4.2/docs/api/java/awt/event/KeyEvent.html   Hope this helps!

How to install a Notepad++ Plugin?

Steps to Install: Download the plugin from the Notepad++ Site: http://sourceforge.net/projects/npp-plugins/ Unzip the plugin into the plugin folder under the Notepad++ source folder usually its something like this: C:\Program Files (x86)\Notepad++\plugins Restart the application Notepad++ You will now see the plugins under “Plugins –> Compare” Enjoy Comparing

Convert String Array to Collection

How to convert a String Array to a Collection? Before we get to know how to convert a String Array into a Collection. We might want to know more details about the two… What’s the difference between a String Array and a Collection? Collection: It’s a group of data manipulated as a single object. Technically, its an interface in java which is implemented by various other classes. Many of which you uses regularly. One of its implementations can be seen in an array. An array best defined by the Sun is “An array is a container object that holds a fixed number of values of a single type.” So by implementing Collection interface, an Array skips the code required for its implementation – that is now taken care by the Collection interface! Why would I want to  convert a String Array into a Collection A Collection contains “Objects” if you understand the language…An Object is more generic implementation of the data types. So in a Collection, you can have any type of Object…So while w...

Shell Script to Check if Selenium Server is Running!

Many a times we would want to write up a script to start the selenium server using a shell script… So here is the script     #!/bin/sh # # @Author – Sirisha # @Date   - May 29 2012 # Script to start the Selenium Server on a given host #   # Defined the hostname hostname=somehostname # Defined the path to the selenium server serverPath=~/seleniumServer/ # Define the Selenium Server version jar server=selenium-server-standalone-2.12.0.jar # Define the Search String for the server SERVICE_STRING="'java -jar $server'"   # Clear the terminal clear   echo "service string is: $SERVICE_STRING" echo "Starting Selenium Server on $hostname"   # Run the command to get the process list ps -ef | grep -v grep | grep selenium   # Check if the Selenium Server is already running if [ $? -eq 0 ] then     echo "$server is running, everything is fine" else     echo "$server is not running"  ...