문제

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.

도움이 되었습니까?

해결책

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

다른 팁

fabric.js .

캔버스에 물건을 그립니다. SVG 가져 오기 / 수출이 있습니다.
그것은 '객체', 일반적인 SVG 모양과 경로를 처리합니다.전체 SVG 표준 (예 : 글꼴)은 지원되지 않지만 하위 집합 만 사용해야합니다.

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

@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());
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top