2

I am looking for ideas to trigger the actions for fly-out menus using QTP.

I am testing a Web App using QTP. The application has "cascaded" or hierarchical fly-out menu.

e.g. Options->Preferences

While recoding QTP recognizes the end point on the Menu hierarchy (say "Preferences"). But while running the test, firing the WebElement("Preferences").Click does not work.

If I call Link("Options").FireEvent ("onmouseover") it pulls down the Menu, and after that I can highlight the Preferences item, but calling the click even after pulling down the menu fails to trigger the menu action.

Any Ideas to trigger the click action on these menu items would be useful.

Regards,
Adarsha

Motti
  • 110,860
  • 49
  • 189
  • 262
Adarsha
  • 2,267
  • 22
  • 29

5 Answers5

5

If Click doesn't do the job then there are probably other events that the web app is expecting that are not simulated by QTP. One way to work around this is to turn on Web's Device Replay mode:

Setting.WebPackage("ReplayType") = 2 

After this line in the test whenever QTP sees a Click step it will replay it by moving the mouse over the element and simulating a click so all the events that are fired by human beings will be fired.

To go back to the default event replay mode set "ReplayType" to 1.

Motti
  • 110,860
  • 49
  • 189
  • 262
  • By setting the Device Reply mode to reply mouse actions, you will loose the ability to work on other things when QTP is executing. I have dual monitor and usually let the QTP running in secondary monitor while working on other things. But its a nice littel trick to consider. – Adarsha Sep 27 '09 at 02:27
  • 1
    Have you tried working with QTP in a virtual machine? That way using device replay won't steal your mouse. – Motti Sep 28 '09 at 18:58
  • Does this also mean that if the button isn't visible on the screen because it's below the fold (ie: you need to scroll to see it), QTP will find it? – Riddari Aug 09 '10 at 01:10
  • @Riddari, if the button isn't visible on your physical screen but is visible in the virtual display (i.e. if you scroll the RDP window it will be visible) then it will work. I've verified this on Microsoft's mstsc.exe). – Motti Aug 09 '10 at 11:05
2

For the reason of loosing multitasking while QTP is executing, I did not implement with Motti's suggesiton. So instaed I ended up going through the HTML code to see which mouse events are expected by the java script. It turns out i need to call the below sequences:

Link("Options").FireEvent ("onmouseover")
WebElement("Preferences").FireEvent ("onmouseover")
WebElement("Preferences").FireEvent ("onClick")

This trick works really nice, but the risk here is if they change any thing drastically (say instaed of litening to Click if they use onMouseDown) I need to tweak the test script.

Motti
  • 110,860
  • 49
  • 189
  • 262
Adarsha
  • 2,267
  • 22
  • 29
  • 1
    You may consider creating custom support for this menu using Web Extensibility (that way you can parametrize on the menu item). – Motti Sep 27 '09 at 08:15
1

I have one more option. use this to click on any object.

Set objMenu = Browser("Browser").Page("Pagel").WebElement("Menu_ELM")
Set objDeviceReplay1 = CreateObject("mercury.devicereplay")
x = objMenu.GetROProperty("abs_x")
y = objMenu.GetROProperty("abs_y")
objDeviceReplay1.MouseClick x + 35 , y + 5,0
Set objDeviceReplay1 = Nothing
Motti
  • 110,860
  • 49
  • 189
  • 262
  • Please try to format the code when you post reply. That's not hard. Also if you look at Motti's answer below he already suggested Device Replay mode. That has its own problems, one being it will steal the mouse when the script is running, and its very rudimentary way of doing things, since you are replying on physical coordinates of the objects. – Adarsha Dec 30 '10 at 17:52
0

Here's what I did with a similar problem:

Set desPrefLink = Description.Create
    desPrefLink("micclass").value = "Link"
    desPrefLink("innertext").value = "Preferences"

Browser(X).Page(Y).Link(desPrefLink).Click()

It might not work with a more dynamic Javascript menu, though.

Riddari
  • 1,713
  • 3
  • 26
  • 57
  • Exactly.. In my case desPrefLink is not visible to QTP until the onmouseover event is fired on Options link. – Adarsha Aug 08 '10 at 21:08
0

I had a similar situation handled in slightly different manner, first click on the parent link Options then trigger the fireevent onclick with the help of ordinal identifier

eg: browser().page().link(options).click

browser().page().link("name:=preferences","html tag:=A","index:=X").firevent "onclick"

This would ideally load the intended parent link & would be helpful in triggering fire event on click- Hope this helps.

nandesh kalyankar
  • 302
  • 1
  • 5
  • 23