Wednesday, July 4, 2012

WARN - Failed to start: SocketListener0@0.0.0.0:4444

WARN - Failed to start: SocketListener0@0.0.0.0:4444
Exception in thread "main" java.net.BindException: Selenium is already running o
n port 4444. Or some other service is


This is very command issue which you will see when you start selenium server either from your code or from command line.
This WARNING comes generally because selenium server is not shutdown properly and you are trying to start again.

So you just need to make sure after you see this error that your selenium server has been stopped properly. To achieve that you need to run the below command in browser URL(Address bar)

http://localhost:4444/selenium-server/driver/?cmd=shutDownSeleniumServer

This will show you OKOK and then you are down. Now you try to start selenium server again and it should start without any problem.

Saturday, June 9, 2012

Change Address Bar Search Provider in Firefox

There are couple of thing you should know about address bar in Firefox. Not necessarily important but yes interesting.

When you type any thing in Firefox address bar it looks for url , if it is not an url then it sends this keywords to Google (By default). The is Google's “I’m Feeling Lucky” option. This “I’m Feeling Lucky” option will load the #1 rank website of the keyword(s) search result, instead of listing matching websites. In simple English if you search same keyword in www.google.com it will give you all search instead of top rank website.

Now there are two things which comes in mind.
How to get rid of   "I m Felling Lucky" Option?
How to change the search engine itself?

Let's look at the first one.
Step 1: Start Firefox
Step 2: Type about:config in address bar (Same place where you type URL)
Step 3: It may give you warning , select "I will be careful, i promise"
Step 4: Search for Keyword.URL and double click on it.
Step 5: Paste below in "Enter String Value"
            http://www.google.com.my/search?q=
Step 6: Select Ok and Your are done.

Now searching from  Firefox address bar will not use "I am feeling lucky option".


Now, how to change the search engine itself. Not every body want to search every thing on google. I uses Bing some times.

Step 1: Start Firefox
Step 2: Type about:config in address bar (Same place where you type URL)
Step 3: It may give you warning , select "I will be careful, i promise"
Step 4: Search for Keyword.URL and double click on it.
Step 5: Past below in "Enter String Value" as
           Bing :
           http://www.bing.com/search?ie=UTF-8&oe=UTF-8&sourceid=navclient&gfns=1&q=

          Yahoo: http://search.yahoo.com/search?p=

          Ask: http://www.ask.com/web?q=

 
 Hope this is helpful.

Use Multiple Firefox Profiles at the Same Time

This is help full in many ways. I do use this in selenium automation to run multiple test case at the same time.
If we different user cert (authentication) for different step us, if i need to check one bug on another old set up which have different user cert installed i can just start that profile and test at the same time.

Step 1: Make Sure you have created Multiple Firefox Profile. If not see the sub steps how to create multiple profile.
        Step A: Open command prompt or Press Windows + R button
        Step B: On command prompt go to C:\Program Files\Mozilla Firefox location and Run below command
                    firefox.exe -P or firefox.exe -ProfileManager
                    If using Windows + R button then type same  command in Run
                    firefox.exe -P or firefox.exe -ProfileManager  
        Step C:  Click on Create Profile
        Step D:  Click on Next and Give the Profile Name
        Step E:   Now Click on Finish... Your newly created firefox profile is ready

Step2: Open command prompt or Press Windows + R button

Step 3: If command prompt then go to C:\Program Files\Mozilla Firefox location and type below command
            firefox.exe -P -no-remote  or   firefox.exe -ProfileManager -no-remote
            If pressing Windows + R then type the same above mention command in Run
            firefox.exe -P -no-remote  or   firefox.exe -ProfileManager -no-remote

NOTE : Make sure there is no space between -no and -remote

Step 4: Now select any profile which you want to run and press  "Start Firefox" button.
            or directly type firefox.exe -P -no-remote "ProfileName"
            You have started first profile successfully now try opening another profile at the same time.

Step 5: Follow Step3 again and run the same command again

Step 6: This time select another profile and press "Start Firefox". Your are running two different profile at a time.

You can check if you are opening two different profile or not by setting up Tools -> Option -> General -> and set two different home page for two different profile.Now start you two different profile at the same time and see if both profile are opening correct home page or not.

Of course there are other way to check the open profile name.
Explore more command/option for firefox profile manager
http://kb.mozillazine.org/Command_line_arguments

Hope this post will help you.

How to Create a Hibernate Shortcut key in Windows

I don't shut down my laptop when i am done at office. I hibernate my laptop so that i can open my laptop at home and start working where i left my work or  next day start the work from same place where i left. In Windows XP to hibernate you have to do Start - > Shut Down and then select Hibernate from drop down. What if you have option like Windows + d or Windows + L (generally daily in use).

I will help you to create same kind of Short Cut key for Hibernate mode for your windows laptop or desktop.

Step 1: Right click on the desktop and select New -> Shortcut

Step 2: Type this into the location field:
C:\Windows\System32\rundll32.exe powrprof.dll,SetSuspendState 0,1,0



 Step 3: Name it whatever you would like: and Finish



Step 4 (optional): Change the icon to something meaningful. Right click on the shortcut, and select Properties. In the Shortcut tab, choose "Change Icon". You can use the default icons in there, or choose from the power icons by clicking browse, and typing this:


%SystemRoot%\System32\powrprof.dll

 Select any of icon which you like and icon for your Hibernate_Shortcut is ready.

Step 5 :  Right Click on Hibernate_ShortCut - > Properties -> Shortcut -> Short cut key
Select short cut key field and press some key example : Ctrl + h. Your selected key will be shown there.
Now click on save and you are done.

To test press Ctrl+h and your laptop or computer will go in hibernate mode.



Thursday, March 24, 2011

How to delete browser cache using selenium


Yes, you need this when you are trying to run you test cases one after another and you don't want to restart the browser as well as you want to avoid creating new profile to run new test case. Restarting browser and creating a new brand profile is slow and time consuming. There are multiple solution for this.

* Create a batch file and call in you code before you start your test case. For more information here.
* Write a javascipt to clear the cache. Go here.
* Use Selenium.deleteCookie ( name,optionsString )
* Use Selenium.deleteAllVisibleCookies()


I am using selenium.delete and selenium.deleteAllVisibleCookies method provided by selenium RC.

deleteCookie ( name,optionsString )
Delete a named cookie with specified path and domain. Be careful; to delete a cookie, you need to delete it using the exact same path and domain that were used to create the cookie. If the path is wrong, or the domain is wrong, the cookie simply won't be deleted. Also note that specifying a domain that isn't a subset of the current domain will usually fail. Since there's no way to discover at runtime the original path and domain of a given cookie, we've added an option called 'recurse' to try all sub-domains of the current domain with all paths that are a subset of the current path. Beware; this option can be slow. In big-O notation, it operates in O(n*m) time, where n is the number of dots in the domain name and m is the number of slashes in the path.
Arguments:
· name - the name of the cookie to be deleted
· optionsString - options for the cookie. Currently supported options include 'path', 'domain' and 'recurse.' The optionsString's format is "path=/path/, domain=.foo.com, recurse=true". The order of options are irrelevant. Note that specifying a domain that isn't a subset of the current domain will usually fail.

For my test case I am not using “recurse” parameter. In result my deletion of cache is prety fast. As I have droped “recurse” so “domain”. So Example is here.
selenium.deleteCookie(“JSESSIONID”,”path=/console”);
You can see cookies name and path in your browser(FF). Tools -> Options -> Privacy -> remove individual cookie -> and type the url in search.
Now when you use “recurse” your optionsString will change slightly.
optionsString = “path=/console/”, domain=”.bbtest.net”, “recurse=true”)
Note: Extra / at the end of path. Dot(.) before the domain name.

Selenium.deleteAllVisibleCookies() , It does not have any parameters. It is like calling selenium.deleteCookie with “recurse=true”

Hope this will help you.

Thursday, February 3, 2011

How to test SSL using Jmeter

Updated
It’s been dark over net and was hard to find any good and consolidated doc about this. I got some information and trying to consolidate all and putting here.

For your brief information A keystore contains private keys, and the certificates with their corresponding public keys. A truststore contains certificates from other parties that you expect to communicate with, or from Certificate Authorities that you trust to identify other parties. If you open any browser you can see truststore of all valid CA installed in browser by default. If you have installed any .pfx certificate for authentication in browser you can see in keystore of browser.

Please follow the steps as needed for you requirement.

Phase 1: If server supports ssl (https). One ways SSL. This is very common SSL where your server have certificate. Gmail is an example of one way SSL when you hit gmail it always opens in https://

Phase 2: Two way SSL where server is configured for two ways SSL. It is next step of one way ssl. Here when server handshake happens it ask for user authentication and one certificate would be installed in your browser.

How to test Phase 1:

It is very simple. You need Jmeter. You need java keytoo.exe which come in all latest version of java under java/jdk/bin directory.

Steps:
         
1.)  Make Sure you have java 1.5 or above version installed and classpath configured
3.)  Unzip  Jmeter
4.)  Open browser, hit the https (SSL) site that you want to test
5.)  If Site is https then the URL first part will be in green color
6.)  Click on Green part
7.)  One pop up will open, Select More Information button
8.)  Next Select Security -> View Certificate ->Details
9.)  Select the Root CA and export it. See picture below for your understanding. (You can save in PEM or .der format)
10.)   Now using java keytool.exe convert exported file to .jks
keytool -importcert -alias mycert -file exportedFile.der  -keystore Convertedtruststore.jks -storepass password

11.)  Now copy this jks file in some directory. I create a cert directory in jmeter and
Keep this file there.
12.)    Now open file system.properties from jmeter/bin
Add this line at that end of the file.

          javax.net.ssl.trustStore=C:/jakarta-jmeter-2.4/Convertedtruststore.jks
(Make sure all other javax.net.ssl.trustStore is commented except what you enter)
13.)    Start jmeter from jmeter/bin/jmeter.bat
14.)    Create thread with server and login details
And you are ready to test SSL using Jmeter.

 
How to test Phase 2:

You need java keytool, jmeter and jetty.jar to test two way ssl. Download /jetty-6.1.22.zip from this location (http://dist.codehaus.org/jetty/jetty-6.1.22/jetty-6.1.22.zip). Unzip this file.
There are lot more other stuff that we will not use for SSL testing.
Look for jetty-6.1.22\jetty-6.1.22\lib\jetty-6.1.22.jar. You just need this jar file from this whole download. Copy this at some location.

Steps:
  
        1.)  Follow the same step to convert truststore to jks mention in Phase1. 
        2.)  Copy your .pfx certificate (cert for login authentication) inside the location where you     
             copied jetty-6.1.22.jar. 
        3.)  Run below command to convert .pfx file to .jks file
java -classpath jetty-6.1.22.jar org.mortbay.jetty.security.PKCS12Import AdminCert.pfx   AdminKeystore.jks

Input keystore passphrase : is the password which you give while installing the cert in browser.
Output keystore passphrase : new password if you want or else give the same old password that you used while installing the cert.

        Example:
        C:\jakarta-jmeter-2.4>java -classpath jetty-6.1.22.jar org.mortbay.jetty.securit
        y.PKCS12Import "ADMIN.pfx"  "Admin_Keystore.jks"
        Enter input keystore passphrase: password123
        Enter output keystore passphrase: password
        Alias 0: a30aa2839c8903cfab4c10a0bf63bb38_ed9f8b24-03cd-4908-9bed-3adc703c5d80
        Adding key for alias a30aa2839c8903cfab4c10a0bf63bb38_ed9f8b24-03cd-4908-9bed-3a
        dc703c5d80 
        4.)  Copy these two .jks file and put it inside some directory in jmeter (Mention in Phase1) 
        5.)  Now open file system.properties from jmeter/bin
       Add this line at that end of the file.

          javax.net.ssl.trustStore=C:/jakarta-jmeter-2.4/Convertedtruststore.jks

javax.net.ssl.keyStore=C:/jakarta-jmeter-2.4/Admin_Keystore.jks

javax.net.ssl.keyStorePassword=password

(Make sure all other javax.net.ssl.trustStore, javax.net.ssl.keyStore, javax.net.ssl.keyStorePassword are commented except what you enter)

   6.)  Start jmeter from jmeter/bin/jmeter.bat 
   7.)  Create thread with server and login details
And you are ready to test SSL using Jmeter.

Hope this will help you to test SSL using jmeter. Let me know if you have any question.
                                                                                                Thanks,
                                                                                                Manoj Rajan