/** * Gets the form with a specified action, or throw an error */ public static WebForm getFormWithAction(WebResponse response, String actionName) throws ProcessingException, SAXException { WebForm[] forms = response.getForms(); for( int i=0; i<forms.length; i++ ) { WebForm form = forms[i]; if(form.getAction().equals(actionName)) return form; } throw new ProcessingException("Unable to find a form with action="+actionName); }
/** * Gets the list member form to mass subscribe/unsubscribe addresses. */ private WebForm getListMemberForm(SubscriptionMode mode) throws IOException, SAXException, ProcessingException { WebResponse response = goTo(project._getURL()+"/servlets/MailingListMembers?list="+name+"&group="+mode.groupName); for( WebForm form : response.getForms() ) { if (form.getAction().equals("MailingListMembers")) return form; } throw new ProcessingException("Error: this is not the Mailing List Members Form!"); }
protected Void scrape() throws IOException, SAXException, ProcessingException { WebResponse response = goTo(project._getURL()+"/servlets/ProjectMailingListList"); for (WebForm form : response.getForms()) { if(!form.getAction().equals("ProjectMailingListList")) continue; if(!form.getParameterValue("listName").equals(name)) continue; // found the form SubmitButton sb = form.getSubmitButtons()[0]; if(!sb.getValue().equals("Subscribe")) throw new ProcessingException("Found "+sb.getValue()+" but expected Subscribe"); // set the mode form.setParameter("subtype",mode.getNameAsWord()); checkError(form.submit(sb)); return null; } throw new ProcessingException("no subscription form found"); } }.run();
public void testGoodLogin() throws Exception { WebConversation conversation = new WebConversation(); WebRequest request = new GetMethodWebRequest( "http://www.meterware.com/servlet/TopSecret" ); WebResponse response = conversation.getResponse( request ); WebForm loginForm = response.getForms()[0]; request = loginForm.getRequest(); request.setParameter( "name", "master" ); response = conversation.getResponse( request ); assertTrue( "Login not accepted", response.getText().indexOf( "You made it!" ) != -1 ); assertEquals( "Page title", "Top Secret", response.getTitle() ); }
String url = project._getURL() + "/servlets/ProjectMemberAdd"; WebResponse r = goTo(url); WebForm[] forms = r.getForms(); WebForm form = forms[forms.length-1]; // last one is it
try { WebResponse r = goTo(project._getURL()+"/servlets/ProjectMemberList"); WebForm[] forms = r.getForms(); WebForm form = forms[forms.length-1];
WebForm[] forms = r.getForms(); for (WebForm form : forms) { String action = form.getAction();