Skip to main content

Posts

Showing posts from May, 2012

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!