Showing posts with label selenium. Show all posts
Showing posts with label selenium. Show all posts

Saturday, February 26, 2011

Review of - The Selenium Testing Tools - Beginner's Guide

As mentioned in one of previous post, I got an opportunity to review a book on Selenium call - The Selenium Testing Tools - Beginner's Guide from PACKT Publishing.

Selenium 1.0 Testing Tools: Beginner’s Guide

I had used Selenium in lot of my projects, I thought, I knew selenium quiet well before reading the book.  After reading the book, I realized that, I had only partial knowledge about Selenium.  I knew how to do things, but the book taught me, how to do them in many different ways and what was the best way in a given situation.

The book, taught me lot of new things about Selenium.  For example, I always thought that, using Selenium IDE, one cannot write maintainable tests, but after reading the book, I realized that if one follow the patterns mentioned in the book, one can easily write maintainable tests simply using Selenium IDE.

Moreover, non-programmers can convert the Selenium IDE tests to programming API tests in a matter of few clicks!

There are may good things that, I could take away from the book, here are a few that stood out:

  • Starts of from the very basics.  The book start with installation of Selenium IDE, Firebug and Firefinder add-ons to Firefox.  Because of this, someone who has never worked with selenium before, can quick start and write their first selenium tests in a matter for minutes
  • While reading some books, I get lost and have to figure out how to do a certain step.  But things are different with this book, there are screenshots for almost every thing.  For every step that book shows there is a Screenshots.  This helps us understand the concepts in a much better way.
  • Book encourages the use of best practices.  For example, book clearly explains why the test cases should be independent of each other and how one could achieve that.  Book encourages the use of Firebug and Firefinder.  These are two tools which every web-develop/web-QA should know for sure!
  • Explains how one can convert Selenium IDE test to programming tests using just the Selenium IDE.  I did try it and it does work!
  • Book Explains how we could use Selenium Grid to parallelize our tests.  Using Selenium Grid we could target our tests to run on a certain browser on a certain OS.  For example, we could configure that Test1 should run on "Firefox on Mac" or "IE on Windows".  Using this feature you can test your application on lot of platforms and browsers without a lot of pain!
  • Demonstrates advanced techniques like Cookie handling using Selenium API
  • A full chapter dedicated to Selenium 2
  • At various steps, the book presents the user with Popup Quizzes, these are helpful to test what we have learned!
  • Explains the Page Pattern.  While writing the Selenium tests using the Programming API, its extremely important that we do not repeat code for every test.  Book explains how we could achieve maximum reuse of code.  End result, more maintainable and easy to write/read tests!
  • Explains various techniques like xpath, regexp, css and javascript to locate an element.  Its extremely necessary that we learn how to locate the element efficiently.  Using the right technique at the right place could result in faster and easy to read tests.  For example using xpath at a place where css could have been used would result in slower tests!
  • Explains the use of user extensions.
Those are some of the take away's for me from the Book.  

The book has much more to offer than, what I have described here.  Take my advice, do not waste any time and grab a copy of the book from here!

Monday, February 7, 2011

Learning good things about Selenium - The Functional Testing Tool

Recently, I have been learning a lot of good things about Selenium. All thanks to this book, Selenium 1.0 Testing Tools - Beginner's Guide.

Selenium 1.0 Testing Tools: Beginner’s Guide

I got an opportunity to review this book from PACKT Publishing. I have just started reading the book, but I can tell you one thing, it gives great start at working with Selenium.

What is Selenium?

Selenium is an opensource automated testing tool for testing web application.  Using Selenium we can write test cases to test the web application in a black box environment.

Quoting from the book:

Test automation has grown in popularity over the years because teams do not have the time or money to invest in large test teams to make sure that applications work as they are expected to. Developers want to make sure that the code they have created works as they expect it to.


As time has passed developers and QA's have realized that automated functional tests provide a great safety net for catching bugs early in development life-cycle.  Selenium makes writing/executing functional tests extremely easily.

We can record and playback the tests directly in firefox using the Slenium IDE!  Selenium also provides programming api to write functional tests in Java, C#, Ruby , PHP, Perl and Python.

Once the tests are written (using the programming API or Selenium IDE) they can be execute as often as one wants using the Selenium RC (remote control) or Selenium Grid!  Over and above it the test can be executed in variety of browsers including IE, Firefox, Opera and Safari!

Selenium can be used to simulate any work flow.  I have been in situations where, because the team had written Selenium tests, a bug was caught early in the development life-cycle, which would otherwise be caught very late.  End result lot of time and money was saved because of Selenium!

The things I am blabbering (about Selenium) in this post are covered in much greater detail in the book.  Simply by reading the first few pages I was able to write a functional test using Selenium IDE.

Some of the good things I have noticed about the book so far:
  • Starts from basics.  The book starts of by guiding users through the installation process of Selenium IDE.  Goes on to explain how to write a simple functional test (using Selenium IDE), with an example.
  • Easy to read.  Its very important that books are written in simple language so that everyone can read it easily.  People with/without programming background can read this book with equal ease and extract useful information out of it.
  • All concepts are explained using examples and lots of screen shots.
These are just initial impressions about the book.  I am sure, I will discover many more good things about the book, as I continue reading further!

Stay tuned folks!  Full review of the book coming up very soon!

Saturday, October 30, 2010

How to run selenium tests as part of maven build phase

Recently I came across a very simple requirement.  Our project used Maven as the build tool and we wanted to run Selenium tests as part of the build.  The idea was, QA's write the automated selenium tests, these should run as part of the integration-test build phase

There are multiple advantages of doing this:
  • We could run these Selenium tests on our Continuous Integration server (Hudson in our case) as part of build process.  This means, if because of some check-in, a selenium tests fails, the build fails and hence someone has to fix it!
  • Developers and QA's can easily run these functional tests whenever they want.  For e.g. if developers want to make sure that the code they are about to checkin does not break any existing functionality they can run the functional tests before checkin with just one command.
So how do they do it?

Lets try and reverse engineer the problem.  To run selenium tests we need to do the following things
  1. Compile the app
  2. Run unit-tests
  3. Create a war file of the application
  4. Run an tomcat server (or any other servlet container you are using)
  5. Deploy the war file created in step 3 on the server started in step 4
  6. Start the selenium server
  7. Fire the selenium tests
Looks like a lot of work to me!  But don't worry we will see in a moment that its not as difficult as it sounds.

Lets do this step-by-step:

Lets break down the problem.  If you look at the above mentioned 7 steps.  We can classify them in four broad categories
  1. Compile the application and package it as a war file. (steps 1-3)
  2. Run the tomcat server (steps 4-5)
  3. Run the selenium server (step 6)
  4. Run the selenium tests (steps 7-8)   
Problem looks simpler now?  Lets try and slove the above four problems separately first.  Later  we will see how we can solve all of them using just one command.

Solving the step 1:

Assuming that you already have the pom.xml setup to properly compile and run unit-tests.  We need to add the configuration in pom.xml to package the application as war file.  This is what we have to do

Find the tag called <packaging> in pom.xml and set the value of the tag to war instead of jar.

Then, we need to tell maven about how the war file will be generated.  This is done using the maven-war-plugin.  The sample configuration looks like this:

Of course for all this to work you should have a proper directory structure and web.xml.  But I will assume that you already have that in place.

At this point if you run the following command:

You will get a war file ready to be deployed in any servlet container.

Next, Solving the step 2:

To run an embedded tomcat server we have to add the following configuration to pom.xml

Now, when we run the following command, we will have a running tomcat server with our application deployed on it.


Next, Solving the step 3:

To start the selenium server from command prompt we need to do two things.
  • Add the dependency of selenium drivers to the app.  This is required so that we could use selenium api to programmatically write selenium testsThis is done using the following code:

  • Add the selenium plug-in so that we can start the selenium server from the command prompt.  This is done using the following code:

After this we can start the selenium server using the following command:


Next, Solving the step 4:

Now, we are ready to run the tests simply run the tests using the following command:

We have our selenium tests running as part of our maven build!  To do this we have to fire three commands from three command prompts/terminal windows.  One running tomcat, another running selenium server and the third running the tests.

All this is good but we don't want three command prompts running.  We just want one command that does it all!

And this is exactly what we are going to see next!

So as you already know that Maven is build around phases, we are going to run our functional tests (selenium tests) in the integration-test phase.

To run the selenium tests in the integration-test phase we have to do the following:
  1. Start the tomcat server
  2. Deploy the war
  3. Start the selenium server
  4. Fire the function tests
Here's how we do steps 1 and 2:

Above configuration means that following things in plain english:

  • Start the tomcat6 server
  • Deploy the app during the pre-integration-test phase.  
  • Stop the server during the post-integration-test phase.
You will have to define an environment variable CATALINA_HOME, which points to the tomcat server installation directory on your machine.

Next up, Step 3 do this:

Above configuration states the following:
  • Start the selenium server during the pre-integration-test.
  • Stop the server during the post-integration-test.
Next, Step 4: 

To run the functional tests during the integration-test phase, do the following (I promise this is the last bit of XML that you see on this post!)

This configuration does the following:
  • Tells maven-surefire-plugin to run the unit tests during the test phase but exclude the classes in the functional folder.
  • Run the test class in the functional folder during the integration-test phase.
And that's it my friend!  Now when you run the following command:

  1. Application will compile
  2. Unit tests will run
  3. War file will be created
  4. Tomcat server will be started 
  5. war file will be deployed on the tomcat started in step 4
  6. Selenium server will be started
  7. Functional tests will be fired
  8. And we will live happily ever after!
Have some Fun!