nate-ward
nate-ward

Reputation: 11

Does a jquery form submit not register with HttpUnit

I'm using jQuery in a class project to catch a form submission and add some additional data to the form. Functionally the system works fine. There are no errors and all outputs are as they expected. We are also required to use HTTPUnit to test our system. In my test (which will shortly follow) I can find the form ok, send in test values and submit. I then have a check which looks for expected results on the web page. I am not getting this statement. Like I said earlier, I can go in and manually run through this exact test and get the output I want but going through httpunit, I get a failure.

This is the html form.

<form action="" method="post" id="cc_form">
<label for="cardType">Card Type:</label>
  <select name="cardType">
    <option value="Visa">Visa</option>
    <option value="Mastercard">Mastercard</option>
    <option value="Discover">Discover</option>          
    <option value="American Express">American Express</option>
  </select><br><br>
<label for="cardNumber">Card Number:</label>
<input type="text" name="cardNumber"/><br><br>
<label for="cvvCode">CVV Code:</label>
<input type="text" name="cvvCode"/><br><br>
<label for="cardHolder">Card Holder Name:</label>
<input type="text" name="cardHolder"/><br><br>
<label for="address">Billing Address:</label>
<input type="text" name="address"/><br><br>
<input type="submit" class="subsub" id="submitcc" value="Submit" /><br><br>
</form>

This is the applicable jQuery I'm using.

$('#cc_form').submit(function() {
    $(this).append('<input type="hidden" name="payment_type" value="cc_form" /> ');
    return true;
});

This is the httptest (one of) that's failing for this issue

public void testIncorrectCVVCode() throws Exception{
    WebConversation wc = login("31", "pw");
    WebResponse wr = wc.getCurrentPage();

    wr = wr.getLinkWith("Billing Statements").click();
    wr = wr.getLinkWith("Oct 10, 2005").click();
    wr = wc.getCurrentPage();

    Button btn = (Button)wr.getElementWithID("ccBtn");
    btn.click();
    wr = wc.getCurrentPage();

    WebForm form = wr.getFormWithID("cc_form");
    form.setParameter("cardHolder", "steven");
    form.setParameter("address", "2 forrest dr");
    form.setParameter("cardType", "Visa");
    form.setParameter("cardNumber", "2323232323232323");
    form.setParameter("cvvCode", "23");
    wr = form.submit();

    //wr = wc.getCurrentPage();
    assertTrue(wr.getText().contains("Invalid Card CVV"));
}

Any help would be welcomed.

PS. This is the failure I'm getting out of httpunit

junit.framework.AssertionFailedError
at junit.framework.Assert.fail(Assert.java:55)
at junit.framework.Assert.assertTrue(Assert.java:22)
at junit.framework.Assert.assertTrue(Assert.java:31)
at junit.framework.TestCase.assertTrue(TestCase.java:201)
at edu.ncsu.csc.itrust.http.BillingTest.testIncorrectCVVCode(BillingTest.java:244)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at junit.framework.TestCase.runTest(TestCase.java:176)
at junit.framework.TestCase.runBare(TestCase.java:141)
at junit.framework.TestResult$1.protect(TestResult.java:122)
at junit.framework.TestResult.runProtected(TestResult.java:142)
at junit.framework.TestResult.run(TestResult.java:125)
at junit.framework.TestCase.run(TestCase.java:129)
at junit.framework.TestSuite.runTest(TestSuite.java:255)
at junit.framework.TestSuite.run(TestSuite.java:250)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:84)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Upvotes: 1

Views: 131

Answers (0)

Related Questions