3

I've been using wicketTester.getServetResponse.getDocument to get the text of the current page for testing, only to find that after an ajax request it is set to the ajax response, not the whole page.

Is there any way to get a representation of the whole rendered page, as the browser would be seeing it after the ajax manipulation?

Duncan McGregor
  • 17,665
  • 12
  • 64
  • 118
  • I see now that that this is really a duplicate of http://stackoverflow.com/questions/6413022/how-do-i-query-the-text-of-an-element-component-using-wickettester - where the page is text of the root element. – Duncan McGregor Jul 05 '11 at 07:12

3 Answers3

2

With WicketTester, you can simulate an Ajax call and see that your app sends the correct Ajax response. But it doesn't really exercise the ajax.

So I don't believe there's a way to get that from WicketTester.

If you actually need to test the app all the way to the UI including Ajax/javascript effects on the rendering, you likely need to use something like Selenium for that portion of your testing.

Don Roby
  • 40,677
  • 6
  • 91
  • 113
  • It's not exercising the Ajax that I'm after, but getting the page source after, for example, I've shown a panel with Ajax. Given the page state is held on the server I'm thinking that this corresponds to what would be served if I refreshed the whole page? – Duncan McGregor Jul 04 '11 at 18:09
  • The page state is not kept as an entire rendered page in html, and I don't think WicketTester provides a means to get the current state of the html after an ajax response. – Don Roby Jul 04 '11 at 18:41
  • I was afraid that was the case. Maybe I'm going to have to simulate a get of the current URL. – Duncan McGregor Jul 04 '11 at 20:28
2

Thinking the Wicket way I hope the following approach should work:

  1. #startPage(YourPage.class)
  2. do some Ajax calls
  3. #startPage(wicketTester.getLastRenderedPage())
  4. wicketTester.getLastRenderedPageAsString()

The idea is: you start a page for testing, the first response is complete page response, then you do some Ajax calls which change some models around, then you start the last rendered page as an instance - this way it will render the page with the updated models from the Ajax calls.

martin-g
  • 17,243
  • 2
  • 23
  • 35
  • Where getLastRenderedPageAsString is getServletResponse.getDocument? So this is performing the operations and then refreshing the now modified page. I'll give it a go thanks. – Duncan McGregor Jul 04 '11 at 22:55
1

The trouble is that you can put any Javascript in the response to an Ajax call. But if you don't want to deal with that, you can save the original full-page DOM, iterate through the objects in the Ajax response, find them by id in the full DOM and replace them with the new versions.

How useful this would be, I don't know, my guess would be not very. so I'd probably go with Selenium too.

biziclop
  • 48,926
  • 12
  • 77
  • 104
  • I've been quite happy with WicketTester except for how hard it is to find components. Maybe I'll fall back on regexp matches on I'd paths... – Duncan McGregor Jul 04 '11 at 22:46