How can I test the functionality of the context menu in a web application?

I play with a grails application that has a context menu (right click). The context menu is built using the Chris Domigan jquery contextmenu plugin .

While the context menus really work, I want to have automatic tests, and I cannot figure out how to do this.

  • I tried Selenium 2.05a (i.e. Webdriver), but there is no rightClick method.
  • I noticed that HtmlUnit has a rightclick method, but it seems I can not detect the difference in the DOM between the click and after it.
+4
source share
3 answers

Internet Explorer Firefox, HtmlUnit. , HtmlUnit HtmlElement rightClick(), , , protected WebDriver, HtmlUnitWebElement.

, , rightClick(), , HtmlUnit - IE 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;
    }
}

(groovy) :

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 ...
}
0

WebDriver , - http://code.google.com/p/selenium/issues/detail?id=161

Shift + F10 :

WebElement element = driver.findElement(....);
element.sendKeys(Keys.chord(Keys.SHIFT, Keys.F10));
+5

Ruby Capybara, :

module Capybara
  module Node
    class Element
      def context_click
        @session.driver.browser.action.context_click(self.native).perform
      end
    end
  end
end
0
source

All Articles