Web ReplayType?

http://blog.sina.com.cn/s/blog_621a2bdf0100gewc.html

Web ReplayType?(Tarun lalwani)

(2010-01-13 14:46:28)
转载
标签:

杂谈

分类: QTP_VBS

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.

你可能感兴趣的:(Web,职场,休闲,ReplayType)