Wednesday, 4 September 2013

Selenium 1 (Selenium RC) Overview

Introduction
As you can read in brief history of selenium project, Selenium RC was the main Selenium project for a long time, before the WebDriver/Selenium merge brought up Selenium 2, the newest and more powerful tool.
Selenium 1 is still actively supported (mostly in maintenance mode) and provides some features that may not be available in Selenium 2 for a while, including support for several languages (Java, Javascript, Ruby, PHP, Python, Perl and C#) and support for almost every browser out there.
How Selenium RC Works
First, we will describe how the components of Selenium RC operate and the role each plays in running your test scripts.
RC Components
Selenium RC components are:
  • The Selenium Server which launches and kills browsers, interprets and runs the Selenese commands passed from the test program, and acts as an HTTP proxy, intercepting and verifying HTTP messages passed between the browser and the AUT.
  • Client libraries which provide the interface between each programming language and the Selenium RC Server.
Here is a simplified architecture diagram....



The diagram shows the client libraries communicate with the Server passing each Selenium command for execution. Then the server passes the Selenium command to the browser using Selenium-Core JavaScript commands. The browser, using its JavaScript interpreter, executes the Selenium command. This runs the Selenese action or verification you specified in your test script.

Thursday, 29 August 2013

Selenium IDE Tutorial

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.



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.

Why learn Selenium and Automation for Software Quality Assurance

The practice of Quality Assurance is evolving with technology. As websites get more and more complex, testing strategies, tools, and practices need to grow along side. Chances are, if you’re reading this, you’re someone either in the QA field or somehow involved with QA  and have an interesting in learning more about website automation, specifically the very popular Selenium testing tool. Maybe you’re thinking of enhancing you or your department’s skill set. Before we divulge into the specifics of Selenium, let’s understand why we should learn about it in the first place.
Pretend you’re working for an eCommerce site that sells technical books. Development has decided to implement a new feature in the registration process that validates email addresses – that is to say, it verifies that email addresses are real enough. Let’s say that when the user enters their email in the form, a little check appears if it’s a valid email. This is an example of how manual QA would work.
  1. QA gets the new feature
  2. QA tests the feature
  • They fill out the form with a valid email address
  • They fill out the form with an invalid email address
  • They fill out the form with international characters
  • They attempt SQL injections
  • They attempt to run arbitrary code
  • And other various tests
  1. QA approves the feature and it gets deployed to production!
Say this takes an hour. That’s not bad right? But let’s not forget we’re talking about the web, in which case we need to support multiple browsers and environments. So that hour now becomes four hours.
That’s still kind of okay, it’s not exactly forever. However, there’s two major problems with this scenario. We’re assuming a perfect build.
  1. If something is wrong and development needs to implement a fix, QA has to redo everything. This means they have to repeat every single test that they had done before. This is very time consuming (and can be quite boring).
  2. In the future, they might have to test this same functionality again, even if new changes may or may not be directly related. This is also very time consuming, multiplied by the fact that some systems and changes are very complex.
The answer to these problems lies in automation. If tests are automated, they can be redone quicker and at a lower cost (in time, effort, brain power). If we automated the previous scenario, we could severely boost QA’s efficiency. For example, we could be running every single browser doing the same tests in parallel, effectively multiplying our QA work force. Automation really provides a level of testing that is untouchable by manual processes. By using the best tools, QA becomes a vital and useful asset to any website or product.
Now let’s explore a little bit of background on Selenium. Selenium is the de facto tool in website browser automation. By spawning up actual browser instances, Selenium offers the closest experience to a live user on the site and allows automation to give the greatest analysis. Selenium is also supported actively by many programming languages so it’d fit right into any tech stack or skill set. In addition, there’s many libraries and tools that integrate right with Selenium to really power up automated testing. By leveraging Selenium and automation, QA can provide real quality value to a product and team.