我怎么能在一个Web应用程序测试的上下文菜单的功能? [英] How can I test context menu functionality in a web app?

查看:147
本文介绍了我怎么能在一个Web应用程序测试的上下文菜单的功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我玩,有一个文本菜单(右键单击)一个Grails应用程序。
上下文菜单是用克里斯Domigan的的jQuery插件的ContextMenu 。

I'm playing with a grails app that has a contextmenu (on right-click). The context menu is built using Chris Domigan's jquery contextmenu plugin.

虽然contextmenus做实际工作,我想有自动测试,我可以不知道如何做到这一点。

While the contextmenus do actually work, I want to have automated tests, and I can't work out how to do it.


  • 我试过硒2.05a(即webdriver的),但没有单击鼠标右键的方法。

  • 我注意到HtmlUnit的方法,单击鼠标右键,但我似乎并没有能够检测到点击之前和之后的DOM中的任何区别。

推荐答案

虽然我希望能够做到这一点在Internet Explorer或Firefox为好,主要用途将是的HtmlUnit。这是很好的化的HtmlUnit的HtmlElement有一个单击鼠标右键()方法,但不幸的是它的保护,因此无法从webdriver的访问包裹HtmlUnitWebElement。

While I'd like to be able to do it in Internet Explorer or Firefox as well, the main usage will be HtmlUnit. It's nice that the HtmlUnit HtmlElement has a rightClick() method, but unfortunately it's protected and so not accessible from the WebDriver wrapped HtmlUnitWebElement.

我写了一个黑客,使之获得,所以现在我可以调用单击鼠标右键(),但只有当它与运行的HtmlUnit工作 - 而不是IE或FF

I wrote a hack to make it accessible, and so now I can call rightClick(), although it only works if it's running with HtmlUnit - not IE or FF.

// Needs to be in this package to get access to the element
package org.openqa.selenium.htmlunit;

import com.gargoylesoftware.htmlunit.html.HtmlElement;

public class OpenHtmlUnitWebElement extends HtmlUnitWebElement {

    // Provide a constructor, even though we don't really need it.
    public OpenHtmlUnitWebElement(HtmlUnitDriver parent, HtmlElement element) {
        super(parent, element);
    }

    // this is the method we really want.
    public static HtmlElement using(HtmlUnitWebElement huwe) {
        return huwe.element;
    }
}

现在我的(常规)测试看起来是这样的:

Now my (groovy) test looks like this:

import static org.openqa.selenium.htmlunit.OpenHtmlUnitWebElement.using

...

def itemWithContextMenu = driver.findElement(By.id('theId'))
if (itemWithContextMenu instanceOf HtmlUnitWebElement) {
  using(itemWithContextMenu).rightClick()
  def contextMenu = driver.findElement(By.id('jqContextMenu'))
  assert ...
}

这篇关于我怎么能在一个Web应用程序测试的上下文菜单的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆