Test Automation for Web Applications using Selenium 2

Posted by batman on Apr 18th, 2011
2011
Apr 18

Test Automation for Web Applications

Many, perhaps most, software applications today are written as web-based applications to be run in an Internet browser. The effectiveness of testing these applications varies widely among companies and organizations. In an era of highly interactive and responsive software processes where many organizations are using some form of Agile methodology, test automation is frequently becoming a requirement for software projects. Test automation is often the answer. Test automation means using a software tool to run repeatable tests against the application to be tested. For regression testing this provides that responsiveness. There are many advantages to test automation. Most are related to the repeatability of the tests and the speed at which the tests can be executed. There are a number of commercial and open source tools available for assisting with the development of test automation. Selenium is possibly the most widely-used open source solution.

Introducing Selenium

Selenium is set of different software tools each with a different approach to supporting test automation. Most Selenium QA Engineers focus on the one or two tools that most meet the needs of their project, however learning all the tools will give you many different options for approaching different test automation problems. The entire suite of tools results in a rich set of testing functions specifically geared to the needs of testing of web applications of all types. These operations are highly flexible, allowing many options for locating UI elements and comparing expected test results against actual application behavior.

Selenium’s Tool Suite

Selenium is composed of multiple software tools. Each has a specific role.

Selenium 2 (aka. Selenium Webdriver)

Selenium 2 is the future direction of the project and the newest addition to the Selenium toolkit. This brand new automation tool provides all sorts of awesome features, including a more cohesive and object oriented API as well as an answer to the limitations of the old implementation.

Selenium 1 (aka. Selenium RC or Remote Control)

As you can read in Brief History of The 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, PRuby, HP, Python, Perl and C#) and support for almost every browser out there.

Selenium IDE

Selenium IDE (Integrated Development Environment) is a prototyping tool for building test scripts. It is a Firefox plugin and provides an easy-to-use interface for developing automated tests. Selenium IDE has a recording feature, which records user actions as they are performed and then exports them as a reusable script in one of many programming languages that can be later executed.

Selenium-Grid

Selenium-Grid allows the Selenium RC solution to scale for large test suites and for test suites that must be run in multiple environments. Selenium Grid allows you to run your tests in parallel, that is, different tests can be run at the same time on different remote machines.

An example using Selenium 2, Java and JUnit4

Download Selenium

Create a Java Project

  • Create a Java project using your favourite IDE – I’m using Netbeans 6.9.1, JDK 1.6 and JUnit 4
  • Add selenium-server-standalone-2.0b3.jar to your project classpath.

Create a Unit Test

public class GoogleTest {

    @Test
    public void test() throws Exception {

        WebDriver driver = new FirefoxDriver();

        driver.get("http://www.google.com");
        Assert.assertEquals("Google", driver.getTitle());

        WebElement element = driver.findElement(By.name("q"));
        element.sendKeys("Wikipedia");
        element.submit();
        Assert.assertEquals("Google", driver.getTitle());

        driver.quit();
    }
}
  • Here I am using Java to test a website written in PHP – the website language is actually irrelevant as it is basically html
  • There are of course benefits to having the selenium tests as part of the actual project (test driven development – TDD)
  • It’s comforting to use the visual FirefoxDriver(), but it is slower. For faster performance, use the HtmlUnitDriver() for in-memory testing
  • It really is this easy – try it 🙂

References

Selenium Website

Selenium Documentation

Powered by Zoundry Raven

Technorati : , , ,
Del.icio.us : , , ,
Zooomr : , , ,
Flickr : , , ,

Share and Enjoy:
  • Facebook
  • Twitter
  • Digg
  • StumbleUpon
  • del.icio.us
  • Yahoo! Buzz
  • Google Bookmarks
  • LinkedIn
  • MySpace
  • laaik.it
  • Google Buzz
  • Technorati
  • Slashdot
  • Reddit

My PC Software

Posted by batman on Feb 27th, 2010
2010
Feb 27

I have compiled a list of programs and software I use on my home PC. It isn’t intended to represent a survey, or exhaustive study of the “best-of-breed” – rather just stuff that I have found, and that work for me. I have no doubt that there are many, many other programs out there that are better than what I’ve got, but my setup does what I need it to. Hopefully it will help you with yours 🙂

Operating System

While I am a Linux person by nature, it just makes more sense to run Windows XP at home. The kids are always wanting to plug in MP3 players, or watching video clips, playing online games (with flash) – and inevitably on Linux one generally needs to spend some configuration time before it works. With Windows – unfortunately – it often just works.

Web Browser

Ok, this one is a no-brainer. Mozilla’s Firefox wins hands down, simply for the way it consistently outperforms Internet Explorer as far as new features, security and lack of vulnerabilities are concerned. No further discussion is even required.

Password Manager

I use Gorilla Password Manager to maintain and protect all of my passwords. It is freely available, open-source and best of all – cross platform. This means that one common password file can be re-used across Windows, Mac OS X, Linux, Solaris and *BSD operating systems. The “Twofish” encryption algorithm is used to secure your password database, and it is not possible to break into it without having the master password. It allows me to store a multitude of login details and passwords, in a hierarchical structure, and allows me to generate seriously secure passwords for sensitive sites. Good luck tring to crack my password of Gj_)bGF5$,!l:;@#jhsTg*(-+

Backups

I use Corbian Backup to backup my valuable data. It is freely available and does everything I need it to do. I can create several tasks, include files and folders and package them in a zip file in a specified folder or folder. I can schedule them to run automatically, so that perhaps my only responsibility is to backup this Corbian folder to DVD or secondary harddisk as and when I deem it necessary. It is highly customizable and would certainly perform as well as – if not better – than many commercial products on a scale much larger than my home PC.

Anti-Virus

AVG is one of the most widely used free virus protection utilities out there. Although in this case there are many other competitors, and in some cases, or as argued by some people, many of them superior to AVG. Touch wood, no virus has yet caused me damage, and AVG has picked up a few. This is one of those cases where commercial products will actually offer vastly superior protection – it just depends on how much you’re prepared to spend.

Desktop Blogging

I am a big fan of Zoundry Raven for creating, editing and publishing blog articles to several blogs. It has a true WYSIWYG editor that is really simple and straightforward to use. Zoundry supports a whole host of destination blog types – I use WordPress, and it works flawlesly. Admittedly I am not a super-blogger, but it certainly does everything I need it to do, and certainly beats having to edit articles “online” – using one of WordPress (or other) built-in editor. The edit-local and publish model just makes so much more sense than the online-edit model.

File Manager/Transfer Clients

  • FileZilla is a simple but effective ftp client that does everything I need it to. As with many of the software on this page, there are many others that will perform equally, if not better. For me – if it works – it’s good enough.
  • WinSCP is a Windows implementation of the *nix function SCP (Secure Copy). It has an awesome amount of features, and one can do almost anything with it. It allows me to easily communicate with my Linux Ubuntu installation, running as a virtual server
  • FreeCommander is an alternative to Windows Explorer. While Windows Explorer does pretty much everything FreeCommander can, FreeCommander offers its functionality with a different interface, and I just prefer using it. It strongly mirrors the two-panel interface of the old blue Norton Commander, or of late, the *nix Midnight Commander (mc as it is better known). F5 means copy, F8 means delete – I just feel at home using it.

Other

  • JRuler is a handy little screen measuring utility – it offers a ruler calibrated in pixels, mm or cm (if my memory serves me correctly). I use it a lot for web page design, when one wants an indication of how big something must be, without the rigour of “trial-and-error”. Very simple, but effective – it does what it was designed to do.

Virtualization

I use VMWare Server– a free option ideally suited to a home pc. The limitations are by no means limiting, as I could run several virtual servers, can configure all of them and allocate resources to my heart’s content.

VM: Ubuntu – KDE

My distro of choice will always be Debian-based – the “apt” method of installation is seamless and reliable, and makes installations a walk in the park. Updates of packages as well as distribution upgrades are really childsplay – the single provisio is that you need a good internet connection. My personal distro of choice is Ubuntu, or rather Kubuntu (Ubuntu + KDE)

VM: Web Content Filtering

Dans Guardian wins this one hands-down for me – to the point of running a linux server whose sole purpose is to provide this capability to my Windows OS. It is extremely powerful and configurable, although out of the box works just fine. I am quite comfortable letting my children aged under 10 loose on the Internet without supervision, knowing that Uncle Dan is keeping an eye out for them. This is one of my Killer Apps, and nothing else on Windows comes even close.

VM: Source Version Control

Even though CVS is aged and improved on by many products these days, it nonetheless still does everything I need from it, and it does it well. I have no need to upgrade, or look for anything more.

Share and Enjoy:
  • Facebook
  • Twitter
  • Digg
  • StumbleUpon
  • del.icio.us
  • Yahoo! Buzz
  • Google Bookmarks
  • LinkedIn
  • MySpace
  • laaik.it
  • Google Buzz
  • Technorati
  • Slashdot
  • Reddit