Thursday 29 August 2013

selenium IDE Tutorial for beginners

Selenium IDE Tutorial:
To start our tutorials off, let’s start by introducing Selenium and what it’s good for as well as discuss one of the tools of the Selenium suite, the Selenium IDE.
The Selenium IDE is an excellent starting point to start using and learning Selenium. For a short description, the Selenium IDE is a plugin for the Firefox browser that let’s one click and record actions in the web browser. In addition, it adds options to your contextual menu (the right click menu) that helps you create tests. As a result, you can very quickly create and prototype scripts for automation.
To get started, head over to the Selenium homepage at http://seleniumhq.org and download the IDE (at the time of this writing, it’s located at http://release.seleniumhq.org/selenium-ide/1.10.0/selenium-ide-1.10.0.xpi). Remember that this is a Firefox plugin so it’s vital that you download and install it in Firefox.
Once you have it installed, start it up by hitting Tools -> Selenium IDE (Ctrl + Alt + S as a keyboard shortcut, if you’d prefer).









The IDE should come up so we’re well on our way to creating our first automated script using the IDE. For our first script, let’s pretend we’re working at Google and we want to make sure that when someone searches for something, their query remains in the search field on the results page. Before we get to creating our script, let’s familiarize ourselves with some of the basic functionality as well as the UI.






The parts that we really need to know right now:
1.       The Base URL field – This is where we put the URL of the web page that we want Selenium to start from. In our example case, we want to put http://www.google.com there.
2.       The controls – Right under the Base URL field, we have the controls. From the various buttons, sliders, and toggles here, we can control the execution of our test as well as whether or not we’re actively recording.
3.       The table – Here is where our script’s functionality will appear/live as we create it. We can also tweak our scripts and add additional commands if we desire.
For now, those are the 3 basic areas that we’re concerned about. We’ll revisit the other areas when we delve deeper in.
To start off automating our test case, let’s first navigate to http://www.google.com in Firefox and fire up the Selenium IDE if it’s not already open. If there are any commands in the table, highlight them and delete them for now.
Now, toggle on the record button (the red circle on the right hand side of the controls) and switch back to Google. From now on, all actions we take in the browser will be recorded by Selenium IDE!
As a reminder, our test is “When we search for a query on Google, the query string should remain on in the query field on the results page.
In the search field, let’s put in “SeleniumHQ” and hit enter. When the page finishes loading, right click the search field and select verifyValue.








Now let’s toggle off the recording button in the IDE and we’re finished! As you can see, all the actions we did have been recorded into the table to be played back at our convenience.








Now if you click on the click on the ‘Play Entire Suite’ button in the controls section, Selenium IDE will playback the exact steps as well as verify that the text is present! Congratulations on creating your first QA automation test! The ability to record and play actions using the Selenium IDE makes creating automated test cases just that simple. Even if you decide to not learn anymore about Selenium, you can still really power up your QA prowess using just the little bit that you’ve learnt here.

Using the IDE is that simple. By leveraging this tool, we can quickly create automated tests that allow us to save on tons of repeatable actions and time. However, we’ve only really just begun scratching the surface of the IDE. In our next installment, we’re going to show how you can customize the tests and create all sorts of advanced automated test cases. However, even though the Selenium IDE has an amazing amount of functionality, it pales in comparison to the other part of the Selenium testing suite, specifically Seleniumwebdriver. For example, the Selenium IDE is restricted to only Firefox, which as we all know, is not the only browser in town and it also lacks the ability to scale. So in additional to exploring advanced usage of the Selenium IDE, we’ll also explore how we can leverage the IDE to help supply test cases for SeleniumWebDriver, which doesn’t have the same shortcoming as the IDE.

Wednesday 28 August 2013

The Potential Differences Between HP QTP & Selenium

The IT sector is aware of the emergence of QuickTest Professional (QTP) & Selenium as the popular choice of testers & programmers for their test automation effort.
First of all let us have a quick overview of both the software testing tools, before going into a broad comparison among the functionality of the two.
1) Quick Overview – HP QTP:
QTPis automated testing tool meant for performing functional and regression testing of various software applications and environments through a user interface like native GUI or web interface. It uses VBScript as the scripting language for specifying a test procedure, & for manipulating the objects & controls of the AUT. It supports a keyword and a powerful graphical user interface.
2) Quick Overview – Selenium:
Selenium is an open source software-testing tool that had been developed by Jason Huggins & his team This is released under the Apache 2.0 license and can be downloaded and used without any charge. It provides a record / playback function for authoring the tests meant for web applications. It offers a test domain specific language (DSL) to write tests in many popular languages like C#, Java, Groovy, Perl, PHP, Python and Ruby etc. Selenium works on Windows, Linux, and Macintosh platforms. Many additional projects have emerged out of the parent Selenium like Selenium Grid Selenium IDE & Selenium Remote Control having different abilities that provide a boost to the parent Selenium.
Now let us make a broad comparison among the two tools
Sr.What HP QTP hasWhat Selenium has
1QTP is ideally suited for browser based testingSelenium too can very well do browser based testing
2QTP is licensed software & requires license costs that are quite a bit.Selenium is an open source tool that doesn’t cost anything
3QTP is quite easy to use. It is quite easy to edit the script, parameterize, navigate, playback & validate the results.For using Selenium one needs to have programming skills.
4QTP is quite easy to learn in a short time.Selenium needs quite a bit of expertise compared to QTP.
5QTP offers great benefit of the support for Business Process Testing.Selenium users don’t enjoy such benefits
6QTP comes powered with several add-ins by which user can comfortably work with Web, Windows, Java, dotNet applications simultaneously.Selenium users don’t enjoy such facility.
7QTP seamlessly integrates with QC and has excellent ability to automate non-web applications.Selenium is an excellent tool for purely web-based applications, especially when you don’t need QC.
8QTP works very well with database applications better than Selenium.With Selenium one needs to exert hard to do the same job.
9It is difficult to deploy smoke tests for web applications using QTP especially with Windows7.With Selenium these tasks can be easily accomplished.
10QTP uses VBscript as the only scripting languageSelenium provides a test domain specific language (DSL) to write tests in many popular programming languages, in addition to scripting with VB script
11QTP users find scripts written in VBscript more flexible & easy to manipulate & as such tool tends to be cost effective due to the availability of a full fledged support.Selenium users feel that the tool tends to be expensive due to lack of support & necessity of rewriting its scripts quite often
12Resource wise it is quite easy to find engineers having expertise on QTPSelenium Automation Engineer are bit scarce.
13With QTP we can easily generate most comprehensive reports due to the availability of an efficient online helpSelenium users don’t enjoy such luxury as enjoyed by QTP users
14Using a QTP framework needs less skills & everyone from a beginner to an expert can contribute in test creation to maintenanceSkill level expected in a Selenium Automation Engineer are a bit higher compared to QTP Automation Engineer
15QTP users don’t enjoy a freedom of scripting language & IDE like their counterparts using Selenium.For web based applications, development with Selenium is a wonderful experience since developer gets two benefits like;1) Scripting language of own choice2) IDE of Own choice.
16QTP is one of the best automation testing tool due to its unique features like Object Repositories, Object identification, Smart Identification etc in addition to its unmatched strength in database testing.Selenium certainly lacks such features packed in QTP.
Conclusion:
Our objective had not been to favor one at the cost of the second. It is a matter of convenience for the testers & programmers to select a tool that suits their requirements best.
Lastly both these tools have their own advantages & shortcomings, while it all depends upon the users who truly knows how to exploit them to their best advantage.

Tuesday 27 August 2013

Learn Selenium – Some useful tips

Learn Selenium – Some useful tips
Selenium is a Test Automation tool for Web Applications. Unlike QTP, TestComplete, or any other market leading commercial automation tools Selenium does not have a good IDE (Integrated Development Environment) for development of automation scripts. Unless having a good knowledge of a programming language such as Java or C#, it is very difficult to understand the way Selenium works although it looks very simple. One more point I want to make it very clear is that Selenium lacks a goodUser Guide since it is a open source tool. Of course, I agree that Selenium’s documentation is very good and comprehensive.  But it is a little difficult for the testing engineers who are newly learning automation concepts and lacking good programming skills.
After listening to many testers who want to learn Selenium, I wanted to provide some guidelines which will help learning Selenium.
Some of the very much popular questions I saw on Selenium forums are:
1.    I am very much new to Selenium, how I can Record and Playback scripts?
2.    I don’t know how to setup Selenium with Eclipse IDE?
3.    Is there any need to learn Java in order to automate test cases using Selenium?
4.    How to create Data driven framework for Selenium?
5.    How to use JUnit with Selenium?
Basically we need to understand some concepts before starting to use Selenium for automation.
1.    What is test automation?
2.    Why the Test Automation is needed?
3.    How a Functional Test Automation tool works?
4.    Which is the programming language / scripting technique used with the tool?
5.    What is programming skill and how can I improve my debugging skills?
6.    Does the tool support IDE or should we use some other IDE for development of automated test case?
According to me first and foremost thing which is needed for an automation tester is having good programming skills.
Practice makes man perfect” – write more and more programs that helps you to improve programming logic and debugging skills.
Before starting to learn Selenium, it is better to learn Java (or C#, Ruby, PHP, Python) and develop good debugging skills.  Debugging is nothing but executing the program step-by-step and find out the values of variables used in each step. Thereby find out the root cause of the issues (if any) with the program we have written.  This greatly helps a programmer or an automation tester. With Selenium, programming skill is very much important.
How to learn Java (or any programming that Selenium supports) and acquire debugging skills?
1.    Learn Java starting from “Hello World!!” program. Download Eclipse IDE and learn how to use it.
2.    Understand the data types, looping structures, flow controls (if else, switch case)
3.    Learn OOPS (Object Oriented Programming System)
4.    What is a class, object, and method? What is encapsulation? What is an access modifier?
5.    Inheritance, Polymorphism, Method overloading / overriding, constructors / destructors
6.    Learning exception handling is very important. Because whenever Selenium / Java throws any kind of exception we can easily understand why the exception is thrown and the type of exception.
When I mentioned all these concepts, don’t think that it is too much to learn. It is just Core Java. Only thing is we need to write a lot of programs which explain the concepts. Once these concepts are clear, then keep on writing / executing simple-to-complex programs and execute them step-by-step. Watch the variables during the execution to enhance debugging skills.
What next?
1.    Download and install Selenium IDE
2.    Download some open source web application (Google and find out some open source web application, there are many on the internet)
3.    We can even utilize some of the web sites online (such as any technology forums) which contain all different types of objects (edit boxes, tables, drop downs, radio buttons, check boxes, etc)
4.    Record some test scenarios and try to play back step-by-step (click and run each step on the IDE, otherwise there is a chance that you might not be able to execute the entire script because of the application loading time)
5.    Once you are comfortable with Selenium IDE and the APIs, then try to export them and save to some notepad.
6.    Go through the code.
All these steps look tedious but it is very easy to follow, it does not even take a week’s time. Once these are done, download Selenium-Java-Client driver and integrate that with Eclipse IDE.  Now, you can straight away export all the scripts recorded so far to Eclipse IDE and execute them.


Advaced Selenium IDE Usage Tutorial


Advaced  Selenium IDE Usage Tutorial

As a followup to our last post, Selenium IDE Tutorial, we’re going to explore how to create some advanced tests utilizing the IDE. We currently have a test where we go to Google and search for SeleniumHQ. After we search for SeleniumHQ,  we verify that the query for SeleniumHQ is still present in the search field. Let’s modify our test case so that we can verify that ANY query will have the same result. That is to say, regardless of what we search, the query should still be in the search text field. To do this, we’re going to use the popular programming language JavaScript to help us add some custom functionality as well as some Selenium IDE commands that we haven’t come across yet.
Instead of making a brand new test, let’s modify the one we made from the previous example. (The following screenshot actually has 1 extra step where we click the search button. See if you can figure out how to do it!)
We need to be able to search for any term, not just SeleniumHQ. Let’s break down what we need to modify in order to make this test robust.
1.       We need some way to store this new query.
2.       We need some way to create this new query.
3.       We need some way to retrieve this new query.
In our case, our new query is going to be something that is different every time we run this test. Let’s tackle our problems one by one.
Storing a new query
To store a new query, we actually need to use a new Selenium IDE command. This command is called ‘store’ and it works a little differently then the other commands that we’ve used so far.
First, let’s add the store command to our test case. To do this, right-click the open command to bring up the context menu and click Insert New Command. A new blank command should appear above the open command. Now click the blank command and in the ‘Command’ argument field under the test case table, type store (it should auto suggest the store command as you type so you can also click that). In the value field, let’s type the word ‘query’. This tells the ‘store’ command that we’re going to name a variable (a variable is a container for data) searchQuery. We need this later when we retrieve the query.
Creating a new query

Now that we have a command to store a variable, we’re need to create the searchQuery. We do this using JavaScript. JavaScript is one of the most popular web programming it is and it’s immensely helpful as a QA Engineer to be familiar with it. We’re going to get our first taste on why it’s useful for a QA Engineer to understand and know JavaScript right now.
In the ‘store’ command in the IDE, we’re need to actually create the value to store. So in the ‘Target’ text field, we’re going to type the following:
javascript{“Test” + Math.floor(Math.random() * 100);}
What this tells Selenium IDE is run this following bit of JavaScript code and store it in the searchQuery variable.
Our JavaScript snippet creates a random phrase which is composed of the word Test and a random number from 0-99. If we wanted to search for something different, we’re have to change the JavaScript code (feel free to do so! This is just a simple example of how we can use JavaScript in Selenium IDE).
Now our ‘store’ command will create a query and store it inside the searchQuery variable.
Retrieving the new query
This where we edit our old test command. To retrieve the value, all we need to do is wrap the searchQuery value in between two brackets with a dollar sign in front, like this: ${searchQuery}. This tells the Selenium IDE to use the value of whatever searchQuery ends up being. Let’s modify our ‘type’ and ‘verifyValue’ commands to accept this. Delete the current SeleniumHQ value and replace it with ${searchQuery}.
We’re all done! Now, run the test by clicking Play entire test suite and it should pass as before (unless Google is broken!). Run it again and again and again, and each time, the searchQuery will be different!
Congratulations, we’ve taken a very specific and simple automated test and added a lot of functionality to it. Now, we can be sure that any term will still pass and not just a single term like SeleniumHQ, which is a stronger test case then we had previously. I encourage you to experiment with other commands in the Selenium IDE to start off your automated testing journey, especially if you’re currently in QA and are only doing manual testing. Not only will you improve your productivity, but you’ll improve your testing skills and breadth of knowledge.
If you’d like to learn more about JavaScript, there are many resources on the web available. One of my favorites is Eloquent JavaScript if you want to learn more about the language itself. It’s definitely a very valuable and desirable skill set to know and understand JavaScript if you’re working on the web.

In our next installment, we’re going to show how we can use even more features of the Selenium IDE to build WebDriver tests. We will also build our first WebDriver test and learn the differences between Selenium IDE and Selenium WebDriver using first hand experience.