Keyword-driven Automated Testing

May 16th, 2010 § 5 comments

Is it really possible for non-programmers to create automated tests?

Keyword-driven test design is a popular approach in testing teams in big corporations, where the skill levels of QA people are vastly different and most of them are not programmers. The problem of QA managers in such organizations who want to invest in test automation is how to best utilize their available resources. I think that now almost everyone realizes that capture and replay tools fail to create useful and reliable tests, so another approach is needed.

Keyword-driven frameworks rely on a library of small standalone reusable and parametrized building blocks, that represent simple and atomic actions of the application under test. Those are usually developed in a scripting language by the test automation developers. Then those building blocks (or keywords) can be used in some graphical or table-driven interface as reusable actions by testers to create automation without coding. In a way this is very similar to the action-word scripting approach that most automation tools provide (like QTP or the table view in the Selenium IDE).  The difference is that the keywords that the testing tools provide out of the box (usually things like 'click_button' and 'type' are both very generic (in the sense that they can be used in any application) and very narrow (in the sense that they do very small things like clicking a web button or typing text in a textbox). The successful keyword-driven approach requires keywords that are defined in the semantic level of the tested application (like for example 'login' or 'register_user').

Here is a quote from my favorite testing book
Lessons Learned in Software Testing: A Context-Driven Approach

“In contexts that require many nonprogrammers to create automated tests, we believe this is one of the better solutions One drawback of this approach is that you can't write a test unless supported keywords already exist for the tasks you require. Defining and implementing the task functions can become a major undertaking.”

You can build such a framework in-house, using for example excel tables to contain the test scripts with  the keywords and their parameters, or try to use the keyword capabilities of some of the commercial tools on the market (like the reusable actions in QTP). JSystem is an open source test automation framework oriented towards API testing that can also interface with Selenium for creating  keyword-driven UI tests.

While keyword-driven sounds wonderful, it is not a magical methodology that will solve all automation problems and cure world hunger.  I worked on a keyword-driven project while I was an employee of a big corporation. We had an elaborate in-house tool, that could compose the keywords into larger blocks of actions, which were also reusable in tests. The project was a failure. The library of keywords became so huge that no one could figure out which keyword should be used in which context. The tool did not have control flow mechanisms. You could not do loops or if-then-else constructs, which  meant only very simple straightforward test scenarios were possible. The tests were breaking too often and the maintenance effort was higher in my opinion, compared with traditional scripting automation (if done well).

I would like to hear from you about your experiences with keyword-driven automation.

The Hidden Firefox Profile in Selenium RC Server

May 5th, 2010 § 3 comments

Image (c) Arthur Caranta (Arthur40A)

You might not know that Selenium provides a feature which allows you to capture the network traffic during a test. This might be handy in some cases - for example if you want to check the HTTP response headers returned by the server for some reason or to verify that a specific HTTP request is triggered during a test. I use it for example to verify that a web analytics request is properly triggered on a particular web page.
To use this feature you must start your tests by providing a special option to the start method, i.e.  selenium.start("captureNetworkTraffic=true");

Another useful Selenium feature I use is the ability to start the RC server by providing a specific Firefox profile for running the tests. Your normal Firefox settings are not used when running tests in *chrome mode. If you want to have a specific Firefox plugin active, or if for example you must use a proxy to access the tested pages, you have to use the -firefoxProfileTemplate setting when starting the Selenium server and provide the path to a custom Firefox profile folder that contains all the settings and plugins you want to use.

The problem is that those two features do not work together - when I use the captureNetworkTraffic=true option, I always get some generic Firefox profile and not the one I provide in the firefoxProfileTemplate parameter.

Here is my workaround for this problem. It turns out that inside the Selenium RC server jar there is a folder called customProfileDirCUSTFFCHROME, which contains the small generic firefox profile, used in this case and probably also in the case when you don't provide a custom Firefox profile.

If you want to capture the network traffic and still use a custom Firefox profile,  here  is how you can hack your selenium-server.jar to include a  custom profile.

  • Extract the customProfileDirCUSTFFCHROME folder from selenium-server.jar
  • Close all Firefox processes. Start Firefox with the -profilemanager option.
  • Choose 'Create Profile' from the dialog that appears, click 'Choose Folder' and select the folder extracted  from the jar file.This way you will use the profile provided by selenium as a starting point. You can then make configuration changes, add plugins etc.
  • When you exit firefox, pack all the changed files from the extracted profile folder back into the jar file. Now selenium will always use your custom profile

I tested this with Selenium 1.0.3. Works like a charm.

Selenium RC 1.0.3 – To Upgrade Or Not

March 16th, 2010 § no comments yet

Image (c) George Rex


Having used the 1.0.3 version of Selenium RC for several weeks  I now have an overall impression of the new release. The thing that bugged me most was that the upgrade was not as smooth as I hoped  - several tests that previously worked fine with 1.0.1  started to fail with 1.0.3.  We were able to relatively quickly  find workarounds for what seem to be bugs introduced in the new release. Here are two links to the Selenium issue database  in case you run into the same or similar problems - 400 and 408; look for 'XHR ERROR' exceptions in your logs when opening URLs.

With the workarounds our tests became as stable as before – not better and not worse. The new version did not really bring any noticeable improvements for me – I have not yet moved to Firefox 3.6 and I am not a Mac user. So my advise would be – If you have your tests running smoothly on 1.0.1 and you don't need Snow Leopard and/or FF 3.6 support yet, don't bother upgrading for now.  There might be a new release on the horizon.

New Selenium RC Release

February 24th, 2010 § no comments yet

Actually for the last two days there were two new releases of Selenium - 1.0.2 and 1.0.3 (released on the next day following 1.0.2 to fix some issues). The most important feature in the new release for me is Firefox 3.6 support. If you are a Mac fan you will be glad to know that OS X Snow Leopard is now supported too.

When it comes to  tools I use for work I usually prefer to wait a little before upgrading, so that any potential problems that might be there are discovered by other people and not by me (the quick release of 1.0.3 seems to confirm that this is actually a good idea). On the other hand my previous experience with upgrading test automation tools shows that I sometimes run into problems no one else has found.

So this time I decided to upgrade to 1.0.3 early and I will blog about my experience.

By the way, there is also a new official Selenium blog.

Test Selenium XPath Expressions Directly in Firefox

January 17th, 2010 § no comments yet

XPather is a small Firefox extension, which I find indispensable (together with Firebug) when writing Selenium tests.

It adds a 'Show in Xpather...' item to the context menu for all the UI elements on the web page. When selected this option opens a small 'XPather Browser' window showing a very, very long XPath expression which selects the element you chose.

Like /html/body/table[2]/tbody/tr[2]/td[2]/div[@id='login']/form[@id='gaia_loginform']/div[@id='gaia_loginbox']/table/tbody/tr/td/div/table[@id='gaia_table']/tbody/tr[8]/td[2]/input, which is the expression you get when you select the 'Sign in' button on the login page of Gmail. Of course you can write your own expressions and test to see what is selected on  the page.  So you can opt to use for example //input[@name='signIn'], which is much shorter and better way to locate the same button. I use XPather mostly to interactively test complex expressions whenever I am trying to locate some hard-to-find object on the web page.

Five Reasons Why I Like Selenium

December 25th, 2009 § 1 comment

Several months ago I started working on a new test automation project for a web site and one of the first things to do was to evaluate and choose a tool for the task. The two main contenders were Selenium and IBM Rational Functional Tester. I chose Selenium and since then never got to regret this choice. Here are some of the main reasons I lke this opensource tool much better than the expensive commerial alternatives for web automation:

Selenium acknowledges the fact that to create useful tests you will have to code them

Yes, it gives you a tool that can record sequences of user interactions, but as a whole Selenium is not built with the assumption that this will be the main approach you will use to create your tests. The recording tool (which is a very easy to install Firefox plugin) is useful as a learning aid and maybe for very simple tests. But what I like most about it is that it can covert your recorded sequence to code in any of the supported scripting languages.  And this brings me to the second point:

You get to choose the scripting language

Most commercial automation tools force you to use some Visual Basic dialect as a scripting language. If you are lucky you get something relatively functional like VBA (with TestPartner) or even VB.NET (with Rational Functional Tester). Otherwise you might be forced to code your tests in VBScript, which is really, really painful (the main reason why I don't like QuickTest Professional). Rational Functional Tester also lets you use Java, which makes it my favorite among the commercial tools.

Selenium is language-agnostic. You can use almost any programming language you want. C# and Java are popular and PHP is also an option if you are automating a PHP web app and want to stick to the same language for testing. Ruby is a great language that makes coding fun and the Selenium library for Ruby provides some domain-specific idioms for testing, similar to what Rails does for web development. If you are a Perl, Python or Groovy fan you can use them too. As an additional bonus you will be able to use any development environment you are comfortable with to write your scripts – be it Eclipse, Microsoft Visual Studio or even Vi or Emacs if you want to.

Selenium has a powerful approach for locating UI objects

Most automation tools are surprisingly limited in the way they identify the UI objects to interact with. They let you locate a control by some unique property (like id) or by a collection of properties which together identify it uniquely on the web page. In my experience this approach is sufficient in only about half of the real-world cases.

Imagine a web page containing 3 identical OK buttons. The buttons are exactly the same and have no id's or anything in their properties to distinguish them. Lets say that the first button is located in a form with id 'signup', the second is inside 'order' and the third is inside 'invoice'. Most automation tools do not let you easily identify a UI object in relation to other objects in the page, i.e. you can not say I want to click the button with caption 'OK', which is located inside the 'signup' form. Normally the most you get is I want to click the second button with caption 'OK' on the page. This will work, but only until you get a new version of your application with added additional OK button above the one you are interested in. The XPath expressions in Selenium can locate objects in the DOM document hierarchy (“//form[@id='signup']//input[@type='button' and @value='OK']”) and are very powerful – for instance you can specify that you want to click the checkbox, which is located inside a table row next to a cell with some specific text in it.

Your tests will run on any browser without changes (well, almost)

While you should not expect that automated tests will catch most browser-dependent bugs (like broken layout), the option to run your tests on all browsers that you support is definitely useful. As with programming languages, Selenium offers you a wide choice of browers to run your tests on – not only specific versions of IE and maybe Firefox (the choice you are likely to get from commercial test automation tools), but also Safari, Chrome and Opera. What is more important – about 95% of your tests will run without any changes on all supported browsers. I don't know other automation tool that does this.

It is surprisingly stable and robust for a 1.0 version

My experience with test automation is that if you want to run lots of long tests, you have to expect that something will go wrong at some point – random crashes are not that uncommon in this business. Selenium is at least as stable as anything else I have tried and we routinely run hour-long tests without any problems.

Selecting Unnamed Pop-up Windows in Selenium

October 8th, 2009 § 3 comments

If the application you are testing tends to open new browser windows using the target="_blank" technique, you might have some problems with Selenium.

One of the reasons I find Selenium a great test automation tool for the web  is that it lets you easily run your test scripts on different browsers without too much effort. Most scripts will run smoothly on IE, Firefox and even on more exotic browsers like Safari, Opera and Chrome without needing browser-specific code or having to tweak the test for a particular browser.  One of the few areas where you are likely to face problems is the handling of pop-up windows.  If the application you are testing tends to open new browser windows using the target="_blank" technique, you might have some problems with Selenium. The standard .selectWindow() method provided by Selenium requires either a title of the pop-up window (which is often the same as the title of the main window) or a name or a variable name (which are both missing, when the window is opened using a target="_blank" link).

You will need a workaround to select such windows and unfortunately the workarounds do not always work the same for all browsers. The following code snippets might be useful if you run into the same problem. They are tested on the *chrome and *iehta Selenium modes (with Internet Explorer 7 and Firefox 3).

Here is how you can select the pop-up window which is opened after a target="_blank" link is clicked. This actually combines several hacks and workarounds, but works at the end (at least for me):

        //A hack to select unnamed pop-up windows
        if (browser.equals("*iehta")){
            //Find out if Selenium substituted the blank target...
            if (selenium.isElementPresent(
                       "//a[starts-with(@target,'selenium_blank')]")) {
                // ...and make it notice the new window on IE
                selenium.openWindow("", selenium.getAttribute(
                      "//a[starts-with(@target,'selenium_blank')]@target"));
            }
        }
        String [] winNames = selenium.getAllWindowNames();
        //the last one is the pop-up window we want
        selenium.waitForPopUp(winNames[winNames.length-1], timeout);
        selenium.selectWindow(winNames[winNames.length-1]);

And here is how you can go back to the main window after you finished working with the pop-up:

        String [] winTitles = selenium.getAllWindowTitles();
        selenium.selectWindow(winTitles[0]);

The Forrester Wave™ – Functional Testing Solutions

April 11th, 2009 § no comments yet

Opensource might actually be better.

waveIn case you are in the process of evaluating test tools, this review by Forrester research might give you a good initial overview of the current commercial offerings - The Forrester Wave™: Functional Testing Solutions, Q3 2008

It looks at solutions that support the whole testing and quality management process and the conclusion is not surprising:

"In today's market, HP is the default choice"

I find the whole thing objective and if you read it carefully you will be able to find the key facts about the automation tools.
The evaluated vendors and the corresponding tools are HP (ex Mercury) with QuickTest Professional, IBM (ex Rational) with Rational Functional Tester, Compuware with TestPartner, Borland (ex Segue) with SilkTest plus also tools from Empirix and Seapine.

The review has its main emphasis on test management and not on test automation:

"Testing teams looking to purchase just a single product should focus on test management first, since mature practices in this area are a prerequisite for success with test automation."

While this sounds logical at first, I somehow can not agree with it entirely. But what follows is really interesting:

"There are exceptions, though: most notably, development teams looking to automate their own regression testing. Commercial test automation tools, however, tend to be less effective here than open source alternatives like FIT/FitNesse or Selenium."

and:

"Both open source testing tools and SOA testing tools are relatively small parts of the functional testing tools market, but they’re growing in importance. Why? Because iterative development methodologies demand that test automation start earlier in the life cycle, and the testing organizations that purchase commercial tools struggle to make this a reality."

It seems that the analysts that wrote this really have some insignt in the business. Overall it is a very interesting read. Did you know that the element Selenium is the antidote to Mercury poisoning?

Where Am I?

You are currently browsing entries tagged with Selenium at Test Automation Blog.