开发者

Does Selenium or WatiN have property like QTP's Setting.WebPackage("ReplayType") = 2?

开发者 https://www.devze.com 2022-12-19 15:54 出处:网络
There are some buttons and menus in the application I am testing that require actual clicks to send all th开发者_高级运维e information through and FireEvent style clicking does not seem to cut it.Both

There are some buttons and menus in the application I am testing that require actual clicks to send all th开发者_高级运维e information through and FireEvent style clicking does not seem to cut it. Both TestPartner and QTP can use actual clicks. TestPartner does this always (slow) and QTP does this by changing the 'ReplayType' to 2 from 1.

Setting.WebPackage("ReplayType") = 2

So my question is. Is there anyway to get real clicks in WatiN or Selenium? I have not been able to find that option.

Thank You, Josh


Selenium 2 can fire real clicks instead of trying to synthesize the clicks and keystrokes like Selenium 1 does. It does a lot of interaction with the OS to do these things natively which over comes a lot of the Selenium 1 issues like is it firing a click or mouseup or mousedown?

Selenium 2 is in its 2nd alpha phase and is quite stable at the moment. You can get Selenium 2.0a2 from http://code.google.com/p/selenium/downloads/list.

I have been working on the .NET bindings and am really happy with the way they are going.


When ReplayType is set to device (2), QTP actually moves the mouse and performs a click (you can see the mouse cursor move). I'm not very familiar with Selenium but from what I know replay is done in pure JavaScript therefore it can fire DOM events (as QTP does in event ReplayMode) but it can't simulate a real click the way QTP does.


With WatiN, it is possible to get to the "native" interface of elements in IE windows. Using that you can get the screen coordinates of any element.

using mshtml; //Add a reference to Microsoft.mshtml that comes with WatiN.
using WatiN.Core.Native.InternetExplorer;

public static System.Drawing.Point GetScreenPoint(IEElement element)
{
    IHTMLElement nativeElement = element.AsHtmlElement;
    IHTMLElement2 offsetElement = (IHTMLElement2)nativeElement;
    IHTMLRect clientRect = offsetElement.getBoundingClientRect();
    IHTMLDocument2 doc = (IHTMLDocument2)nativeElement.document;
    IHTMLWindow3 window = (IHTMLWindow3)doc.parentWindow;

    int windowLeft = window.screenLeft;
    int windowTop = window.screenTop;
    int elementLeft = clientRect.left;
    int elementTop = clientRect.top;
    int width = nativeElement.offsetWidth;
    int height = nativeElement.offsetHeight;

    int clickX = windowLeft + elementLeft + (width / 2);
    int clickY = windowTop + elementTop + (height / 2);

    return new System.Drawing.Point(clickX, clickY);
}

To use it:

Button myButton = browser.Button(Find.ById("myButton"));
System.Drawing.Point clickPoint = GetScreenPoint((IEElement)myButton.NativeElement);
MyClick(clickPoint);

Obviously the element has to be visible. I don't know how to check for that offhand, but I think you can change the scrollTop and scrollLeft attributes of the body to scroll around.

You'll also need a method to actually do the click, but there's probably an answer for that already on stackoverflow.

0

精彩评论

暂无评论...
验证码 换一张
取 消