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

Thursday, August 16, 2012

Setting up WebDriver for C# bindings with VS2010 ,NuGet , NUnit , TFS


With changing need & moving onto different businesses/work place.

We are thrown different challenges !!!! mine was get the framework done in C#

As the technology stack was .Net/IIS servers.

Here's a step by step illustration of Integrating Visual Studio 2010 with NuGet, webDriver C# bindings ,Team Foundation Server

Pre-requisites :

1. I have a licensed Visual Studio 2010 installed on my box,if you don't you can live with a trial version too

2. Now adding NuGet to Visual Studio 2010

A bit about NuGet : Yeah it’s NuGet & not Nugget  to all those nugget fans
NuGet is a Visual Studio that makes it easy to install and update third party
libraries(In our case it is webDriver API’s) and tools in Visual Studio.


3. VS 2010 > Click on Tools > Extension Manager

a. As shown in the screen shot as you don’t have NuGet already installed you should see DOWNLOAD against the NuGet Package Manager

b. I have NuGet on my box so a little green icon.




We are now done with adding NuGet Package Manager

Pre-requisite : TFS access if you are using Team Foundation Server as your version control get your Login details from whoever manages it

1.Start your Visual Studio 2010 on start you should your screen just like the one one displayed in screen shot

a.Click on servers and add your TFS server

b.Assuming that you have already identified location to check-in your code select that directory

d.Click on Connect



2. On click to connect a pop-up opens up

a.Enter the TFS server name /url just as shown in the screen shot



3. Now to we have gained access to TFS & integrated with VS 2010 we have to create a local folder that maps to the folder in TFS



4. Either select the default Workspace or create a new one. while you are on a Source Control Explorer view- like shown in the screen shot



5. On selecting one of the workspaces you'l see a popup just as shown in the screen shot



6.Now Click on Add & enter all details required as shown in screen shot



7.We are nearly there Switch to Source Control Explorer and get the latest version



8.Let's verify if a local sync was actually through just like the one displayed in screen shot



9.Add a file called packages.config look at the screen shot





10.For getting latest updates for any of your third party tool set.

Use NuGet - go to Extension manager & click on updates you'l be able to see them click on update you are all done.
automationwithselenium.blogspot.com-Google pagerank and Worth

Wednesday, May 23, 2012

Invoking a InternetExplorer using InternetExplorerDriver


It is been a struggle to get the InternetExplorer work with different drivers available specifically for each browser.

Life would be easy at work when we move finally to Selenium Grid.

Steps to get the internet explorer driver work :)

1. Download the internet explorer driver from seleniums

2. Add the below snippet for Invoking the InternetExplorer Driver

3. Have a look at this bug that was raised for issues with InternetExplorerDriver http://code.google.com/p/selenium/issues/detail?id=1795

If you hit any of the issues, However the below solution works perfectly fine.

var options = new InternetExplorerOptions();

options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;

IWebDriver driver = new InternetExplorerDriver(options);


Thought of Adding this bit here with New release of IE standalone server Selenium WebDriver 2.22

Reason for having a standalone server

" The IE WebDriver now has a standalone server. Previously, we've relied on packaging and silently using our own DLL, but this often meant that Selenium was falling foul of overly active virus scanners. If you place the new IEDriverServer.exe on your %PATH% the InternetExplorerDriver will Do The Right Thing and use it. For now, the DLL is also still packaged just as it always was, and you can use it by setting the DesiredCapability "useLegacyInternalServer" to the boolean "true" value when creating your IE instance."

Now a bit more steps to follow/get IE working

1. Download the latest IE standalone server based on your requirement of 32 bit or 64 bit

Download from here : http://code.google.com/p/selenium/downloads/list

I have downloaded InternetExplorerDriver standalone server for 64-bit IE

2. Unzip it to a location where all other .dll files are present

3. You can either set a path to locate IEstandaloneserver or call within your script the executable

This is how you will call within the script.

Updates that are needed for our code to invoke is as follows


var options = new InternetExplorerOptions();

options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;

IWebDriver driver = new InternetExplorerDriver(@"C:\Selenium\",options);

automationwithselenium.blogspot.com-Google pagerank and Worth

Wednesday, May 2, 2012

Invoking a Chrome browser - using ChromeDriver


As ChromeDriver is developed is Collaboration with the Chromium team.

Implementation is slightly different, Thought i'll better have it blogged which may help any one

Here are steps i followed to override the Enable Protected Mode To All zones

1. Here's the detailed wiki of selenium for a bit of background http://code.google.com/p/selenium/wiki/ChromeDriver

2. Download a appropriate driver based on your Operating System http://code.google.com/p/chromedriver/downloads/list

There are many ways mentioned on the selenium website for invoking the ChromeDriver.exe,I am mentioning what worked for me

IWebDriver driver = new ChromeDriver(@"C:\Selenium\");

driver.Navigate().GoToUrl("Pass your http request");

3. The above snippet is C#

4. On executing your tests

5. Just like in screen shot you'l see the chromedriver.exe being initialized



6. Then the browser launches

7. You will have to cleanUp at the end of your test by quitting the driver

driver.Quit();
automationwithselenium.blogspot.com-Google pagerank and Worth

Thursday, April 19, 2012

Generating HTML report for NUnit with Nant


In my earlier post we saw how we can get the NUnit runner with our Visual Studio 2010 ultimate.

Now let's look at how to generate reports in html format.

Steps invloved in generating a html report for nunit tests :

1. Download Nunit2report from http://sourceforge.net/projects/nunit2report/ and unzip it to a location just like in the screen shot

2. Download Nant from http://nant.sourceforge.net/ if you don't have already place it in a location suitable to you

3. Once you are in Nunit2Report bin directory - You must have these files just like i have in screen shot

4. Copy all files from the bin directory of Nunit2Report to Nant/bin directory - Just as in screen shot

5. Add reference to Nant with Visual Studio 2010

6. Click on Tools Menu in Visual Studio and click on External Tools - Just like in Screen shot

7. Add details just like i have entered in the external tools configuration for nant

8. You can either follow step 7 for integrating Nant with Visual studio or just create a batch file with details $NANT_HOME\bin\nant.exe -buildfile

9. Let's look at how our build file looks - Have a look at the screen shot

10. You should see a nice html report - Just like screen shot

11. We can add a task to email results as well using the mail task
automationwithselenium.blogspot.com-Google pagerank and Worth

Monday, April 16, 2012

Integrate Nunit With Visual Studio 2010 Ultimate IDE


How to Integrate Nunit with Visual Studio :

1. Download Nunit from http://nunit.org/?p=download

2. I have Visual Studio Ultimate 2010 IDE have tried only with this not sure if it works well with other versions former or later.

3. Go To Tools Menu >> External Tools.

3.a It would look like this



4. Click on Add - Enter Details as specified based on your system settings - Have a look at the picture

4.a Click on Apply & then OK



5. Click on Customize - Check Against Nunit and then close

5.a Have a look at the picture



6. You should be able to see Nunit within your Tools Menu

7. Click on Tools > Nunit - You will see GUI open up

7.a Just like the one in the screen shot


automationwithselenium.blogspot.com-Google pagerank and Worth

Tuesday, April 10, 2012

Getting started with WebDriver C# & Visual studio


With new changes in work environment & Agility comes change in technology & moving on from your usual traits

To explore & challenge yourself with new paths.. Ahh am going to philosophical :)

Let's get started with WebDriver C# - It took a while for me to move from jars to dll's, API's to

Assemblies,Packages to namespace ...But must say have gone past the initial hiccups..

It looks all well now, Hence blogging my experiences :) as i could hardly find any help on C#.

List of Things to do before plunging in :

1. Download webDriver for .NET from http://code.google.com/p/selenium/downloads/list

2. We have licensed Visual studio ultimate 2010 as IDE,If you don't have one you can download Visual studio Express

3. You can either write in NUnit framework or in Microsoft's Test tools in Visual studio

4. Download Nunit from here based on the operating system you are in

http://www.nunit.org/index.php?p=download

5.
automationwithselenium.blogspot.com-Google pagerank and Worth

Thursday, March 8, 2012

Microsoft's SilverLight Plug-in


Microsoft's SilverLight Plug-in:
Silverlight is a powerful development that comes with Rich Internet Application ,how does it impact testing.
Challenge for a tester is object identification :
Though it is cross browser compatible it is hard to identify objects with the usual selectors
FireBug
IE developer
Debug bar

Solution is :
SilverLight Spy
This is Opensource tool for identifying UI elements that are developed in SilverLight with limited features & commercial with full features.
Here is there official link : http://firstfloorsoftware.com
Screen shot -1 : Displays the Where to enter url

Screen shot -2 : Displays How to use the UI element selector
Tabs of Properties,View,Statistics(Am not sure how we are benefitted with this
automationwithselenium.blogspot.com-Google pagerank and Worth

Thursday, March 1, 2012

Writing our first script in WebDriver


Prior to getting started with writing scripts ensure that you have completed your installations & you have identified which framework you would work with

I have chosen to write the test in JUnit Framework , Where Eclipse is my IDE & Selenium 2.

Here is a basic script for search on an amazon site.

Objects that are dealt are :

1. Drop down list

2. Text box

3. Button

4. Link

Actions performed are :

1. Am selecting a value from drop down list

2. Enetering text in the text box

3. Clicking on the button.

4. Clicking the link that meets my partial text of the url's fetched


import org.junit.Test;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.firefox.FirefoxDriver;

public class Search {

@Test

public void testSearch(){

WebDriver driver = new FirefoxDriver();

driver.navigate().to("http://www.amazon.co.uk/");

WebElement dropDownsearch = driver.findElement(By.id("searchDropdownBox"));

dropDownsearch.sendKeys("Electronics & Photo");

driver.findElement(By.id("twotabsearchtextbox")).clear();

driver.findElement(By.id("twotabsearchtextbox")).sendKeys("Sat Nav & Car Electronics");

driver.findElement(By.id("navGoButton")).click();

driver.findElement(By.partialLinkText("Satellite Navigation System")).click();

driver.close();

}

}
automationwithselenium.blogspot.com-Google pagerank and Worth

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