Skip to main content

Posts

Showing posts from 2012

Hudson Configuration

Ever wondered where can you find the information on how your Hudson was setup? Well you can see all the properties and their values by visiting this link: https://<SystemName_IP_WhereHudson_IsSetup:5443/systemInfo On this page you will see all the System Properties and Environment Variables If you want to configure the setup of Hudson then you should go to https://<SystemName_IP_WhereHudson_IsSetup:5443/configure Enjoy! Happy Testing

Could not start Selenium session: You may not start more than one session at a time

Error is: java.lang.RuntimeException: Could not start Selenium session: You may not start more than one session at a time at com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:107)   If you get this error on Selenium then this might be the problem… If in your test you are using a webdriver to create the DefaultSelenium or Selenium object then remove this line from your code:         selenium.start(); Happy Testing

“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 writi

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"     # Go to the selenium s

How does Shell find out which command/script I am trying to execute?

This is nothing new but yet I thought why not document it so that its etched into my memory (Ya I know I am selfish ) When you run a command or try executing a shell script, the shell first tries to look if your script is found in the Current Directory. To execute a shell script you should be in the same directory where it was created/written. Now this isn’t possible always – so what to do? There are two ways:   Method 1 - When you are executing the script, give the full path to the script! Now if you go by the usual file/folder structure in most of the software engineers – you can go crazy with the paths – the depth at which the script is found can drive you insane   So thankfully we have another way   Method 2 - Add the folder of your script to the PATH variable. What I suggest is create a folder for all your scripts – say myScripts and then add this to your PATH variable. If you are new to using the PATH variable, I suggest you go through this link on PATH variables  

TestNG DataProvider–Phew!!!

It took me some time to get a hang of what the TestNG DataProvider could do…Once I got to know about how it functions believe me I created wonders with it   What is a TestNG DataProvider? There are loads of definitions on the web for it but if you are an average-but-wanting-to-learn software engineer then in simple words, a TestNG DataProvider is a Test Data Provider class…Simple! It is powerful enough to provide data according to the method which is initiating or rather calling it…   When/Why do I need a TestNG DataProvider? Of course, most of us would agree that we provide the test data through various forms like an xml, excel, csv etc…The reason I found this feature useful when I knew the input before hand and it varied based on the test case…For example, if I am testing buying of a product on a retail website…I want to test buying of a new product, buying of a used product, buying of multiple products…I have the test data in all the three cases but then the test data differs

Useful Linux Commands - IV

who : gets all the connections made to your account netstat –antp : to know all the process running on ports sudo /etc/init.d/network restart : restart networking on your linux box Understanding the init.d Directory – This directory has the control scripts for most of the services on our linux box. The start/stop/restart/reload/force-reload options can be used with any command found under this directory Most common Services controllable from this directory are: apache2, sshd, networking, ftpd, samba, mysql You can run any command using the following format: sudo /etc/init.d/<command> <option> where command can be apache2, sshd, networking etc and option can be start, stop, restart etc For ex: sudo /etc/init.d/networking restart Simple! Refresh DNS Cache Ping your linux box using “ ping <your_computer_name> ” – Note down the IP Address shown Look at the contents of ifconfig file using “ sudo /sbin/ifconfig ” – Read the part labeled as inet addr: The t

Get the Parent Directory!

We all work with files and file paths…I got this recently when I was trying to get the current directory of the user while he is navigating through the application. Issue: At any time, I should get the parent directory of the current user directory and perform the designated actions. Solution: We have system properties which will give us the current user directory… Access the system property using String userDir = System.getProperty(“user.dir”); Now you can user the File Java Class to access the parent directory as String parentDir = new File(userDir).getParent(); For Example: User is in /home/someuser/SeleniumTests/Test1 userDir will have the value /home/someuser/SeleniumTests/Test1 parentDir will have the value /home/someuser/SeleniumTests   Hope this helps! Happy Coding!

Setting up Apache

Though there are hundred’s of links available for Apache Server setup…Yet I felt there is a need to scribble what I did: Download the tar.gz file from this link Unpack or uncompress the file using the command: tar –zxvf <file-name> <destination folder name> Go to the apache/conf/server.xml - change the server name to the machine name where you unpacked the apache folder Go to the <host> tag in the file Change the “name” attribute To access the ManagerPanel/Administration - Go to the apache/conf/tomcat-users.xml - add a user If you want to add a user with name “apacheuser” and password “apache” add the following to the file <user username="apacheuser" password="apache" roles="manager-gui"/> This will give the user “apacheuser” access to the manager GUI. You can access this panel Start the server Open command prompt (On windows) or Terminal (On Linux) Go to the following folder: On Windows - C:\Program Files\Apache S

Standard way to find a Character TYPE!

While we are processing Characters, it’s a very common practice that we use ASCII values… I still remember in my computer class if I had to find out a character is a capital letter or not I would compare it with its ASCII value   I have also seen these comparisons if (ch >= ‘a’ && ch <= ‘z’ || ch >= ‘A’ && ch <= ‘Z’) – This means our character is an ALPHABET if (ch == ‘ ’) – This means our character is a whitespace     Now this comparison is language specific…I mean it works for English and some other international languages but fails for others… If you are interested in having an internationally accepted Character Test Code ready then read on     Char cTest; If (Character.isLetter(cTest) – This mean cTest is an Alphabet If (Character.isDigit(cTest) – This mean cTest is a Digit If (Character.isSpaceChar(cTest) – This mean cTest is a Space   There is a very useful function called getType which can return meaningful constants which will tell you

Print all the ant variables used!!!

Have a large build file and want to see what your ant variables contain? Use <echoproperties></echoproperties> in your target and you will get the list of ant properties with their values printed to standard output. You can redirect the output to a file using the attribute destfile as below <echoproperties destfile="allproperties">                    </echoproperties> You can always print individual values using echo as below <echo message=" testng.timeOut = ${ testng.timeOut }"/>

Increasing Productivity–Templates!!!

Innovation at its best would give you immense power!!! Not just for you to go places in your career but to start with give you ways to get the best out of you. Raise your hand if you are victimized by the huge number of emails sent out each day…I say each one of us has to do our share…I send out loads of emails every week…Some of them are well decided! So how do you get the most out of this boring task of sending out report, emails? Simple – Templates !!! Yes, you heard it right…I won’t dictate which templates you would want to use but the freedom lies with you…You decide which templates you are looking for…If its an email that you have to send out week after week then have a word template created for yourself which you can send out as an email Send out Word Template as an Email Here are a couple of links which I found useful while learning about word templates http://www.wordweaving.com/word-template-101/5-creating-a-word-template http://office.microsoft.com/en-us/word-help/sav

Useful Linux Commands - III

Here are some useful linux commands... whoami - This command gives you the userid you are logged in as pwd - print working directory. When you type in this command it tells you which folder you are in and along with printing the path of the folder ls - listing. This command will list out all the files and directories under the current directory sorted alphabetically ls -F - This command lists all the files and directories with directories displayed with a trailing slash and executables have a * at the end of the executable name ls -s - lists file sizes - displays in disk blocks ls -s -h lists file sizes with human readable file sizes wc - word count displays lines, words, characters for a particular file wc -c  wc -w wc -l cat - concatenate - prints the file contents one after another sort - sorts the output  head - - gets the topN results from a file mv - move - moves a file cp - copy - copies a file rm - removes a file rmdir - removes a directory cd - change dire

Useful Windows Commands

ipconfig : Used to see the IP address and the gateway mask. Can also be used to ipconfig /all : Displays all the available information for a system ipconfig /displaydns : This will display the local dns file ipconfig /flushdns : This command will clear the local dns file systeminfo : Get the operating system information using this command systeminfo /S <systemname> /U <username> : Get the operating system information for a remote system using this command tasklist : Does the same thing that starting a task manager would do…Display a list of tasks running on the system. taskkill /im <imagename> : Kills the process with the image name provided taskkill /pid <processid> : Kills the process with the process id provided type : read a file from command line using type… netstat : You can get to know who/what is getting connected to your system   netstat –a: displays all connection info netstat –b : displays the executable name in the netstat output n

Interface for and just for Static Constants?

http://stackoverflow.com/questions/320588/interfaces-with-static-fields-in-java-for-sharing-constants   Looks like using an interface and making core classes implementing the interface which has just the static constants pollutes the core class export API’s. You might want to reconsider the choice of using Interfaces for Static Constants

AJAX Testing–Some Useful Links

Testing dynamic elements is always a challenge. I found some interesting/useful links which might prove useful to you too: http://agilesoftwaretesting.com/selenium-wait-for-ajax-the-right-way/ http://stackoverflow.com/questions/6850994/wait-for-javascript-file-to-load-in-selenium-2 http://saucelabs.com/blog/index.php/2011/04/how-to-lose-races-and-win-at-selenium/   Happy Testing!!!!

Apache Commons StringUtils.isEmpty() vs Java String.isEmpty()

You might want to test for if a String is empty many a times. Before we jump onto the numerous solutions available let us take a look at how we define “Empty String”   The difference in the two methods given by Apache and Java are dependent on how we define an empty string. Java String.isEmpty returns a boolean true if the string’s length is zero. If the string has null it throws NullPointerException Apache StringUtils.isEmpty returns a boolean true if the string is either null or has length is zero   Thus its purely dependent on how you are defining “empty string” in your program which will decide which function to use…BTW if you want to skip using Apache Commons funciton and would want to stick to java then you can have your own function like this:   public static boolean isEmptyOrNull(String strStringToTest) {                  return strStringToTest == null || strStringToTest.trim().isEmpty(); }

verifyTrue vs verifyEquals to compare strings

There is a clear winner here! Lets explore which one is better. Here is the scenario: “Lets say I have to test if the appropriate tooltip is flashed for a component” To get to the code directly, lets say I already have the tooltip text stored in a variable. Now all I have to do is to compare this string to the components tooltip text which I would get at runtime. So the algorithm would be Have the Expected Tooltip text stored in a variable Get the Actual Tooltip text for the component Compare the two strings – you should get the exact text We usually tend to use verifyTrue to compare because according to our algorithm we are expecting the result of the string comparison to be TRUE There is nothing wrong in using verifyTrue as if your test passes there is no difference in using verifyTrue or verifyEquals. The actual difference comes into picture only when your test fails. String varExpectedTooltipText = “Some tooltip”; // Method 1 - verifyTrue(selenium.getAttribute(&qu

“Document Not Saved” error in Excel

Its so common that we convert an excel to a PDF. It happens almost everyday for me. It was recently that I got to see the error “Document Not Saved” while converting an excel to a PDF file.   Here are the steps which helped me resolve the issue: Step 1: Check for your permissions – Many of the times, a shared file might restrict saving the file into other forms. In this case, get the proper permissions for yourself Step 2: You have embedded objects in your excel ( MS Support Link ) If you do, then the workaround is to remove the embedded objects and try saving the file again If you don’t know anything about the existence of embedded objects just like I do, then perform the following steps   Use the Go To option from the Edit menu or use the keyboard shortcut Ctrl + G to open the Go To dialog box. Click on Special. Select Objects in the Special dialog box. Click Ok. This will highlight all the embedded objects on the excel file – now you can delete them   Picked up the

Working with File Path Separators

Something I learned very recently.  Have you ever written code which involved file path's? If yes then this post might be helpful...Even otherwise knowing something unknown or brushing up concepts known won't hurt - would they? :) So here I go, I have my Selenium Scripts which might run on both Linux and Windows machines. I don't store my test files on a central location which can be accessed over the network/internet, so when my script runs on a Linux machine it would look locally on the linux file system for the test files. Same is the case when I run my tests on Windows.  Here is what I used to do :)  My Initial Approach:  If ( Test_Running_On_Linux ){ return System . getProperty ( "user.dir" ) + "/" + TestProperties . strFilePathPart1 + "/"+ TestProperties.strFilePathPart2; } else if( Test_Running_On_Windows ){ return System . getProperty ( "user.dir" ) + "\\" + TestProperties . strFilePathPa

How to check if my xpath is valid using firebug?

Yes, you can verify if your xpath is pointing to the right source on the web application under test using FireBug. Here is how:  Go to the Web Application under test We'll take Google for simplicity reasons Open FireBug -  Go to the Console   Console can also be seen at the bottom of the page, so don't worry they both are the same. They can be switched as follows:  Type in $x("Your xpath here") on the command line prompt as shown below: Hit Enter/Run You will get to see the element which was filtered out with your XPath expression

Selenium Exception: java.lang.RuntimeException: Could not start Selenium session

You have a simple Java Selenium Code. All of it looks perfect :) except for when you try running it, it fails miserably again and again with an exception:  java . lang . RuntimeException : Could not start Selenium session The possible solutions for the above issue can be the following: You repeated the "selenium.start()" issue - Looks like if we create a webdriver first and then create a selenium object thereafter, an internal issue arises with the selenium server where it fails when we use selenium.start() So if you are wondering on how to solve - Use selenium.open() instead

Useful Linux Commands - III

To know your hostname type hostname To know the shell we are working in ps -p $$ This command would give a result: PID TTY          TIME CMD 15362 pts/3    00:00:00 zsh echo $SHELL This command would give a result like: /bin/zsh Please note that once you export your PATH variable or any other env variable, you should restart your terminal to see the changes To create links between the files we can use "ln" To view the current processes which are Running:  ps -ef | more To find out how much free memory (RAM) we have on our linux box: free This command will give the used, swap, free memory on our linux box Also the output is in bytes free -g This command will give the used, swap, free memory on our linux box in GB's To find out the disk space usage data:  df -k  This commands gives output in bytes df -h  This gives the output in GB's