現(xiàn)在就可以查看 jWebUnit API 的實(shí)際應(yīng)用了。我將帶您研究一個(gè)示例應(yīng)用程序,幫助您更好地理解 jWebUnit 的真正威力。這個(gè)應(yīng)用程序是一個(gè)測試用例,用于打開一個(gè) Google 搜索頁面并搜索文本 HttpUnit。應(yīng)用程序需要測試以下場景:
打開 Google 主頁 http://www.google.com。
確定該頁包含一個(gè)名為 q 的表單元素。(在 Google 的主頁上,名為 q 的文本框是接受用戶查詢輸入的文本框。)應(yīng)用程序用這個(gè)元素輸入搜索參數(shù)。
C:/temp>java com.jweb.test.GoogleTest "HttpUnit Hwee" .F Time: 5.338 There was 1 failure: 1) testSearch(com.jweb.test.GoogleTest)junit. framework.AssertionFailedError: Link with text [HttpUnit Hwee] not found in response. at net.sourceforge.jwebunit.WebTester. assertLinkPresentWithText(WebTester.java:618) at net.sourceforge.jwebunit.WebTestCase. assertLinkPresentWithText(WebTestCase.java:244) at com.jweb.test.GoogleTest.testSearch(GoogleTest.java:36) at sun.reflect.NativeMethodaccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at com.jweb.test.GoogleTest.main(GoogleTest.java:19)