使模态对话框脚本适应 Firefox

发布于 2024-11-01 02:21:07 字数 775 浏览 6 评论 0原文

我正在调整我的回归测试来测试 Firefox 中的网络应用程序。最大的障碍似乎是如何自动化 Firefox 中的模式对话框。

在 ie 中,我使用以下脚本的变体,但它在 Firefox 中不起作用。有没有可以同时在 ie 和 firefox 中使用的替代方案?

popup=Thread.new {
    autoit=WIN32OLE.new('AutoItX3.Control')
    ret=autoit.WinWait(title,"",60)
    if (ret==1)
        puts "There is popup."
        autoit.WinActivate(title)
        button.downcase!
        if button.eql?("ok") || button.eql?("yes") || button.eql?("continue")
            autoit.Send("{Enter}")
        else
            autoit.Send("{tab}")
            autoit.Send("{Enter}")
        end
    elsif (ret==0)
        puts "No popup, please check your code."
    end
}
at_exit { Thread.kill(popup) }
end

   button.click_no_wait

   check_for_popups("Message from webpage", "OK")    

I'm adapting my regression tests to test a web app in firefox. The biggest stumbling block seems to be how to automate the modal dialogs in firefox.

In ie I use variations of the script below, but it doesn't work in Firefox. Is there an alternative that will work in both ie and firefox?

popup=Thread.new {
    autoit=WIN32OLE.new('AutoItX3.Control')
    ret=autoit.WinWait(title,"",60)
    if (ret==1)
        puts "There is popup."
        autoit.WinActivate(title)
        button.downcase!
        if button.eql?("ok") || button.eql?("yes") || button.eql?("continue")
            autoit.Send("{Enter}")
        else
            autoit.Send("{tab}")
            autoit.Send("{Enter}")
        end
    elsif (ret==0)
        puts "No popup, please check your code."
    end
}
at_exit { Thread.kill(popup) }
end

   button.click_no_wait

   check_for_popups("Message from webpage", "OK")    

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

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

发布评论

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

评论(2

红衣飘飘貌似仙 2024-11-08 02:21:07

鉴于您正在谈论一个 javascript 创建的对话框,我真的不得不问,实际测试这些对话框是否有很多价值?

它基本上相当于测试浏览器的功能

如果您正在谈论此处描述的弹出窗口类型 http://wiki.openqa.org/display/WTR/JavaScript+Pop+Ups 那么我认为第一个解决方案,覆盖 javascript 很可能是您最好的跨平台选择。

像这样的模式对话框的问题在于,它们基本上是一个 UI,即使是在操作系统级别发生的,它不再位于浏览器 DOM 内部,因此您需要特定于操作系统的工具(例如依赖于 win32ole 的工具) ,例如 autoit),以便生成与本机 UI 和单击按钮、发送击键等必要的交互。我认为所提供的大多数解决方案应该在 Windows 上与 FF 一起使用(正确重命名预期的窗口标题等),但会失败在 Mac 或 *nix 操作系统上。这意味着您需要为每个操作系统提供不同的解决方案,这很痛苦。

验证您是否可以在页面的 HTML 中找到可以触发事件的正确内容可能会更容易,这样您就知道事件会被触发,然后覆盖一些东西,这样它就不会被触发。毕竟,当在 javascript 中调用 alert('This is an Alert box') 之类的内容时,验证浏览器是否弹出本地对话框并不是您真正的工作。您担心的是,在 HTML 中,给定元素被编码为触发所需的事件,例如,有类似这样的 onClick = 'javascript:x = recognize('Do you确实想这样做');" 附属于元素

Given you are talking about a javascript created dialog, I really have to ask, is there a lot of value in actually testing those?

It basically amounts to testing the functionality of the browser

If you are talking about the type of popups described here http://wiki.openqa.org/display/WTR/JavaScript+Pop+Ups then I think the first solution, of overriding the javascript may well be your best cross platform option.

The problem with modal dialogs like this is that they are basically a UI even that is happening out at the OS level, it's no longer inside the browser DOM, and thus you need tools that are specific to the OS (like stuff that depends on win32ole, such as autoit) in order to generate the necessary interaction with the native UI and click buttons, send keystrokes etc. Most of the solutions presented should I think work with FF on windows (with proper renaming of expected window titles etc) but would fail on a mac or *nix OS. That means you need a different solution for each OS, which is a pain.

It might simply be easier to verify you can find the proper stuff that would fire the event in the HTML of the page, so you know an event WOULD be fired, and then override things so it isn't. After all it's not really your job to validate that the browser pops up a local dialog when something like alert('This is an alert box') is invoked in javascript. Your concern is that in the HTML a given element is coded to fire off the event that is needed e.g. that there's something like this onClick = 'javascript:x = confirm('Do you really want to do this');" affiliated with the element

我纯我任性 2024-11-08 02:21:07

我在 Firefox 中遇到了类似的问题(并且我必须在 Firefox 中进行测试)。我可以看到调用 Javascript 的代码,但是当我尝试如上所述重写时,什么也没有发生。有什么解决方法吗? Watir 预计会有更新吗? ;-)

I am experiencing a similar problem in Firefox (and I do have to test in Firefox). I can see the code calling the Javascript but when I try to override as described above nothing happens. Is there any kind of a workaround for this? Anticipated updates to Watir? ;-)

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