You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Dave Kallstrom <DK...@widen.com> on 2003/11/14 15:10:41 UTC

HtmlUnit

I was wondering if anyone is currently using htmlunit for testing tapestry
applications? I have a few questions concerning form submittal. My tests
find the form and input fields but fail to return the correct page after
calling the form submit method. 

Or perhaps someone could suggest a better testing tool for tapestry apps.

Dave Kallstrom
dkallstrom@widen.com
Software Engineer
Widen Enterprises
608.443.5448


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: HtmlUnit

Posted by Bill Lear <ra...@zopyra.com>.
On Friday, November 14, 2003 at 08:10:41 (-0600) Dave Kallstrom writes:
>I was wondering if anyone is currently using htmlunit for testing tapestry
>applications? I have a few questions concerning form submittal. My tests
>find the form and input fields but fail to return the correct page after
>calling the form submit method. 
>
>Or perhaps someone could suggest a better testing tool for tapestry apps.

I have used jWebunit, based upon HttpUnit and have found it simple,
robust, and very useful.

Failing to return a correct page sounds very strange.  What page are
you getting instead, if you are getting a page?

I did find it very helpful to add ids to my HTML elements, to aid in
element retrieval.  Here is a test case I have written using
jWebunit:


import net.sourceforge.jwebunit.ExpectedRow;
import net.sourceforge.jwebunit.ExpectedTable;
import net.sourceforge.jwebunit.WebTestCase;

import dao.DAO;
import dao.DAOException;
import dao.DAOFactory;
import dao.SortOrder;
import dao.mysql.test.MockMySQLDAOFactory;
import model.Employee;
import ui.Display;

public class ECIWebTest extends WebTestCase {
    private DAO dao;

    public ECIWebTest() throws DAOException {
        DAOFactory factory = new MockMySQLDAOFactory();
        dao = factory.createDAO();
    }

    private ExpectedTable getExpectedTable(SortOrder sortOrder)
        throws Exception {
        Employee[] employees = dao.getEmployees(sortOrder);

        ExpectedTable expectedTable = new ExpectedTable();
        expectedTable.appendRow(new ExpectedRow(new Object[] {
            "Name", "Office Phone", "Dept", "Email"}));

        for (int i = 0; i < employees.length; ++i) {
            Employee employee = employees[i];

            String name = Display.getEmployeeName(employee, sortOrder);

            expectedTable.appendRow(new ExpectedRow(new Object[] {
                name, employee.getOfficePhone(),
                employee.getDepartment(), employee.getEmail()}));
        }

        return expectedTable;
    }

    public void testECI() throws Exception {
        getTestContext().setBaseUrl("http://localhost:8080");

        // submit #1
        beginAt("eci/app");
        assertTitleEquals("Employee Contact Database");
        assertFormPresent("sortOrderForm");
        assertOptionsEqual("sortOrderSelect", new String[] {
            "Last Name", "First Name", "Department", "Email Address"});

        assertTableEquals("summaryTable",
                          getExpectedTable(SortOrder.BY_LAST_NAME));
        assertLinkPresentWithText("Smith, William (Bill)");

        // submit #2
        selectOption("sortOrderSelect", "First Name");
        assertLinkPresentWithText("William (Bill) Smith");
        assertTableEquals("summaryTable",
                          getExpectedTable(SortOrder.BY_FIRST_NAME));

        // submit #3
        selectOption("sortOrderSelect", "Department");
        assertTableEquals("summaryTable",
                          getExpectedTable(SortOrder.BY_DEPARTMENT));
        assertLinkPresentWithText("Smith, William (Bill)");

        // submit #4
        selectOption("sortOrderSelect", "Email Address");
        assertTableEquals("summaryTable",
                          getExpectedTable(SortOrder.BY_EMAIL_ADDRESS));
        assertLinkPresentWithText("Smith, William (Bill)");

        // submit #5
        clickLinkWithText("Smith");

        // check detail page for Smith
        assertTableEquals("detailTable", new ExpectedTable(new Object[][] {
            {"Office Ext:", "6207"},
            {"Cell Phone:", "512.555.5585"},
            {"Fax:", "512.555.6450"},
            {"Office Address:",
             "8303 N. Foobar, Suite A-900\nAustin, Texas  78759"},
            {"Email Address:", "wlear@foobar.net"},
            {"Home Phone:", "512.555.5823"},
            {"Home Address:", "711 Foobar Drive\nAustin, Texas  78746"},
            {"Department:", "Engineering"}
        }));
    }
}

I have not, as yet, toyed with form submission.


Bill

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org