Skip to main content

Posts

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"  ...

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 ...

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...

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 c...