randyl · GitHub

I have a jQuery UI autocomplete widget where I type a few characters to produce a menu of suggestions. I'm trying to test that a suggestion is highlighted when mousing over it. However, the test fails because it never sees the highlighting class appear, even though the class does appear in the browser. I've made a test case using a demo from jQuery UI's website:

import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlInput;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import java.util.List;
import org.junit.Test;
import static org.junit.Assert.*;
public class AutocompleteTest {
  @Test
  public void testMouseOver() throws Exception {
    final WebClient webClient = new WebClient();
    HtmlPage page = webClient.getPage("https://jqueryui.com/resources/demos/autocomplete/default.html");
    webClient.waitForBackgroundJavaScript(5000);
    HtmlInput input = page.getFirstByXPath("//input[@id='tags']");
    input.type("ja");
    webClient.waitForBackgroundJavaScript(5000);
    HtmlElement item = page.getFirstByXPath("//ul[@id='ui-id-1']/li");
    assertEquals( "Java", item.getTextContent() );
    page = (HtmlPage) item.mouseOver();
    page = (HtmlPage) item.mouseMove();
    webClient.waitForBackgroundJavaScript(5000);
    HtmlElement div = page.getFirstByXPath("//ul[@id='ui-id-1']/li/div");
    assertEquals( "ui-menu-item-wrapper ui-state-active", div.getAttribute("class") );
  }
}

When I run this code, it fails with the following message:

org.junit.ComparisonFailure: expected:<ui-menu-item-wrapper[ ui-state-active]> but was:<ui-menu-item-wrapper[]>

The missing "ui-state-active" class is what makes the suggestion highlighted. It does highlight correctly in the browser.

Read the original on github.com ↗