简体   繁体   English

HP QTP / UFT中的fireevent()功能如何?

[英]What is the functioning of fireevent() in HP QTP / UFT?

I am learning HP UFT. 我正在学习HP UFT。

Recently I came across fireevent and I tried to implement it on the website of Flipkart . 最近我遇到了fireevent ,我试图在Flipkart的网站上实现它。 I was trying to use firevent("onmouseover") for the link Men on the homepage of the website. 我试图在网站主页上使用firevent("onmouseover")链接Men

I used ChildObjects to find out the Link and WebElement (in two different tests) , first Highlighted it and then used object.fireevent("onmouseover") as well as object.fireevent("OnClick") . 我使用ChildObjects找出了Link和WebElement (在两个不同的测试中) ,首先突出显示它然后使用object.fireevent("onmouseover")以及object.fireevent("OnClick") The OnClick is working and it is showing the link as selected (ie the dotted box covering the link when we press tab) , but it is not showing the Menu Under Men Section. OnClick正在工作,它显示链接为选中(即当我们按Tab键时覆盖链接的虚线框) ,但它没有显示菜单下的男性部分。

I had googled and bingged a lot. 我用谷歌搜索了很多东西。 But was unable to find the exact working of FireEvent in QTP/UFT. 但无法在QTP / UFT中找到FireEvent的确切工作。

Please Help me solving the above problem as well as some tutorials on FireEvent. 请帮我解决上述问题以及FireEvent的一些教程。

EDIT: I am using IE 11 for testing. 编辑:我正在使用IE 11进行测试。

Motti has already answered the technical definition, but I shall attempt to give you a solution to your functional issue. Motti已经回答了技术定义,但我将尝试为您解决您的功能问题。

In my experience .FireEvent often doesn't work as you would expect. 根据我的经验.FireEvent通常不会像你期望的那样工作。 An alternative for something like onmouseover is to simulate user behaviour a bit more closely by actually moving the mouse to the desired location. onmouseover类的替代方案是通过将鼠标实际移动到所需位置来更紧密地模拟用户行为。 In our framework we have a little extension function to do just that, a pared-down version of which is shown here: 在我们的框架中,我们有一个小扩展功能来做到这一点,其中的简化版本如下所示:

Sub My_MouseOver(objSender)
    Dim absX : absX = objSender.GetROProperty("abs_x")
    Dim absY : absY = objSender.GetROProperty("abs_y")
    Dim width : width = objSender.GetROProperty("width")
    Dim height : height = objSender.GetROProperty("height")
    Dim x : x = (absX + (width / 2))
    Dim y : y = (absY + (height / 2))
    Dim deviceReplay : Set deviceReplay = CreateObject("Mercury.DeviceReplay")
    deviceReplay.MouseMove x, y

    Reporter.ReportEvent micDone, "A step name", "A useful step description"
End Sub
RegisterUserFunc "Link", "MouseOver", "My_MouseOver"
RegisterUserFunc "WebButton", "MouseOver", "My_MouseOver"
RegisterUserFunc "WebElement", "MouseOver", "My_MouseOver"

As an example you can then do as follows to bring up the "ELECTRONICS" menu overlay on flipkart.com (obviously substitute your own Browser and Page definitions): 作为示例,您可以按照以下步骤在flipkart.com上显示“ELECTRONICS”菜单覆盖(显然可以替换您自己的BrowserPage定义):

Browser("Flipkart").Page("Main Nav").Link("xpath:=//a[@data-tracking-id='electronics']").MouseOver

In the original version there's various extra bits of error handling and custom reporting so it tells you what you clicked on, but the essence is the same. 在原始版本中,有各种额外的错误处理和自定义报告,因此它会告诉您点击的内容,但实质是相同的。 It locates the object on screen, calculates the centre and moves the mouse there. 它将对象定位在屏幕上,计算中心并将鼠标移动到那里。 You might want to wait a small amount of time for the menu overlay to appear after doing so before calling .Click on one of the newly-displayed sub-elements. 在调用之前,您可能需要等待一小段时间才能显示菜单覆盖.Click其中一个新显示的子元素。

I found a solution to my problem and it is working perfectly. 我找到了解决问题的方法,并且工作正常。

Setting.WebPackage("ReplayType") = 2
object.FireEvent "onmouseover"
Setting.WebPackage("ReplayType") = 1

In this case, the object will be: 在这种情况下, object将是:

Browser("name:=Online Shopping.*").Page("name:=Online Shopping.*").Link("innertext:=Men")

I have tried this and it is working fine. 我试过这个,它工作正常。 I guess, we do not need any alternatives. 我想,我们不需要任何其他选择。 But I really don't know is, Ctrl+Space is not working for this in UFT. 但我真的不知道是,Ctrl + Space在UFT中不起作用。 Don't know the reason. 不知道原因。

This actually depends on what browser you're using. 这实际上取决于您使用的浏览器。

Warning: There are exceptions to the information presented in this answer and it also may change in the future. 警告:此答案中提供的信息有例外情况,将来可能也会发生变化。 The answer is meant to give a basic understanding but don't depend on it to be true without checking the behaviour for your specific version/use-case. 答案是为了给出基本的理解,但如果不检查特定版本/用例的行为,则不要依赖它。

Originally QTP's FireEvent was supposed to call IE's non-standard fireEvent method. 最初QTP的FireEvent应该调用IE的非标准fireEvent方法。 On Firefox and Chrome this is implemented using the standard dispatchEvent . 在Firefox和Chrome上,这是使用标准的dispatchEvent实现的。 You should check which events the web site expects to get. 您应该检查网站期望获得哪些事件。 Things get complicated if you mix the event models (the standard DOM level 2 and Microsofts) as explained in this blog post . 如果您按照本文中的说明混合事件模型(标准DOM级别2和微软),事情会变得复杂。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM