Simulate the Back / Forward / Refresh button in unit test using Wicket

I would like to unit test (jUnit 4) the behavior of my pages when I click the browser back button (or redirect or update).

Is there any way to simulate the browser buttons back / forward / update in unit test? Is there a utility class that provides such functions?

2nd Edit:

I understand that the Wicket test tools do not simulate a browser with a full history. In my opinion, to simulate browser behavior with unit test:

I will need the following two things:

(1) The cabinet should tell me what exact request (e.g. URL) is made when I call WicketTester.startPage()or WicketTester.clickLink().

(2) The gate should again process the same request, for example. by accepting the URL previously written in (1).

I want to do this in a way that is compatible with WicketTester, FormTesteretc., since I use search components, assertions, and nicer functionality in these classes. This means that I have to send requests from Wicket, and not from external clients such as HttpUnit / HtmlUnit / Selenium.

+3
source share
3 answers

You cannot mimic the functionality of the “back” in the wicket tests, it completely goes beyond what the wicket does, however you can check almost everything that happens when you press

- , , "" "" ,

0

, , WicketTester, WebApplication, "" .

, Wicket...

, Selenium RC. , goBack(), .

+1

HtmlUnit, History.

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

    // Surf to a page
    final HtmlPage page = webClient.getPage("http://htmlunit.sourceforge.net/");

    // Click "Get started" link
    page.getAnchorByHref("gettingStarted.html").click();

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

    // Current page
    assertEquals("http://htmlunit.sourceforge.net/gettingStarted.html",
                 history.getUrl(history.getIndex()).toString());

    // Go back one page
    history.back();
    assertEquals("http://htmlunit.sourceforge.net/",
                 history.getUrl(history.getIndex()).toString());
}
+1

Source: https://habr.com/ru/post/1734595/


All Articles