28.9.13

Working with HTML DOM and QTP

The other day a junior team member of mine was having hard time working with HTML DOM and QTP, he was confused between a lot of terms like tags, attributes, values, properties, DOM elements, GetROProperty, GetTOProperty....the list was endless, and as usual, he was already late to meet the deadline. So, instead of asking him to google all the 'gyaan' on this topic, I gave him a shot of red bull, as follows.....

•    The Document Object Model (DOM) is a platform and language-neutral interface that allows programs and scripts to dynamically access and update the content, structure, and style of a HTML document. The HTML DOM defines the objects and properties of all HTML elements, and the methods (interface) to access them. JavaScript uses DOM to add interactivity to HTML pages. The DOM is an API for HTML and XML documents. It provides a structural representation of the document, enabling you to modify its content and visual presentation.

[ The most important thing to realize is - what we refer to as "Property" of an object in QTP, is actually the "Attribute" in HTML terms, and the Value of the Property is actually the value defined for that Attribute. ]
 You can modify the appearance and behavior of an HTML element by altering a DOM object's properties and calling its methods.
When you use the QTP's "Object Property" for a Web object, you actually get a reference to the DOM object. You get access to the native methods and properties of that web object.
This means that any operation that you can perform on a DOM object, you can also perform by running a <WebTestObject>.Object statement on the Web object.
For example, you can use the links property of the Internet Explorer document object to retrieve a link collection.
Example: Activate an Edit Box's Native Focus Method

    Set MyWebEdit = Browser("Mercury Tours").Page("Mercury Tours").WebEdit("username").Object
    MyWebEdit.focus

All the values of the attributes can be accessed by using the following syntax in DOM (as shown below):
    object.attribute
These attribute values can also be accessed via GetROProperty method in QTP.
Both the sets of code (the one with the DOM and the other with QTP methods) will return the same values, the only difference being that if a attribute does not exist, then the DOM returns an Error whereas the QTP GetROProperty method returns 0.

•    Common Methods used in DOM:

        •    Supported by QTP by defualt
                •    getElementById
                •    getElementsByName
                •    getElementsByTagName
           
When we use methods like the GetROProperty to read property values of the objects, QTP actually returns the values of these attributes that are defined for that object. Hence, if we use GetROProperty("href") it will return the value of the href attribute.
If we want to do this via DOM then we can get the value of href property by using the below code:
sHref = oDOM.Document.getElementById("OpenAcct").href

•    DOM vs DP:   
    Code written in DOM will be substantially faster than the code written in DP (to perform the same operation), because there will be no overhead of Object identification with DOM. QTP UnP Pg 202.
           
    Methods like GetROProperty, GetTOProperty, etc will not be supported by DOM elements directly because they are QTP specific methods. However, these methods will be supported by DP because DP is nothing but the same QTP code.
                       
•    Tools: Even though QTP has a good built in Object-Spy, its nowhere close to what Firebug add-on for FireFox can do, and is a must in anyone' arsenal of tools.


•    WebTablesNow a days modern websites dont use the 'table' tags for building their pages and displaying content, because of the following reasons

  • More number of code needs to be written and maintained overtime as compared to the use of div tags
  • It makes the page structure rigid
  • It tries to mix the content and the style, which is not a good practice
  • Its difficult to display the data correctly on mobile devices with table tags


If there are multiple nested table tags in the html code for displaying data in tabular format, then that's a poorly written code.
As opposed to this, DIV tags provide easy maintenance, faster loading and search engine friendly features, as described here

Hence, now a days only DIV tags are used to structure data in tabular format. This also means that 'grids' would be used to display data in tabular format. Grids and Tables are 2 different things in HTML world.



Having said all this, it does not mean he can get away with not having to understand HTML, DOM, and related concepts, as I have ensured that this goes in his appraisal goal sheet, and I would suggest you do the same, if not done already.

Happy learning!!!

31.7.13

Is a formal Certification in Testing still Relevant?


The real answer to this is - it depends! on the context, on the need, on necessity, on motivation, on relevance, and even on geography...
Is it absolutely necessary - definitely not! Should you go for it - may be. Why? - read the first line.

OK, now the real reasons.
What a formal Certification (like ISTQB) does is a lay a foundation about the basic process of Software Testing, that anyone who works in this field is expected to know - you cannot build an Empire state building with only 6 inches of slab as foundation.
But I feel that the course-ware (syllabus) is mostly irrelevant in today's real world scenario, though some of it can be pretty useful even in the advanced stages of your careers. It is like the basics of engineering that we all studied but rarely used, but it was still important at that point of our lives.
So, the point is if you are just starting your career in testing - most of the young people in India and some Asian countries fall in this category  - it might be worthwhile to go for it. Because most testers start their careers in testing without any formal training in the different aspects of testing, and they keep struggling until they develop that knowledge and understanding. So all this certification can do is speed-up that learning a bit, by pointing you in the right direction.

But for people who have credible experience it may not be worth spending a weekend that you could have spent on taking your wife shopping! For people in mature markets like US and EU, this certification has already lost all relevance; and for those who want to 'statistically' refuse, here is a good article that can help you do just that - http://chrismcmahonsblog.blogspot.in/2010/10/ignoring-certification-with-numbers.html

A weekend is all it takes to clear these certifications - but its no cake-walk either as the failure rate is quite high, though the material is quite abundantly (and freely) available online.

One exam tip for those who want to take the plunge - don't sweat too much over the 'Standards' even if you get the itch to do so, because not much gets asked about those anyways!

1.7.13

When QTP is unable to Identify Web Objects

Often we are faced with an issue when QTP cannot identify the objects in a web page.
So, listed below are some of the things we should try (in no particular order). This is not an exhaustive list (yet), but this could give some pointers or options that you may not have tried.

Bear in mind that Uninstall & Re-install should always be the last option - no matter how tempting it is ;-)

•    Check the compatibility of QTP with OS and IE.

•    IE Browser > Tools > Internet Options > Disable the "Enable Tabbed Browsing" checkbox.  
    This worked for me on Windows 7 with IE 8 and QTP 11 - Jun2012

•    IE Browser > Tools > Internet Options > Disable the "Enable Protected Mode" checkbox. If Protected Mode is required to be set as ON, then a QTP Patch QTPWEB_00073 is needed.


•     Sometimes QTP identifies objects on the main browser page but not on the child page. This may happen when web pages have Web 2.0 elements embedded in them. These Web 2.0 apps are not based on new technology but instead on a set of cumulative toolkits or frameworks, like AJAX, Dojo, Yahoo User Interface (YUI) and GWT. In such cases, we have to enable/install Web 2.0 toolkit add-ins in QTP. Refer the following links in such a case:


•    UAC (User Account Control) has to be disabled on Vista and for Windows7 has to be set to "Never Notify"

•    If QTP's BHOManager Addon is disabled in IE, even this can cause issues, and has to be Enabled.
    To enable it go to IE > Tools > Addons > BHOManager Class - Enable

•    IE Browser > Tools > Internet Options > Advanced > Browsing > Enable Third Party Browser Extensions

•    For FireFox, ensure that QTP Plugin is available in the Extensions section of the Addons in Fox



•    Ensure that the Browser is running in 32-bit mode, even if the machine is 64-bit because QTP is a 32-bit app. To ensure this during run-time, pass the complete path for the browser (the one with (x86)) via SystemUtil.Run

List of COM Objects

We often work with a lot of COM objects, and it may cause errors if we define them incorrectly, so, here is a list of commonly used COM objects.

Set oQTPApp =                 CreateObject ("QuickTest.Application")
Set oWSHNetwork =          CreateObject ("WScript.Network")
Set oWSHShell =             CreateObject ("WScript.Shell")
Set oShell =                     CreateObject ("Shell.Application")
Set oFSO =                         CreateObject ("Scripting.FileSystemObject")
Set oWMI =                     GetObject ("WinMgmts:")
Set oWMIService =         GetObject ("WinMgmts:{ImpersonationLevel=Impersonate}!\\.\Root\Cimv2")    ' ''The "." can be replaced by compturename

Set oADOConn =             CreateObject ("ADODB.Connection")
Set oADORecSet =             CreateObject ("ADODB.Recordset")
Set oDeviceReplay =        CreateObject ("Mercury.DeviceReplay")
Set oIE =                             CreateObject ("InternetExplorer.Application")
Set oDic =                         CreateObject ("Scripting.Dictionary")
Set oWinHTTP =             CreateObject ("WinHTTP.WinHTTPRequest.5.1")
Set oXmlDoc =                 CreateObject ("Microsoft.XmlDom")
Set oXml2Doc =              CreateObject ("MSXml2.DOMDocument.5.0")
Set oSoapClient =              CreateObject ("MSSoap.SoapClient")
Set oCal =                          CreateObject ("MSCAL.Calendar")
Set oQuattro =                  CreateObject ("QuattroPro.PerfectScript")
Set oWPerfect =              CreateObject ("WordPerfect.PerfectScript")
Set oRandom =                  CreateObject ("System.Random")
Set oArrList =                  CreateObject ("System.Collections.ArrayList")
Set oSortList =                  CreateObject ("System.Collections.SortedList")
Set oiTunes =                  CreateObject ("iTunes.Application")
Set oWMPlayer =              CreateObject ("WMPlayer.OCX")
Set oWM7Player =          CreateObject ("WMPlayer.OCX.7")
Set oRealPlayer =              CreateObject ("rmocx.RealPlayer G2 Control.1")
Set oFSDialog =                  CreateObject ("SAFRCFileDlg.FileSave")
Set oFODialog =              CreateObject ("SAFRCFileDlg.FileOpen")
Set oDialog =                  CreateObject ("UserAccounts.CommonDialog")
Set oWOL =                      CreateObject ("UltraWOL.ctlUltraWOL")
Set oSearcher =              CreateObject ("Microsoft.Update.Searcher")
Set oEmail =                      CreateObject ("CDO.Message")
Set oInet =                      CreateObject ("InetCtls.Inet.1")
Set oExcel =                      CreateObject ("Excel.Application")
Set oOutlook =                  CreateObject ("Outlook.Application")
Set oPpt =                          CreateObject ("PowerPoint.Application")
Set oWord =                      CreateObject ("Word.Application")
Set oHTML =                     CreateObject ("HTMLFile")

26.6.13

Options to improve performance of QTP Scripts

There are umpteen ways to improve the performance of a script, here are some of my tips to improve performance, (at least the ones I can remember right now :-) ).
Will keep adding, and request you to do too.

Cheers!

  1. Ensure that Smart Identification is not invoked too often during execution by updating the concerned object's properties, but i would recommend to not disable entirely as it may cause script failure. 
  2. Also, object identification and manipulation is faster with DOM based methods, as compared to using Object Repository for the same task, because there is no overhead for object identification
  3. Remove or minimize the output to the QTP Print Log, and keep the statement as short as possible.
  4. Avoid having unnecessary columns in your database queries, have only the ones that are really required. 
  5. Avoid taking a screen shot at every step - restrict it for submitting pages, and errors.
  6. Change the Default Timeout options depending on your needs, but i would prefer to use this option as the last resort, because this may sometimes cause issues during execution.
  7. I like QTP Actions, but having a lot of actions within a single script may slow down script execution, especially if you are using LoadAndRunAction statement to call the actions dynamically in a loop of sorts. This will only get worse if you are calling the actions from QC. So, minimize the number of actions being called, or better still use as many Functions as possible because these are much faster than actions.
  8. For those of you who access data from an Excel, and that too on a shared drive, things could be faster if you directly import the entire sheet/file, rather than referring it via association, or reading line by line. I personally prefer to use a MS SQL Server Database for all my test data.