Selenium 或 WatiN 是否具有像 QTP 的Setting.WebPackage(“ReplayType”) = 2 这样的属性?

发布于 2024-08-21 04:43:30 字数 300 浏览 4 评论 0原文

我正在测试的应用程序中有一些按钮和菜单需要实际单击才能发送所有信息,而 FireEvent 样式单击似乎并不能解决问题。 TestPartner 和 QTP 都可以使用实际点击。 TestPartner 总是(慢)执行此操作,而 QTP 通过将“ReplayType”从 1 更改为 2 来执行此操作。

Setting.WebPackage("ReplayType") = 2

所以我的问题是。有没有办法在 WatiN 或 Selenium 中获得真正的点击次数?我一直无法找到该选项。

谢谢你, 乔什

There are some buttons and menus in the application I am testing that require actual clicks to send all the 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

比忠 2024-08-28 04:43:30

Selenium 2 可以触发真实的点击,而不是像 Selenium 1 那样尝试合成点击和击键。它与操作系统进行了大量交互来本地执行这些操作,这解决了许多 Selenium 1 问题,例如它是否触发了单击或 mouseup 或 mousedown?

硒 2 处于第二 α 相,目前相当稳定。您可以从 http://code.google.com/p/selenium 获取 Selenium 2.0a2 /下载/列表

我一直在研究 .NET 绑定,并且对它们的进展非常满意。

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.

童话里做英雄 2024-08-28 04:43:30

ReplayType设置为device(2)时,QTP实际上移动鼠标并执行单击(您可以看到鼠标光标移动)。我对 Selenium 不太熟悉,但据我所知,重播是在纯 JavaScript 中完成的,因此它可以触发 DOM 事件(就像 QTP 在事件 ReplayMode 中所做的那样),但它不能模拟 真正的点击就像QTP那样。

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.

顾挽 2024-08-28 04:43:30

使用 WatiN,可以访问 IE 窗口中元素的“本机”界面。使用它您可以获取任何元素的屏幕坐标。

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);
}

要使用它:

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

显然该元素必须是可见的。我不知道如何立即检查这一点,但我认为您可以更改正文的scrollTop 和scrollLeft 属性以进行滚动。

您还需要一种方法来实际执行点击,但 stackoverflow 上可能已经有答案。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文