I have this web code:
<a id="btn">Click</a>
<script>
$('document').ready(function() {
$('#btn').click(function() {
...
location.search = $.params({click: '1'});
});
});
</script>
This code work perfectly in Chrome.
But I want to test it with HtmlUnit. I wrote:
page= (HtmlPage) ((HtmlAnchor) page.getDocumentElement().querySelector("#btn")).click();
assertThat(page.getUrl().getQuery(), containsString("click=1"));
This code works randomly. Sometime the test passed and sometimes failed. I think it is due because of the asynchronous call to JS, but I couldn't solve it.
So how can I test it?
Besides, there is better solution to test web site insted HtmlUnit? HtmlUnit disappointed...