I'd like to unit test (jUnit 4) the behavior of my pages when the browser's back button (or forward or refresh) is clicked.

Can I somehow simulate the browser's back/forward/refresh buttons in a unit test? Is there a utility class that provides such functionality?

2nd Edit:

I understand that the Wicket test facilities don't simulate a browser with a full history. From my understanding I would need the following two things to simulate a browser's behavior from a unit test:

(1) Wicket has to tell me what exact request (e.g. URL) is made when I call WicketTester.startPage() or WicketTester.clickLink().

(2) Wicket has to process the same request again, e.g. by accepting the URL previously recorded by (1).

I want to do this in a way that is compatible with WicketTester, FormTester and so on as I'm using the component finders, asserts, and more nice functionality in these classes. That means that I have to issue the requests from Wicket facilities and not from external clients like HttpUnit / HtmlUnit / Selenium.

Was it helpful?


You cannot simulate "back" functionality in wicket unit tests, it is completely out of the scope of what wicket does, you can however test almost anything that will happen when you click back

post something more specific about what you are trying to test, generally a back button will just give you a bunch of "detached" components in wicket, and you can test those


This is pretty certainly not supported by WicketTester, which explicitly uses a dummy WebApplication not supporting the back button to save resources.

I suspect it would be painful to simulate in Wicket...

Your best bet might be to use a browser-based testing tool like Selenium RC. I haven't tried it myself, but it does have a goBack() method that will simulate a click on the browser back button.

Check out HtmlUnit, you can imitate back and forward events using the History class.

public void testHistory() throws IOException {
    // Create a web client
    final WebClient webClient = new WebClient();

    // Surf to a page
    final HtmlPage page = webClient.getPage("");

    // Click "Get started" link

    // Get History
    History history = webClient.getCurrentWindow().getHistory();

    // Current page

    // Go back one page
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top