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.

How do you test your web services?

December 12th, 2009 § 1 comment

Service oriented architecture is not something new or cool anymore. From enterprise software to web sites, software exposing its functionality via web services is becoming increasingly common.
The question is how to test those services. One option is to use a unit testing framework and create tests calling the services in any programming language you are familiar with (Java + Junit, C# + Nunit, etc). Whether such tests can be called unit, functional or even integration tests is not that important, but this approach is probably best suited for developers creating tests themselves. It is also not quite convenient for ad-hoc or exploratory testing.
A lot of commercial Java application servers such as SAP NetWeaver provide built-in web-based tools for browsing and testing the deployed services on the server. Using such tool is a good option for ad-hoc testing, because usually the services are readily accessible in it without any need for additional configuration. If you don't have access to something like this or if you need more flexibility, like maybe saving the test parameters and creating whole test suites, you might want to look at SoapUI. This is a tool for web service testing that has a free (open source) version and a commercial 'Pro' version with additional features. The most useful 'pro' feature for me is the form-based interface for entering the input parameters for the service call. SoapUI allows you to create whole scenarios consisting of services called in sequence and exchanging data between them. It even has some performance / load testing features.
SoapUI seems to be the most popular tool for web service testing, but it has its quirks and is not always as robust as I would like it to be.  I am curious if  anyone knows something better out there.

Windows 7 Automation API Available on Vista and Server 2008

October 31st, 2009 § no comments yet

Windows-Automation

Right after the recent release of Windows 7 Microsoft also released a platform update for Windows Vista and Windows Server 2008. The update brings in some of the new technologies from Windows 7 to those operating systems. Besides 'Windows Graphics, Imaging, and XPS Library' (which  actually gives you  new DirectX), 'Windows Portable Devices Platform' and 'Windows Ribbon and Animation Manager Library' (I hate the ribbon interface), the update also includes something called 'Windows Automation API', which "enables accessibility tools and test automations to access the Windows user interface in a consistent way across operating system versions"
Since Active Accessibility Microsoft has been providing programmatic interfaces for UI automation in Windows.  So if you are starting a Windows automation project, think about using this approach.  You can script with the Automation API in any of Microsoft's programming languages (Visual Basic, C# and even C++)  even with the free Express Editions of Visual Studio. This will not only be a really cost efficient approach, compared with the prices of automation tools like QTP or RFT, but probably will produce results which are more stable too.  After all this is the technology Microsoft uses to create UI tests for their own applications.

Selecting Unnamed Pop-up Windows in Selenium

October 8th, 2009 § 2 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]);

TestPartner Review – Final

October 4th, 2009 § 2 comments

...use Window.TextSelect if you can not identify something

Review

This is the final part of my hands-on review of TestPartner. Here I will try to demonstrate the old-style Visual Basic scripting approach, which I find to be more reliable.   I will again use my GMail scenario.

As I mentioned before, the only place I find recording useful is in such cases when you want to get to know how the tool ‘sees’ the UI.  I have no experience with the UI of GMail,  so I tried to record the scenario first.

This is the script that I got:

Sub Main()
 
' Begin record on Monday, 13. September 2009 at
' 11:17:07 by Admin
 
    ' Attach to Gmail Email from Google -
    ' Microsoft Internet Explorer IEWindow
    IEWindow("Gmail Email from Google - IEWindow").Attach
 
    ' Attach to Caption='Gmail: Email from
    ' Google'
    HTMLBrowser("Caption='Gmail: Email from Google'").Attach
        HTMLEditBox("Name=Email").SetText "testautomationblog"
        HTMLEditBox("Name=Passwd").SetPasswordText "***"
        HTMLButton("Name=signIn").Click
 
    ' Attach to Gmail - Inbox (2) -
    ' testautomationblog@gmailcom - Microsoft
    ' Internet Explorer IEWindow
    IEWindow("Gmail - Inbox (2) - IEWindow").Attach
 
    ' Attach to Name=cgudh0fxq7w2n
    HTMLFrame("Name=cgudh0fxq7w2n").Attach
        HTMLSpan("ID=':r3'").Click 43, 12
 
    ' Attach to Gmail - Compose Mail -
    ' testautomationblog@gmailcom - Microsoft
    ' Internet Explorer IEWindow
    IEWindow("Gmail - Compose Mail - IEWindow").Attach
 
    ' Attach to ID=':kl'
    HTMLFrame("ID=':kl'").Attach
        HTMLFrame("ID=':kl'").Click 33, 19
        HTMLFrame.Type "Lorem Ipsum Dolor"
 
    ' Attach to Name=cgudh0fxq7w2n
    HTMLFrame("Name=cgudh0fxq7w2n").Attach
        HTMLImage("ID=':ia'").Click
        HTMLDiv("ID='' Index=589").Click 48, 7
        HTMLAnchor("Caption='Drafts (1)'").Click
        HTMLSpan("ID='' Index=38").MouseDown 42, 7
        HTMLDiv("ID='' Index=702").MouseUp 358, 25
        HTMLDiv("ID='' Index=733").Click 35, 12
        HTMLAnchor("Caption='Sign out'").Click
 
' End record on Monday, 13. September 2009 at
' 11:18:22 by Admin
 
End Sub

As I expected, the recorded script could not be run successfully at all.  So what is wrong with it?

The recording has used two ways of addressing the controls. The first one is used with controls that TestPartner attaches to, those seem to be the controls it sees as more important,  for example see line 12. Those controls are identified using something called object maps. The object maps are artifacts that represent definitions of UI controls. When you access a control in a script via an object map, you provide only the name of the map. The actual properties used to identify the control are stored in the map itself. This is the definition of the object map from line 12:

object_map

Basically this says that the window we are interested in is an Internet Explorer window with a caption 'Gmail: Email from Google - Microsoft Internet Explorer'. The idea of object maps is that they try to separate how controls are identified from the test logic. If something changes in some particular control, you will have to modify only the relevant object map, but not the script itself.    This looks like a nice idea, but I found that in practice it does not always work that well.

The second way of addressing controls is called 'Raw attach names'. You can see it for example in rows 12-15.  Here you just provide sets of properties and their values as a string.  Notice how TestPartner identifies controls with expressions like "Name=cgudh0fxq7w2n"  and "ID=':r3'".  Unfortunately as we  saw before, those IDs and Names are dynamically generated and change each time you log in GMail. We need a better way to locate those controls. Unfortunately GMail does not provide easy and reliable way to locate some of them (like persistent names or IDs for example), and TestPartner on the other hand does not know how to identify controls based on their relative location in the page.

Still, with some dirty hacks,  I was able to quickly come up with this version of the script which can be executed reliably:

Sub Main()
 
    sText = "Lorem Ipsum Dolor"
 
    ' -- Login
    IEWindow("Caption='Gmail*'").Attach
    HTMLEditBox("Name=Email").SetText "testautomationblog"
    HTMLEditBox("Name=Passwd").SetPasswordText "********"
    HTMLButton("Name=signIn").Click
 
    ' -- Go to compose mail and type the text
    HTMLSpan("InnerText='Compose Mail'").Click
    HTMLFrame("Name='' Index=1").Click
    IEWindow.Type sText
 
    ' -- Center and save
    HTMLImage("Width=20 Height=20 Index=16").Click
    Window.TextSelect "Save Now"
 
    ' -- Wait for the draft to get saved
    Sleep 2
    Window.TextSelect "Draft saved"
 
    ' -- Go to Drafts
    HTMLAnchor("Caption='Drafts*'").Click
    HTMLSpan("InnerText='*" & sText & "'").Click
 
    ' -- Find the text and discard the draft
    Window.TextSelect sText
    Window.TextSelect "Discard"
 
    ' -- Logout
    HTMLAnchor("Caption='Sign out'").Click
 
End Sub

This is a quick summary:
At line 6 I attach to the IE window. This is the only place I attach in the script as I only work in one window. I used raw attach instead of object map. Note how I used a wilcard for the window caption. Lines 7-12 are self explainotary. What you see in lines 13 and 14 is really a small hack. The editor area in GMail is contained in a HTMLFrame.  TestPartner can not find anything meaningful in it to identify it, so I used HTMLFrame("Name='' Index=1"), which means basically the first HTMLFrame with empty name.  Because the HTMLFrame object does not support the SetText method (like the HTMLEditBox in line 7 for example), I first click on it (line 13) and then just type in the text (line 14). I do not feel very good about this solution, but it was the first quick hack I could think of.
Identifying the center button in the toolbar of GMail was also problematic (line 17). All the buttons in GMail also lack unique IDs or Names, so I was able to identify the button only as HTMLImage("Width=20 Height=20 Index=16") - the 16th HTMLImage with Width=20 and Height=20 in the page.
Clicking the 'Save Now' button (line 18) also proved more difficult than I anticipated. For some reason it appeared as an empty unidentifiable Div when I tried to locate it with the object browser.  I used the Window.TextSelect trick, which is the most universal way to make TestPartner click on some text you can not identify otherwise.  This is actually a helpful tip - use Window.TextSelect if you can not identify something.  After clicking the 'Save Now' button we have to wait for the backend to actually save the page before moving on with the test. A quick and somewhat dirty way to do this is shown on lines and - wait for 2 seconds and then verify that the "Draft saved" text appears on the page.  I think the rest of the script needs no explanation.

To sum it up - TestPartner can be buggy and confusing, but after all, it is powerful enough to let you automate almost anything.  Maybe you'll need some time to find the right workarounds. Probably they will be ugly. Overall there are much better tools, especially if you want to do web automation. There are worse too, but I am happy that I don't have to use TestPartner anymore.

Failed Automation Projects

May 13th, 2009 § 2 comments

"Do not automate buggy software."

I was thinking about the failed automation projects I’ve been involved in during the last few years and I seem to find a pattern. All those projects were very, very buggy. I realize now that you should only aim to automate functionality which is fairly stable, so that you do not expect to see a test failure in more than about 1 of 10 test runs. If you see that your tests are failing 50% of the time, then automation is not the cure for your problems. Try to find out why this is happening in the first place.

 

HP’s Center of Excellence

April 22nd, 2009 § no comments yet

Centralization leads to mediocrity at best.

center

Today I went to a seminar, organized by HP to promote their offerings in the quality management area. What struck me most was the 'Center of Excellence' notion.  Basically the idea is that (big) organizations should centralize their quality-related activities into one unit (boldly named Center of Excellence), in order to reduce costs.  HP is willing to support you in this endeavor with software and consulting. They even came up with their own maturity model which ranks organizations on one of several levels - the lowest called for some reason 'Manual Testing' and the highest  of course being 'Center of Excellence'.

Somehow I don’t buy into this.  I realize that cost saving measures are in vogue now, but my experience shows that centralization leads to mediocrity at best, not excellence.

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?