1

I've got a class assignment to test using httpUnit a use case that involves entering text into a textbox even though it is not wrapped in a form tag. Without a form to look inside, how do I send text or set the value? GetElementWithId doesn't allow you to do either of those. I can make any changes to the code I want in addition to writing the tests.

Here is the jsp code used to render the html:

<script type="text/javascript">
 $(function(){

    $("#searchBox").keyup(function(){
        $("#userSearch").attr("src","patientSearch.jsp?forward=<%=StringEscapeUtils.escapeHtml("" + (request.getParameter("forward") ))%>&q="+$("#searchBox").val()+"&allowDeactivated="+$("#allowDeactivated:checked").val())
    });
    $("#oldSearch").hide(); 

 });
</script>
<h2> Select a Patient</h2>
<b>Search by name or MID:</b><br/>
<div style="border: 1px solid Gray; padding:5px;float:left;">
    <input id="searchBox" name="searchBox" style="width: 250px;" type="text" value="<%= StringEscapeUtils.escapeHtml("" + ( firstName )) %>" />
    <br />
    <input id="allowDeactivated" type="checkbox" />
    Show deactivated patients
</div>
Brantley Blanchard
  • 1,208
  • 3
  • 14
  • 23
  • i can see that you are calling that keyup listener each time someone types text in `searchBox` but I still dont get what you are trying to do? – 1337holiday Apr 14 '13 at 05:38
  • curPage.getFormWithName("???").setParameter("searchBox", "1"); – Brantley Blanchard Apr 14 '13 at 06:27
  • I'd like to do something like that so that the user with MID 1 comes up. The problem I'm having is I don't have or know the form name here. – Brantley Blanchard Apr 14 '13 at 06:28
  • Could I wrap my input in
    so that I had a form to grab onto?
    – Brantley Blanchard Apr 14 '13 at 06:29
  • Got it to work by calling a hidden form. It's a hack defeats the purpose of UI user testing if you're going to just set values like this but it works. WebForm form = curPage.getForms()[0]; form.getScriptableObject().setParameterValue("UID_PATIENTID", "1"); Button btn = form.getButtons()[1]; btn.click(); curPage = wc.getCurrentPage(); – Brantley Blanchard Apr 14 '13 at 07:42
  • I'd still like to know if anyone knows how to actually enter text like a user would so I'm not going to select my answer as correct. – Brantley Blanchard Apr 14 '13 at 07:43

1 Answers1

1

Here is the hack I used to get it to work...

WebForm form = curPage.getForms()[0];
form.getScriptableObject().setParameterValue("UID_PATIENTID", "1");
Button btn = form.getButtons()[1];
btn.click();
curPage = wc.getCurrentPage();

The form I'm changing is hidden therefore not what a real "user" would do but it lets my test pass. If someone knows how I can do this a better way, I'd really like to know.

Brantley Blanchard
  • 1,208
  • 3
  • 14
  • 23