Now that the TestCase is pointed at your application, you can navigate to a particular resource to ensure that it exists, and contains the content you expect. For example, if your application starts at index. Now that we can access the Login page, we can use JWebUnit to fill out the form and assert that it works as expected.
For pages with more than one form, JWebUnit will usually establish which form is being worked with implicitly from the form elements being accessed.
You can also set the form explicitly by form ID or name:. You can assert the presence of and navigate to windows by name. For instance, if clicking on a button on the root page should open a window, you could test for this and go to the popup window as follows:. Once you have navigated to the page you wish to test, you can call the assertions provided by JWebUnit to verify it's correctness. A number of assertions are provided by JWebUnit to validate the contents of tables on a page.
You can simply check for the presence of text within a table, or check layout of all or a portion of the table. HttpUnit is used to purge empty rows and columns from the actual table before comparison, so you may leave spacer cells and rows out of your check.
The below test validates against this html table the table id attribute is "ageTable" :. If you need to validate non-blank table cells that span more than a single column, a set of classes are provided which represent expected tables, rows, and cells. JWebUnit allows you to check for the presence of any html element by its id, or for text in an element. This can be a useful trick to check for the presence of some logical part of the page.
Even in the case of free floating text, a span element can be used to surround the text and give it a logical id:. Another useful testing trick is to use property files for your expected values rather than hard-coded strings.
This is especially useful if your application uses property files as a source for static text and messages. The same files can be used to provide the expected values for the tests.
For convenience, most of the JWebUnit assertions that take strings for the expected have an equivalent assertion that will take a property file key. You can use the TestContext to set the bundle to be used as well as the Locale default is Locale. Whether to check for a given logical chunk of text by hard-coded string, property file lookup, or by use of an element id is up to you.
Last Published: Version: 3. TestCase; import net. Selecting the plugin you want to use JWebUnit can use different plugins to execute the tests you write. Only one line makes the difference: import net. TestingEngineRegistry; import org.
Before; import static net. Navigating Your Web Application The primary way that JWebUnit allows you to test your web application is through navigation of the application itself. Working With Forms Now that we can access the Login page, we can use JWebUnit to fill out the form and assert that it works as expected.
This includes navigation via links, form entry and submission, validation of table contents, and other typical business web application features. The simple navigation methods and ready-to-use assertions allow for more rapid test creation than using only JUnit or HtmlUnit.
And if you want to switch from HtmlUnit to other plugins such as Selenium available soon , there is no need to rewrite your tests. The current version of JWebUnit is 3. This is the "stable" version of JWebUnit, and requires Java 1. You may then test your web application by importing JWebUnit static helpers, and running these test cases with JUnit:. JWebUnit aims to be an active project with a vibrant community. As such we are looking for contributors , especially help in implementing other plugins such as Selenium.
0コメント