Posts Tagged ‘QuickTest-Pro-9.2’

QTP’s mysterious Init method

Thursday, May 22nd, 2008

One limitation of QTP that has always bothered me is the inability to reuse its web objects after the browser reloads. I spend countless cpu cycles parsing the DOM to find an element, grab enough properties to make it unique, build a description with those properties and finally get the right micobject. Then I perform some action and that reloads the page, and my object is useless. If I want to use it, I have to start the process all over again.

After years of struggle to find an answer, I packed some gear, hired a Sherpa and set off to find a guru who could give me an answer.
(more…)

Execute Javascript from QuickTest Pro

Tuesday, May 20th, 2008

Despite persistent the rumors to the contrary, you really can execute Javascript from QTP, and not just using Web Extensibility. Here is a simple function that will run some javascript in IE and return the result.

Visual Basic:
  1. Public Function evalJS(oBrowser, sJavaScript)
  2.     Set JSEntry = oBrowser.object.document.documentelement.parentnode.parentwindow
  3.     On Error Resume Next
  4.     evalJS = JSEntry.eval(sJavaScript)
  5.     On Error Goto 0
  6. End Function
  7.  
  8. Set oBrowser = Browser("version:=inter.*")
  9. evalJS oBrowser, "alert('Hello, world');"

(more...)

Test Design Studio

Wednesday, September 5th, 2007

I have spent most of the last few weeks working on QTP libraries, but very little of that time was spent wrestling with Mercury’s beast of an IDE. Aside from actually running my tests, I use QuickTest for very little these days. Instead, I am using a new editor called Test Design Studio. Everybody who uses QuickTest Pro’s expert view should try Test Design Studio. Once you do, you won’t go back to QTP.

Before we get too far into this, you need to know that Test Design Studio (TDS) isn’t a complete QTP replacement. TDS replaces QuickTest’s editor and library management, but it doesn’t actually run the tests. You use TDS to write tests and QTP to run them.

I could go on for pages about TDS’s features, but I won’t. You can see all of that at Patterson-consulting.net. Instead I will give you my first-ever top 10 list.

Top Ten Test Design Studio features that QTP is missing

10. Edit two tests at once – QTP is already on version 9.2 and they still haven’t figured out that users programmers might want to copy text from one test to another.

9. Excellent technical support – This isn’t technically a product feature, but it makes a big difference in using the product. I have submitted my share of help requests and bugs to Mercury, and I don’t think I have ever had an issue resolved within a day…rarely within a week. Patterson Consulting is another story. They will bend over backward to help you. Send an email to support or post in their help forum, and you have a good chance of getting a resolution within the hour. I haven’t called their support number, but I think I’m safe in assuming that if I do I won’t have to navigate through multiple levels of tech support before getting a resolution. The same can’t be said for Mercury.

8. Documentation Wizard – Automatically generate a help file from your code comments. If you maintain a large library, you know what a pain the documentation can be. TDS’s Documentation Wizard takes 90% of the work out of it.

7. IntelliSense for every class and function in your library – Don’t confuse this with QTP’s IntelliSense. TDS goes far beyond what QTP offers. With QTP, if you type Browser(oDescription), you will get IntelliSense for the various methods registered to the Browser type, but what if you have a function that returns a Browser object? You are out of luck with QTP, but TDS is able to tell that the function will return a browser. For instance, I often call the function BrowserDefault, which returns my default browser. With TDS, as soon as I type the period after the function name, I see all of Browser’s registered methods.
TDS Intellisense
I can’t do justice to TDS’s IntelliSense here. You’ll have to see it for yourself.

6. Customizable menus – You can put almost anything you can think of on any toolbar or menu. I recently worked on customizing the xslt file that defines the layout of TDS’s Object Browser. Instead of restarting TDS to try out changes, I added the “Reload ObjectBrowser.xslt” command to my tools menu. For most applications, that would be an internal-only call, but it looks like Patterson Consulting has made a point to make everything possible available to their users.

5. Hooks for external tools – There are still a few things that Test Design Studio doesn’t do. For that, there are external tools. For instance, I have an external tool set up that grabs all the vbs files in my project and adds them as resources on the active test. Another external tool is a vbs script that will open and run the current test in QTP.

4. Customizable Hot Keys – One of the few things I don’t care for in TDS are the default hot-keys assignments, but thanks to the customizable hot keys, I don’t have to remember that Ctrl+E,C is the command to comment out a block of text. It took about five minutes to make TDS match the Eclipse hot keys that I am used to.
Also, by combining this with the external tools mentioned above, I just have to press F5 to run the current test in QTP.

3. Code snippets – If you use Visual Studio, you already know what these are. I had not used code snippets before TDS, but I have come to find them very useful. I’m not sure that I can adequately explain code snippets in this post, so I’ll let Patterson explain it.

2. Macros – If you like to do the same thing over and over and over and over, this isn’t for you.

1. Search and replace throughout the project – Search and replace throughout the project is huge. Shortly after I started evaluating TDS, I changed the signature on a function. It literally took less than a minute to find and update hundreds of calls to that function spread over dozens of files.

There you have my first-ever top ten list. I hope you enjoyed it. I probably shouldn’t have numbered them because I just wrote them in the order that I thought of them. I also ran out of numbers before I ran out of features. If the list were a bit longer I would have included Object Browser, collapsible code outlining and xml-comments.

Domain Specific Language

Tuesday, August 28th, 2007

One of my favorite talks at GTAC was Douglas Sellers' presentation on implementing a Domain Specific Language (DSL) with Selenium. I am not a Selenium user, but a lot of what he talked about relates well to what we are trying to do with QTP.

Here is the video for your viewing pleasure.

Introducing SIFL

Thursday, August 23rd, 2007

The Inquisitors are proud to introduce a bit of code we have been working on. We are calling it the Software Inquisition Foundation Library for QTP, but you can call it SIFL (pronounced like "sniffle", but without the "n").

SIFL is a collection of QTP functions that we have been using for a while as a base framework for our QTP tests. Having eschewed checkpoints, the object repository, and the idea of record-and-playback testing, we needed a uniform way to write tests. SIFL is what we came up with.

Before I get into the details, let me show you a sample test to give an idea of what we are looking at. This is a quick example that uses the all-too-familiar Mercury Tours web site. We will open the site, navigate to the cruises page and make sure the departure time for the Skagway cruise is 5 pm.

Visual Basic:
  1. BrowserDefault.Navigate "http://newtours.mercuryinteractive.com"
  2. BrowserDefault.Link("innerText:=Cruises").Click
  3. Set oTable = BrowserDefault.WebTable("innerText:=Cruise Itinerary.*")
  4. sDeparture = oTable.GetXWhereYisString("Departure", "Port of Call", "Skagway, Alaska")
  5. assertStringEquals sDeparture, "5 pm"

If you are used to seeing QTP code, that should look somewhat – but not entirely – familiar. I’ll go line-by-line to show you what is happening.

BrowserDefault.Navigate "http://newtours.mercuryinteractive.com"

The “BrowserDefault” function returns the current default browser. Because we have not already defined a default browser, it will open a new instance of IE for us and make it the default for future calls to BrowserDefault. The “Navigate” portion of that line is just the browser object’s standard navigate method. This causes the newly opened instance of IE to navigate to the Mercury Tours site.

BrowserDefault.Link("innerText:=Cruises").Click

Here we are calling the default browser again. This time we are clicking a link in the default browser.

Set oTable = BrowserDefault.WebTable("innerText:=Cruise Itinerary.*")

Once again, this is pretty standard. We are just assigning this web table instance to oTable. This step isn’t really necessary, but I wanted to keep the next line short

sDeparture = oTable.GetXWhereYisString("Departure", "Port of Call", "Skagway, Alaska")

Here we are using the SIFL method “GetXWhereYisString”. To put it simply, this gets the data from the “Departure” column in the row where the “Port of Call” column is “Skagway, Alaska”. If everything is kosher on the site, sDeparture should be a string with the value “5 pm”.

assertStringEquals sDeparture, "5 pm"

Here we assert that the string sDeparture equals “5 pm” and note the results in the log. If the assertion is correct, it passes, if not, it fails. Note the fine control we have over the types involved in this homemade "checkpoint". This is what allows us to execute tests across continents without a complicated source tree.

I am writing this on a plane that is about to land, so that's it for now. Expect to see more on SIFL in the next few days along with a link to download it for yourself.

Multiple QTP instances with sandboxie

Wednesday, July 11th, 2007

I just learned a new trick.

Sandboxie is a freeware application that you can use to run two instances of QuickTest Pro simultaneously. Sandboxie will create a virtual sandbox separated from the rest of the applications on your machine. What happens in the sandbox stays in the sandbox, and what happens outside the sandbox stays outside.

Once you have sandboxie installed, run an instance of QTP in the sandbox and then run another instance outside the sandbox. They won't see each other. Better yet, they won't see each other's browsers, so you can run two tests at the same time without them interfering with each other.

Of course sandboxie wasn't written with QTP in mind. This is just one of many applications for it. Most of you are software testers, and I am sure that software testers can figure out the benefits of segregating a test app from the rest of your machine.

More on Named Optional Arguments in VBScript

Saturday, December 9th, 2006

I have been extensively using the method for vbscript optional arguments that I described in March. I want to expand on this a little with some recent changes we have made to how we use this.

Functions that use this method have an aOptions parameter in their signatures. That means, that even if we are not going to specify any optional arguments, we have to pass something, so we pass a Null. The problem is that I end up passing Null most of the time, and I don't like having to do that - especially for our smoke tests where are code is visible to manual testers and developers.

For example, I will use a simple function called WebEditFillByID that simply finds a WebEdit based on it's html id and fills it with the text supplied. There is also an aOptions parameter in its signature, but I don't usually set any options. So, when I am filling out a form it looks something like this.

Visual Basic:
  1. WebEditFillByID "firstName", "Bob", NULL
  2. WebEditFillByID "lastName", "Saget", NULL
  3. WebEditFillByID "ssn", "208-49-8168", NULL

That doesn't look too bad, but it would be much more legible without the Nulls in the way. So, to get aOptions out of WebEditFillByID's signature I create a new function called WebEditFillByIDAdv that is identical to WebEditFillByID. Directly beneath WebEditFillByIDAdv, I put a second function named WebEditFillByID with the same signature minus the aOptions. All WebEditFillByID does is call WebEditFillByID with the same arguments it was passed and adds a Null for the aOptions in WebEditFillByID's signature.

Now I can fill the same form without the Nulls.

Visual Basic:
  1. WebEditFillByID "firstName"  ,       "Bob"
  2. WebEditFillByID "lastName"   ,       "Saget"
  3. WebEditFillByID "ssn"        ,       "208-49-8168"

In my opinion, this is much more pleasant to deal with. For reference, here are the new functions.

Visual Basic:
  1. Public Function WebEditFillByIDAdv ( sID, sValue, aOptions )
  2.     Set oOptions = GetOpts( _
  3.         ARRAY( _
  4.             "oBrowser", BrowserDefault(NULL) ), _
  5.         aOptions)
  6.     Set oBrowser = oOptions("oBrowser")
  7.     oBrowser.WebEdit("html id:=" & escapeHTMLid(sID)).Set sValue
  8. End Function
  9.  
  10. Public Function WebEditFillByID ( sID, sValue )
  11.     WebEditFillByIDAdv sID, sValue, NULL
  12. End Function

To read more about named optional arguments in vbscript, see my previous post about it.

Mercury gives us SAFFRON

Friday, October 27th, 2006

Last week, Mercury posted a file for download called "QTP Expert Series - Issue 1". I saw it today and it interested me enough to download it. I'm certainly glad I did, because inside I found a spicy* little example framework called SAFFRON (Simple Automation Framework For Remarkably Obvious Notes).

SAFFRON is far from being a ready-to-use framework, but it does provide some good example code for creating an easy to read and write meta language that doesn't use an Object Repository. It is similar in concept to what the Inquisitors have been working on ... except a lot more light weight.

Here is an example from the SAFFRON FAQ:

QuickTest Script:

Visual Basic:
  1. Browser("Google").Navigate "http://google.com/"
  2. Browser("Google").Page("Google").WebEdit("q").Set "Hello World!"
  3. Browser("Google").Page("Google").WebButton("Google Search").Click
  4. Browser("Google").Page("Hello World! - Google").Link("Hello, World Page").Click

SAFFRON Script:

Visual Basic:
  1. BrowseTo "http://google.com/"
  2. EnterTextIn "q", "Hello World!"
  3. Activate "WebButton", "Google Search"
  4. Activate "Link", "Hello, World Page"

SAFFRON is extremely limited, but it is a step in the right direction. And it is good to know there is at least one person at Mercury who is doing some innovative thinking on test frameworks instead of focusing on how to apply the latest buzzword to the same old record and playback tests.

You can download SAFFRON on Mercury's support site or through this direct link.

* spicy...saffron...get it?