Wicket Bench 0.5 - Features

Wicket Editor


Wicket editor

Wicket editor is a tabbed editor that allows a quick switch between java/html/property files. A recommended configuration is to set Wicket editor launcher as a default editor for Java files (from Window->Preferences->General->Editors->File Associations). This launcher will open a normal Java editor for regular Java classes. The tabs in editor can be swiched using ctrl-alt-, and ctrl-alt-. keybindings. A new html or properties file can be created using shift-ctrl-alt-, and shift-ctrl-alt-. keybindings.

Preview pane is wicket:preview attribute aware. It is possible to include other markup files for preview by adding wicket:preview attribute to wicket component tag:

      <span wicket:id="myPanel" wicket:preview="../MyPanel.html" />
      

There's no limit how deep the previewed hierarchies can be. Preview pane can also inline non-packaged CSS and relocate images. A common way for instance is to keep some files in src/webapp/css/ and src/webapp/images/. The context root and css files can be configured for the plugin from Properties -> Wicket. If configured, the preview pane will include them. WicketEditor adds toggle buttons to toolbar to enable/disable these features.

Wicket editor

Wizards


Create Wicket Project

A new Wicket project can be created using a wizard. The wizard is activated from File -> New -> Other -> Wicket

The wizard creates a Java project and sets the classpath containing Wicket jar and its dependencies. A template application class is created to a desginated package. web.xml is created to a context root folder.

Create Wicket project


Create Wicket Panel

Wicket panel wizard is used to create a panel Java class and its html template.

Create Wicket panel


Create Wicket WebPage

Wicket WebPage wizard is used to create a WebPage Java class and its html template.

All templates can be edited from Window -> Preferences -> Wicket -> Templates



Form generation

A form Java code can be generated from provided Html markup file. Select a form markup from Html file, right click and select 'Generate Wicket form code'. This will open a popup containing a sample implementation of the form. This can be copy-pasted to a destination Java file and finished there.

Form generation

Selecting above form will generate:

Form generation

Quick fixes


Quick fixes for problem markers

Quick fixes to create Wicket Panel, WebPage or Form are installed at problem locations where an instance of Wicket component is needed.

Quick fixes

Refactoring


Rename

Rename refactoring has been enhanced so that it renames non-java based resources with the same name as the type being renamed when the type inhertis from wicket.MarkupContainer


Parser


Markup parser

Wicket's markup parser is used to validate the correctness of associated markup file. The parser must be activated by configuring builder 'wicketbench.associatedMarkupAuditor' for the Wicket project. Please, see post installation steps from project page.

Parse error


Launchers


Design time launcher

Wicket Bench uses JUnit test case to launch the component that is under development.

You should extend from WicketTestCase (which extends JUnit's TestCase) to provide a factory to create the component. This component is then launched in isolation from rest of the application.

        public IComponentFactory createFactory() {
            return new IComponentFactory() {
                public SearchPanel createComponent(String panelName) {
                    return new SearchPanel(panelName);
                }
            };
        }
      

Remember to add wicket-bench-api.jar and its dependencies to your project's build path. With maven2 this can be done by putting following to your pom.xml.

      
      <project>
        <repositories>
          <repository>
            <id>laughing-panda</id>
            <name>Laughing Panda</name>
            <url>http://www.laughingpanda.org/maven2/</url>
          </repository>
          <dependencies>
            <dependency>
              <groupId>wicket-bench</groupId>
              <artifactId>wicket-bench-api</artifactId>
              <version>0.5.0</version>
            </dependency>
          </dependencies>       
        </repositories>     
      </project>
      
      

Launcher

The launcher opens an Eclipse view containing a simple browser. This browser opens a page where the component can be tested. The view can be detached to its own window by right clicking the tab and selecting 'Detached'. Open url 'http://localhost:8090/wicket-bench' if you want see the page in a real browser.

browser


Selenium launcher

Wicket bench integrates Selenium remote control functional testing tool to automate testing of Wicket components.

        public void testDictionaryPanelOnSelenium() {
            openSelenium(createFactory());
            getSelenium().type("query", "ca");
            getSelenium().click("submit");
            getSelenium().waitForPageToLoad("5000");
            String text = getSelenium().getHtmlText();
            assertTrue(text.contains("kissa"));
            assertTrue(text.contains("auto"));
        }
        

See this test case for a more complete example.

Windows users should propably go to Tools->Internet Options->Temporary Internet Files->Settings and check the "Every visit to the page" option. Otherwise IE caches the Selenium requests.

Usage:

  1. Start Selenium server: java -jar selenium-server.jar
  2. Write a Selenium test (see example)
  3. Write a launcher (not necessary but recommended, see: example)
  4. Run tests with normal JUnit launcher (Run As -> JUnit test)

Selenium integration contains Wicket specific methods to make it easier to do more robust assertions:

        Component getComponent(); 
        Component getComponent(String path); 
        ListItem getComponent(ListView list, int index);
        Component getComponent(ListView list, int index, String pathInItem);
        String id(String path);
        

Examples:

        public void testSearchResults() {
            openSelenium(createFactory());
            getSelenium().type("query", "wicket");
            getSelenium().click("submit");
            getSelenium().waitForPageToLoad("5000");
            ListView listView = (ListView) getComponent("result:listing");
            // Assert that model contains correct values.
            List results = listView.getList();
            assertEquals(Arrays.asList("wicket", "rocks"), results);
            // Assert that HTML contains correct elements
            for (Iterator i = listView.iterator(); i.hasNext(); ) {
                assertTrue(getSelenium().isElementPresent(id(i.next().getPageRelativePath())));
            }
        }