In this QTP tutorial, we will learn – Smart Object identification, adding Synchronization point, Running a test & viewing the results, and the Silent Test runner.
Assume a situation when no object matches or multiple objects match the recorded description for an object during run time, then how does QTP handle it?
What You Will Learn:
QTP has a mechanism in place for cases exactly like this. If the recorded description does not enable QTP to identify the specified object in a step, and a smart identification definition is defined (and enabled) for the object, QTP tries to identify the object using “Smart identification”.
Let us see how this works along with some examples. For every object, there are Primary Properties and Secondary properties.
Example 1: Object with the recorded description is not found.
On the page, there was a button and the following are the properties:
- Primary: Name
- Secondary: Abs x,y
While recording the “Name” property was “Login ID”. Due to some changes to the application, the “Name” property is now changed to “User ID”. In this case, QTP will find a button with a different description and it should fail if it considers the primary properties alone.
But in cases like this, when the primary properties don’t match then it checks the secondary ones and if they match it recognizes the object. In this case, it is going to recognize the button by its X and Y coordinates.
Example 2: QTP was supposed to find a page X and there are 2 pages with similar browser settings.
In this case, too, it tries to use the “name” or other properties to find the right page/pages and works accordingly.
The above 2 are examples of cases where QTP engages the Smart Identification mechanism.
- Test results will also show if the step employed Smart identification to run successfully.
- If QTP cannot find the object despite Smart Identification, then the test fails.
For most of the objects, QTP provides default base filter properties (Primary) and optional filter properties (Secondary) that it checks if we enable Smart identification for them. The user does have an option to edit which properties to consider too. To do so, go to “Tools -> Object Identification”.
Choose the relevant Environment from the drop-down and choose the Object Class. Once you chose it, check the “Enable Smart Identification” and click “Configure”.
Click Add or Remove.
Select properties as required:
Make your selection and click OK when done.
The above process will ensure that the next time it has difficulty identifying an object of this class, it will employ smart identification to do so.
Also, for most of the objects “Smart identification” is turned ON by default. You can see where this is the case for a certain object by accessing it in the OR under the “Additional details” part of its object properties.
It is set to “True” if enabled and “False” if disabled.
You can also choose to enable or disable Smart identification entirely for a test run. Choose “File -> Settings -> Run -> Disable Smart Identification during the run session” option.
Consider this program,
SystemUtil.Run "iexplore.exe", "http://www.gmail.com" Browser("Gmail: Email from Google").page("Gmail: Email from Google").Sync Browser("Gmail: Email from Google").Page("Gmail: Email from Google").WebEdit("Email").Set "swatiseela" Browser("Gmail: Email from Google").Page("Gmail: Email from Google").WebEdit("Passwd").SetSecure "sfgs686898" Browser("Gmail: Email from Google").Page("Gmail: Email from Google").WebButton("Sign in").Click Browser("Gmail: Email from Google").Page("Gmail - Inbox").Link("Sign out").Click
In an ideal world, as soon as you hit the “Sign in” button on the Gmail login page, the “Inbox” should get displayed without any delays. This means that the state of the application is ready for the last statement in our example to be executed immediately after the last but one statement runs.
But in real-time, due to many reasons, applications don’t always load at the same pace. If we do not instruct QTP to wait a certain while before it moves on. More specifically, until an object attains a certain state.
A synchronization point is used to instruct QTP to wait until a particular object property achieves the value you specify.
On inserting a sync point a “Wait Property” statement is inserted into the test.
Browser("Gmail: Email from Google").Page("Gmail - Inbox"). Link("Sign out").WaitProperty “Visibile”,true,20
So your new program is going to look something like this: (line #6 below)
SystemUtil.Run "iexplore.exe", "http://www.gmail.com" Browser("Gmail: Email from Google").page("Gmail: Email from Google").Sync Browser("Gmail: Email from Google").Page("Gmail: Email from Google").WebEdit("Email").Set "swatiseela" Browser("Gmail: Email from Google").Page("Gmail: Email from Google").WebEdit("Passwd").SetSecure "sfgs686898" Browser("Gmail: Email from Google").Page("Gmail: Email from Google").WebButton("Sign in").Click Browser("Gmail: Email from Google").Page("Gmail - Inbox"). Link("Sign out").WaitProperty “Visible”,true,1000 Browser("Gmail: Email from Google").Page("Gmail - Inbox").Link("Sign out").Click
It can be inserted while recording using the menu option “Insert -> Synchronization Point”. Choose the Object to insert the sync point.
Enter the value as required:
This is the statement that gets inserted:
Browser("Gmail - Inbox").Page("Gmail - Inbox").Link("Sign out").WaitProperty "visible", true, 10000
Running a Test
#1) Automation -> Run or F5 typically runs the entire test.
#2) You can run a part of the test by choosing the “Automation -> Run Current Action” option.
#3) You can run a test from a certain point in your test by choosing the “Automation -> Run From Step” option.
#4) As soon as you choose any of the above ways to run a test, you will be prompted to choose the location where you would like the test results to be stored. You can choose the folder by choosing the first option, in which case the results will be stored for every instance of the test run.
But if you choose the next option, a temporary folder, the results get overwritten and only the latest test run result will be stored in the folder chosen. In terms of memory, it is advisable to use the second option while testing your QTP test.
Unless you want every test run results, do not choose the first option because obviously, it is going to use up a lot of space.
#5) Input parameters: If the test input parameters were defined for this test, this tab is the place where you provide them.
#6) You can also run a couple of tests all at once in a batch. QTP has a “Batch Runner” tool. It is also an external tool just like a “Password encoder tool” that we discussed earlier.
In our articles so far, whether we are discussing data table iteration, checkpoints, smart identification, or in general the test step run, the Test results are the place you get to see whether something was successful or not.
Apart from the above, the test results can hold a screenshot of your AUT when a failure occurs. This depends on the settings at “File -> Settings -> Run”. The tester can print and export test results.
To make test results more understandable the user can write his comments into the test results.
For Example, if a certain condition fails in your test, you might want to write in the test results that “Did not work for the value X”. You can do so by using the “reporter.reportevent” statement.
The following is the syntax:
Reporter.Reportevent(Event Status,Reporter step name, details)
Event status: MicPass, MicFail, MicWarning, MicDetail, the next two parameters can be any text that helps include further details.
If this is my statement and I run it:
reporter.ReportEvent micPass,”Swati’s First Step”,”Passed coz I told it to pass …”
The test results are going to look like this:
Since this is not a very widely used feature, I am going to do a high-level introduction here.
Typically, a test is divided into transactions when you have to measure how long it takes to run a certain section of it.
It is also used when a QTP test is to be used by Load Runner or Business Process Monitor. In either of these cases, your test has to be recorded in terms of a transaction and anything outside of it will be ignored.
You can start a transaction from QTP using “Insert->Start Transaction”. Give it a name, choose if you want it before or after the current step, and choose OK.
Services.StartTransaction “TransactionTest” – Gets inserted. I will now record a login into Gmail.com.
Once you are done with the recording. Choose “Insert -> End Transaction”. Click OK.
Services.EndTransaction “TransactionTest” – gets inserted.
This is the code:
I will run this test now. Let us see how the test results look. The results will show a summary in terms of the time taken to finish the transaction.
Silent Test Runner
Another tool that QTP provides is the Silent Test runner. This enables the tester to run his test without having to launch QTP. It also helps simulate QTP runs from load runner and verify its compatibility with the same.
It will not work if QTP is already open and another test is running via it.
Use Start -> Programs -> QuickTest Professional -> Tools -> Silent Test Runner menu command to invoke it. Select the test and click “Run Test”.
This is how it looks while running the test:
Once this is completed:
Test Run log:
The “Transaction Summary” will be activated if the test contains at least one transaction.
We have now reached the end of this tutorial and have covered quite a few miscellaneous QTP topics here. I hope this is useful to you all.
Please feel free to post your comments and questions.