My understanding was that HtmlUnit 2.15 would support AngularJS pages. I had originally attempted to trial our web pages using the recent Selenium 2.43.1, and found that while the landing page would be rendered, and page elements could be queried, however, attempting to click or invoke controls results in nothing happening. I then tried writing a simple Java app to just drive HtmlUnit 2.15 directly to reduce the layers, but the same problem still exists.
A simple AngularJS page on the public internet is hat.jit.su . On this page, if I have created a scrum room, I want my test scenario to open the page, enter the room number and click "join room". If I use Selenium to automate via any existing browser (Chrome/FireFox/IE) I have no problems.
The basic code I used is as follows:
final WebClient webClient = new WebClient(BrowserVersion.CHROME);
final HtmlPage page = webClient.getPage("http://hat.jit.su");
try {
HtmlInput room_ip = page.getHtmlElementById("roomfield");
List<?> btns = page.getByXPath("//button[@ng-click='enterRoom(room)']");
HtmlButton room_bt = null;
if (!btns.isEmpty())
room_bt = (HtmlButton) btns.get(0);
room_ip.setValueAttribute("63661");
if (room_bt != null)
room_bt.click();
} catch (ElementNotFoundException enfex) {
// Landing page does not have expected elements. END
return;
}
Thread.sleep(10000); // Ugly wait to allow page to load if click worked.
try {
HtmlParagraph room_p = null;
List<?> ps = page.getByXPath("//p[@ng-binding='roomNumber ng-binding']");
if (!ps.isEmpty())
room_p = (HtmlParagraph) ps.get(0);
if (room_p != null)
// We entered room of number: + room_p.getTextContent()
else
// We're not in the room. + page.asXml()
} catch (ElementNotFoundException enfex) {
// Room page wasn't entered. END
return;
}
webClient.closeAllWindows();