I sure could use an “implements interface” in VBScript right about now…
In the last post, I showed a basic code snippet and described a little about how we implement our test scripts for automation. This post will go more into detail about how the underlying objects are implemented.
So, I'll re-post the same script I used in the last one, with some slight changes
-
'Log in to the application as the super administrator
-
LoginProfile "SUPER"
-
-
'Create a User, and set a few key attributes
-
Set oUser = NewUser
-
oUser.sUserID = "inquisitor"
-
oUser.sGivenName = "Marcus"
-
oUser.sFamilyName = "Inquisitor"
-
oUser.sPassword = "qq"
-
oUser.commit
-
oUser.validateFields
-
-
'Go to the master user list
-
AdminPageNav "users"
-
-
'Make sure this user is in the master list of users
-
oUser.assertExists
-
-
'Add some attributes, and change the Family Name (Last Name) to "the Inquisitor"
-
oUser.sBusinessEmail = "blah@si.com"
-
oUser.sBusinessPhone = "555-555-1222"
-
oUser.sFamilyName = "the Inquisitor"
-
oUser.update
-
-
'Assign this user the role of Manager
-
oUser.selectRole "Manager"
-
-
Logoff
-
-
'Log back in as this new user
-
Login "inquisitor", "qq"
-
-
'Make sure we're on the Manager dashboard now
-
' instead of the normal Employee Welcome page
-
ComparePageTitleWith "Manager Dashboard -- Marcus the Inquisitor"
First, I should note some of the methods used here: validateFields, update, and assertExists. The title of this post reflects a bit of a flaw here: almost all of our Classes have the same functions... these three and a few others, but there's no way, as there is in Java, to enforce the implementation. It's not a big deal when two or three of us are working on building out these libraries, but it becomes a much bigger deal when we add a 4th and a 5th... oy.
Here's the list of standard methods we implement for each of the 40+ Classes we've implemented:
Init- a poor man's constructorcommit- takes all defined attributes and creates the entity within the AUTlocate- navigates to the entity's representation in the AUTvalidateFields- checks the UI form fields against the defined attributesdel- deletes the objectassertExists- asserts, however it can, that the entity has been created in the AUTassertDoesNotExist- asserts, however it can, that the entity has NOT been created in the AUTsubmitViaAPI- creates the entity via the API instead of the UI, if available for this entity
Those methods are available, reliably, for every object we've implemented. In addition, each object has a set of methods tailored to that object. oUser.addRole is one such method--allows you to set the permissions for this user in a way that gives them more access. Most of our time is spent filling out these methods, so we can add functionality to our entities and allow complex interactions between them.
If you're using TDS (and you should be), IntelliSense will pick up all the attributes and methods for the Classes, and you'll be able to start writing code for any object without needing studying the code, or even all the documentation we've written. You don't need to know much about coding at all. We have our QA team members request methods where they don't exist. These methods get prioritized and implemented as we see fit, and as the AUT's underlying features stabilizes.
One key here - when the business analysts conduct their usability sessions and get feedback from our user conferences, things frequently change. They add a click here, remove a tab there, and change things all up. Most of the time, all that is required from our library developers is a change in one part of the central Class file, and the test script code doesn't change. That's a point you'll see emphasized time and again as I go through these things.
Anyway, once the test script is written, it gets entered into Rally, our test case repository. More on that in the next post.
Tags: qtp, QTP Classes, QTP Objects, test automation, test framework, test management, VBScript


June 5th, 2008 at 3:18 am
Nice article, I like the list of standard methods. Today it is day 4 of QTP for me, and I came up with the same sort of framework. It is funny to see how classes are playing a central role in QTP. Defining classes is actually the way the business works: Datamodels are important, the way it is imported or exported is less important. While as a tester you are apt to think the other way around.
Reply to Bas M. Dam
June 5th, 2008 at 9:30 am
Welcome to QTP!
It really is a decent little product as long as you use the parts of it that are good (browser control model at the DOM level, reporting, data tables, API, fine-grained XML control) and leave out the parts of it that are bad (object repository, actions, checkpoints, outputs, and all the things they’ve done to make things easy, but which only increase the amount of time you have to spend in maintenance).
Hopefully we’ll give you a bit of a jump start in the things that took us the longest, like remote test execution and pretty HTML test results via email.
Thanks for stopping by… and btw, if you’re going anywhere near Classes and you’re not using TDS, you’re doing a lot more work than you should be. Check it out.
MM
Reply to Marcus Merrell
June 5th, 2008 at 1:36 pm
Your site was a jump start to me indeed! It got me to start working with classes.
It is funny that just the things WinRunner had to offer, QTP is lacking and vice versa. I used to work a lot with WinRunner, but despite on what I wrote, I’m getting the catch real fast on QTP. (Quoting a colleague: “You are a real QTP expert!”)
I still have to get to work with XML and HTML reporting, but I think it will not be problematic because I did a lot with that with WinRunner. I’ll certainly read your articles about it!
BTW, I was flattered to see my site at your links section. Thank you!
Reply to Bas M. Dam