Oct
25
2008
--

When to change QTP Web ReplayType Setting?

What is ReplayType?

ReplayType is QTP Web Add-in setting. It can be used to change how the events are replayed on the browser. There are two modes of ReplayType

  • Events (1) - Replay of events using the Browser methods (something similar to DOM).
  • Mouse (2) - Replay of events using the mouse and keyboard simulation.

When to change ReplayType?

Use of ReplayType can be best explained by a below example. In below sample textbox we need to type in any value and see that the button gets enabled when there some text in the textbox and disabled when there is not text. Click on the button will display the values inside the textbox.

Scenario #1

Type in textbox and enable the button:

Now when we record using QTP on this page we would get the below code

Browser("KnowledgeInbox").Page("ReplayType").WebEdit("txtReplayType").Set "KnowledgeInbox"
Browser("KnowledgeInbox").Page("ReplayType").WebButton("Type and enable me").Click

But on replay QTP will throw a “Object is disabled” error as shown in below image

Object is disabled error during replay

Object is disabled error during replay

QTP throws above error as the ReplayType of the Web Add-in is set to 1 (Events). Let’s look at the HTML code related to the text box

<input onkeyup="EnableThis(this, document.getElementsByName('btnReplayType')[0])" name="txtReplayType" size="20" type="text" />

The input text box has a handler for onkeyup event. Now with ReplayType as 1 (events) QTP just goes and sets the value of textbox which means non of the events get fired. Now there are two possible solutions for the same. We will look at each of them one by one

Solution #1
Firing the handled event manually using FireEvent. In this approach we need to look into the HTML and see which event has a handler and fire the same after changing the value of the textbox

Browser("KnowledgeInbox").Page("ReplayType").WebEdit("txtReplayType").Set "KnowledgeInbox"
Browser("KnowledgeInbox").Page("ReplayType").WebEdit("txtReplayType").FireEvent "onkeyup"
Browser("KnowledgeInbox").Page("ReplayType").WebButton("Type and enable me").Click

Solution #2
Changing ReplayType to 2 (Mouse) will instruct QTP to replay the Set method using Keyboard and mouse simulation. This would simulate a actual user typing into the browser

Setting.WebPackage("ReplayType") = 2 'Mouse
Browser("KnowledgeInbox").Page("ReplayType").WebEdit("txtReplayType").Set "KnowledgeInbox"
Browser("KnowledgeInbox").Page("ReplayType").WebButton("Type and enable me").Click
Setting.WebPackage("ReplayType") = 1 'Events

We saw two of the few possible solutions. Which one should be used then? IMO we should first go for Solution #1 and if that does not work then for Solution #2. The reason behind that opinion is that ReplayType=2 means that your workstation needs unlocked when QTP replays the script.

Scenario #2
I won’t demonstrate the 2nd scenario but would just give overview of the same. For some links which opens popups, when clicked manually popup would open. But when we do the same thing through QTP it IE popup blocker would show a popup blocked message. IE popup blocker is said to be smart enough to determine if a user clicked a link or it was done through code and based on the same the popup is blocked or shown. Changing ReplayType to 2 (Mouse) would simulate a user click and not give the popup bar.

Rating: 0.0/10 (0 votes cast)
Oct
05
2008
--

Identifying controls using labels - Approach 1

Identifying objects correctly and robustly in an application is very important in Automation. In case you have automated any CRM application you might have noticed objects are recognized by a dynamic name

Browser("Browser").Page("Page").WebEdit("TS_EXTRA_FEILD40").Set "AAA"

Now after a build the code or object might change to

Browser("Browser").Page("Page").WebEdit("TS_EXTRA_FEILD42").Set "AAA"

These object changes are unpredictable and cause scripts to fail. Let’s assume the field name to be ‘Product Name:’ in the CRM application. Digging into the HTML code we can see the HTML code specific to the product code label and text box would look like below

<LABEL for="TS_EXTRA_FEILD40">Product Name:</LABEL>
<INPUT id="TS_EXTRA_FEILD40" name="TS_EXTRA_FEILD40" >

The HTML preview of the same is shown below

Product Name:

Using the general way of recording will produce a high maintenance effort scripts, as the object repository would need to be updated every time. Code below demonstrates how to get object using it’s label and not the actual HTML name

'----------------------------------------------------------------
'Author: Tarun Lalwani
'Website: http://KnowledgeInbox.com
'Paremeters -
'@ParentObject - The parent object for which the control needs
'            to be retrieved
'@LabelName - Label for which you need to get the control
'@MicClass - Type of object (WebEdit, WebList etc...)
'----------------------------------------------------------------
Function ObjFromLabel(ByVal ParentObject, ByVal LabelName, ByVal MicClass)
   'Return Nothing in case of issue
  Set ObjFromLabel = Nothing
 
   Dim objLabel
   Set objLabel = ParentObject.WebElement("html tag:=LABEL","outertext:=" & LabelName)
 
    'Check if the label object exists
   If objLabel.Exist(0) Then
      Dim controlHTMLid
 
      'get the property specified in FOR atrribute of the tag
      'Test. Below works for IE
      controlHTMLid = objLabel.GetROProperty("attribute/htmlfor")
 
      'In case of firefox
      if controlHTMLid ="" then controlHTMLid = objLabel.GetROProperty("attribute/for")
 
      If controlHTMLid <> "" Then
         Execute "Set ObjFromLabel = ParentObject." & MicClass & "(""html id:=" & controlHTMLid & """)"
      End If
   End If
End Function
 
Dim oPg, oEdit
 
'The page object
Set oPg = Browser("Identifying controls using").Page("Identifying controls using")
 
'Get the webedit for 'Product Name:'
Set oEdit = ObjFromLabel(oPg ,"Product Name:","WebEdit")
 
'Set the value
oEdit.Set "Tarun Lalwani"

The approach discussed above uses descriptive programming to check for the label first and then gets the html id of the specific control mapped to it.

Rating: 9.3/10 (11 votes cast)