Favourite Quote

Every artist was first an amateur. - Ralph Waldo Emerson The more difficulties one has to encounter, within and without, the more significant and the higher in inspiration his life will be. - Horace Bushnell

Tuesday, February 28, 2012

Getting started with Installation of WebDriver - Java Client


With SELENIUM / WebDriver being most cost effective tool for functional testing these days most of the companies are embracing this open source tool.

Let's get started with installation of WebDriver & configurations as required.

1. Download from the official website of selenium http://code.google.com/p/selenium/downloads/list

1.a Have a look at the screen shot



2. We have downloaded Selenium-2.20 version for java & selenium-server-standalone-2.20.jar was the latest when i wrote the blog

3. I am on a Windows 7 box - Create a dierctory called Selenium & have the downloaded selenium extracted. I have mine within Eclipse as i would use that as my IDE ,placed it within Eclipse for it would be easy mapping the library files a.k.a jars

This is how it would look ,folder structure & files.



Now that we have our Selenium 2 downloaded we need to have java on our box let's get that.

4. Download java from http://www.oracle.com/technetwork/java/javase/downloads/index.html

5. After you are done with installation of java to verify just go to where it is installed & check for version of java

6. Have a look at the screen shot



7. Now that we have jdk , selenium we need an IDE which is Eclipse in our case

8. Download Eclipse from there official website http://www.eclipse.org/downloads/

9. We are all set with downloads that are required to get started,Let's get to configuring as appropriate

10. Click on the eclipse.exe

11. Create a Java Project : Click on File > new > Java Project

12. Give a name to the Project as appropriate

12. Right Click on the Project name within the Project explorer window & click on Properties >> Click on Java Build Path

13. Look at the screen shot.

Screen shot 13


14. Click on Add external jars , now add the selenium-java-2.20.0.jar that we downloaded earlier

15. Again Click on Add External jars,now add the lib folder of C:\selenium-2.20.0\libs

Once you have added all your jar's it shoudl look like above screen shot 13 at step 13

16. Let's also add JUnit jar's as our framework is written in JUnit

17. Click on Java Build Path > Add Library > Will show a list of libraries just like the below screen shot

screen shot 17


Choose appropriate JUnit version

We are now done with our installations and configurations required for selenium-2,junit,java,eclipse
automationwithselenium.blogspot.com-Google pagerank and Worth

Regular expression Extractor - Testing ReCaptcha with JMeter


Most often these days every website that accepts payment want's to add additional security of having ReCaptcha inplace.

It is definitely a challenge to test reCaptcha without turning it off, but allowing to accept same password as against dynamically generated one.

So here's how i load tested reCaptcha using JMeter.

1.It is important that we know how to use the regular expression extractor,So that we retrive params from one request and pass them to another request.

2. Add a HTTP Sampler

3. We need to add Regular expression extractor which is required to retrive values from the response of the previous request. Therefore it would be a post processor.

3.a Right click on the HTTP Sampler > Add > Post Processors > Regular expression Extractor - see the screen shot


3.b Now the Regular Expression Extractor is added have a look at the screen shot,Let's have a closer look at it :



3.c Give appropriate name just like i have given ,It is however optional giving a name will help in debugging issues if it exists

3.d Apply to : leave this to default or choose as appropriate to your requirement

3.e Response Field to check : Leave this to default or choose as appropriate to your requirement

3.f Reference Name : Give a appropriate name here this act's as a variable that stores value retrieved from teh Regular expression

3.g Regular Expression : "params":"(.+?)nonce=(.+?)" Let's get to understanding this we are matching all that is after the params : and then matching the value for nonce

The special characters above are:

( and ) - these enclose the portion of the match string to be returned

. - match any character

+ - one or more times

? - don't be greedy, i.e. stop when first match succeeds

4. As i have previously mentioned it is good to add a DEBUG SAMPLER to understand whether right value is being fetched & for debugging purpose

5. Trick to validate your regular expression is :

5.a Add a View Results Tree

5.b Choose RegExp Tester to Validate if you have written the right expression

have a look at the screen shot


automationwithselenium.blogspot.com-Google pagerank and Worth

Wednesday, February 22, 2012

How to build a request dynamically in - JMeter


Most often we end up dealing with how to dynamically build our request.

Also how to fetch values received from HTTP request-1 & pass them as parameters to HTTTP request-2

We can achieve this by writing a simple script within JMeter.
for ex:
Let's take a scenario of amazon where we have to add items to the shopping basket

where items are onsale (These items onsale vary each day)

Therefore we don't want to be updating our data scripts each day

though we are reading from external files.

Let's get started to handle such situation.

1.Within a Testplan add a Thread group

2.Add a HTTP request sampler - This is our request-1

2.a We have to retrieve the item/product id's from this request so we need to add a xpath extractor as a post processor event.

Have a look at the screen shot.

2.b
Add a Debug sampler so that you can verify if the xpath extractor does retrieve the value.

To add a debug sampler right click on the Thread Group > Add > Sampler > Debug Sampler

To view contents of sampler you will have to add Listener.

Right Click on the Thread Group > Add > listener > View results tree



3.Add a HTTP request sampler - This is our request-2

3.aNow that we have retrieved id's from our previous request we need those to send as a request, Hence we need to Pre Process before a request is made.

3.b After adding your HTTP request sampler-2

3.c Right Click on the HTTP Sampler > Add > Pre-Processors > Beanshell Pre processor
Have a look at the figure


3.d Now let's take a closer look at the BeanShell PreProcessor

3.e Give a meaningful name for the PreProcessor just like i have given.

3.f Now add the script where you want to build your request.

int count = Integer.parseInt(vars.get("GET_EVENT_ID_matchNr"));

for(int i=1;i<=count;i++) {

String prefix = "eventInTopPackage[";

sampler.addArgument( prefix+vars.get("GET_EVENT_ID_" + i)+"]", vars.get("GET_EVENT_ID_" + i) );

}

Let's understand what we are achieving in the above script.

3.g Get count of the matched id's that were retrived from Xpath Extractor.

prefix - Is constant/static value

param - Will now have eventInTopPackage[] event_id_value

Have a look at the screen shot how request will look
automationwithselenium.blogspot.com-Google pagerank and Worth

Tuesday, February 21, 2012

How to add a Xpath Assertion in JMeter

As i've mentioned in my earlier posts about how assertions can be of help in validating the right response code

Xpath Assertion eases life when we have to validate if an object exists.

For ex:

Let's again take a shopping cart example.

1.Search for an item
2.Add selected item to shopping cart > now we want to verify if the Add cart button is available on the page.

Therefore we need to add a xpath assertion.

Below screen shot should give a clear idea & how an expression is built.



Let's have a closer look at the Xpath Assertion.

Add a xpath Assertion :

1. Right Click on the HTTP Sampler > Assertions > Xpath Assertions.

Once you'ev added the Xpath Assertion, now we have to add appropriate values so that we can assert object or value.

1. Give a name to Xpath Assertion just like i have given not necessarily same.

2. XML Parsing Options - Check the Checkbox's against "Use Tidy(tolerant parser) & Quiet".

3. Xpath Assertion - contract the xpath & pass the xpath string within the Xpath Assertion.

For ex : I am validating to see if the button with id "bestAvailableTickets_LookForTicketsButton"" exists on that page.

I have left the "True if nothing matches" as unchecked as i want it to match.
automationwithselenium.blogspot.com-Google pagerank and Worth

How to post parameters with request in - JMeter

We most often have to post our request with dynamic parameters or even static parameters,It would be handy if we did find a way to post our parameters.

For ex:

Let's say that :

1.I have a shopping cart as my application

2.I am seaching for a item

3.Adding it to my shopping basket

Assuming that we figured out what are the parameters that we need to pass to the request.

We can use FireBug as a tool to identify what are parameters that are sent with a request quickly (or)
We can use LiveHTTP Headers to do the same functionality of identifying what are variables that are dynamic,static,values/names of the object.



So let's have a closer look at the image above.

1. Add a sampler viz., the HTTP Request give a name to the request just as i have given.

2. Method is "POST" we have different webmethods for each request we do.

3. POST method uses web method which means that you are posting a request to the
server & the response will be sent inturn to the server.

4. To avoid the hiccups we face in future let's parametrise the dynamic content by passing it as a variable either as user parameter or from a CSV file.

5. Click on the Follow Redirects & Use Keepalive so that we can have a look at if there are any redirests that occur.

8. Now let's have a look at the parameters which we have to pass through our request.

9. Make sure you know what the application code rather id for an object is called as,you can find out this by using Firebug or Live HTTP Headers both the name & value.

10.We send the Name Value pair as request so name is the id/name that uniquely identifies an object on the application.

11.It sometimes rather often happens that we don't want to change the values frequently in those scenarios you can read values from a CSV file.
automationwithselenium.blogspot.com-Google pagerank and Worth

Adding Response Assertions


It is often important that we validate the response we receive for every request we had sent to the server.

We can achieve this by adding a response assertion to the sampler.

There are various types of assertions you will have to identify what serves your purpose & work accordingly.

Add a response assertion by right clicking on the sampler > Assertions > Response Assertion - Have a look at the fig1




Now that we have added a response assertion let's have a closer look at the settings & values we are looking for identifying/validating our response.

1.Add a name to teh response assertion so that you know when it fails.

2.Select the radio button Main Sample only - this looks for text you are looking for in the main sampler.

3.Let's select "Text Response" as we are going to validate the same.

4.Pattern of matching - Helps in identifying what operation rules you want to apply a wider search pattern would be "Contains" so that pattern matching ignores the pre & post text & just look for "Pattern String".

5.In Patterns to Test - Click the Add button just below the patterns to test "enter the text you want to validate".


It is that easy ... Adding a response assertion. automationwithselenium.blogspot.com-Google pagerank and Worth

Thursday, February 16, 2012

How to add user defined variables in JMeter at Test Plan level

User defined variables with JMeter can be defined at various levels.

1.At a Test Plan level adding here will result in using the variables across the thread groups it could range from variables to passing the csv file.

Here's the screen shot :



2.At a Thread Group level by adding a pre processor > User parameters.
This is usually used when you want to iterate through 'n' users it is preferred to read from a external file if the data is massive.

However let me show you details on how to add a user,delete a user ,add variable & delete a variable.

When we add at a thread group level it acts global to that thread group & all those samplers within that thread group.




3.Sampler Level by adding a pre processor > User Parameters.

Adding user parameter at sampler level is more like a local variable to that sampler.

It is accessed by right clicking on the sampler >> pre processor >> user parameters automationwithselenium.blogspot.com-Google pagerank and Worth

Monday, February 13, 2012

Using XPATH Extrcator

Xpath plays a vital role when you want to extract value of an object present in one request and pass fetched value on to a next request.

This is more often true when you never know what would be the id in simple terms if the value is dynamic & changes for every request.

Let's take a shopping cart example:


1. When we add items to the cart we never know what forms a cartId,if we have to pass that cartId to the basket.

So let's extract the value of Id by passing a xpath query to search for the name "cartId" - This can be determined either by firebug if you are on firefox or debugbar if you are on Internet explorer.


2.Add a debug sampler so that you will know what is returned in the variable you stored.

3.How do we add a XPATH Extractor to our HTTP request.

3.a Right Click the HTTP request

3.b Click on Add >> Post Processors > Xpath Extractor



4. Let's have a closer look at the XPATH Extractor.



4.a Give a name to the xpath extractor.

4.b Check the Use Tidy and the Quiet

4.c Add Reference name - It is like a variable name

4.d Pass the Xpath query

4.e Pass the default value it will displayed if there is no value being fetched from the query.

GUI View - System / JMeter Properties.

JMeter Properties let's us have a look at the Jmeter.Properties file that is placed within the bin folder of the jmeter installation directory you.

It gives a nice GUI view as against the files being edited.



To have a look at the Property file.

1.Right Click on the work bench.
2.Add Non- Test Elements.
3.Property Display.

Will result in displaying all properties of the JMeter.You can select to view the system properties or the JMeter Properties. automationwithselenium.blogspot.com-Google pagerank and Worth