URL url = new URL(testUrl);
HtmlPage page = (HtmlPage) client.getPage(url);
// System.out.println(page.getTitleText());
// Check response code
WebResponse resp = page.getWebResponse();
assertTrue(resp.getStatusCode() <= 200);
List forms = page.getForms();
HtmlPage resultPage = null;
WebResponse resultResponse= null;
boolean formfound = false;
for (Iterator iter = forms.iterator(); formfound != true && iter.hasNext();) {
HtmlForm form = (HtmlForm) iter.next();
if ("loginAction".equals(form.getActionAttribute())) {
formfound = true;
HtmlInput login = form.getInputByName("login");
HtmlInput password = form.getInputByName("password");
login.setValueAttribute("test");
password.setValueAttribute("password");
resultPage = (HtmlPage) form.submit();
// Check response from servlet
resultResponse = resultPage.getWebResponse();
assertTrue(resultResponse.getStatusCode() <= 200);
String response = resultResponse.getContentAsString();
assertTrue(-1 != response.indexOf("Account Information for"));
assertTrue(-1 != response.indexOf("Test"));
assertTrue(-1 != response.indexOf("134-42-6231"));
assertTrue(-1 != response.indexOf("123.43"));
assertTrue(-1 != response.indexOf("134-43-3941"));
assertTrue(-1 != response.indexOf("23.12"));
Pattern pat = Pattern.compile("LU.*7", Pattern.DOTALL);
Matcher test = pat.matcher(response);
assertTrue(test.find());
}
}
forms = resultPage.getForms();
formfound = false;
for(Iterator iter = forms.iterator(); formfound != true && iter.hasNext();) {
HtmlForm form = (HtmlForm) iter.next();
if ("purchaseStock.jsp".equals(form.getActionAttribute())) {
formfound = true;
resultPage = (HtmlPage) form.submit();
}
}
assertTrue(formfound);
forms = resultPage.getForms();
formfound = false;
for (Iterator iter = forms.iterator(); formfound != true && iter.hasNext();) {
HtmlForm form = (HtmlForm) iter.next();
if ("FormServlet".equals(form.getActionAttribute())) {
formfound = true;
HtmlInput login = form.getInputByName("symbol");
HtmlInput password = form.getInputByName("quantity");
login.setValueAttribute("EDS");
password.setValueAttribute("131");
resultPage = (HtmlPage) form.submit();
// Check response from servlet
resultResponse = resultPage.getWebResponse();
assertTrue(resultResponse.getStatusCode() <= 200);
String response = resultResponse.getContentAsString();
assertTrue(-1 != response.indexOf("Account Information for"));
assertTrue(-1 != response.indexOf("Test"));
assertTrue(-1 != response.indexOf("134-42-6231"));
assertTrue(-1 != response.indexOf("123.43"));
assertTrue(-1 != response.indexOf("134-43-3941"));
assertTrue(-1 != response.indexOf("23.12"));
Pattern pat = Pattern.compile("LU.*7", Pattern.DOTALL);
Matcher test = pat.matcher(response);
assertTrue(test.find());
pat = Pattern.compile("EDS.*131", Pattern.DOTALL);
test = pat.matcher(response);
assertTrue(test.find());
}
}
assertTrue(formfound);
forms = resultPage.getForms();
formfound = false;
for (Iterator iter = forms.iterator(); formfound != true && iter.hasNext();) {
HtmlForm form = (HtmlForm) iter.next();
if ("stockSale.jsp".equals(form.getActionAttribute())) {
// System.err.println(form.asText());
Pattern pat = Pattern.compile("EDS.*131", Pattern.DOTALL);
Matcher test = pat.matcher(form.asText());
if(!test.find()) continue;
formfound = true;
resultPage = (HtmlPage) form.submit();
// Check response from servlet
resultResponse = resultPage.getWebResponse();
assertTrue(resultResponse.getStatusCode() <= 200);
}
}
forms = resultPage.getForms();
formfound = false;
for(Iterator iter = forms.iterator(); formfound != true && iter.hasNext();) {
HtmlForm form = (HtmlForm) iter.next();
if ("FormServlet".equals(form.getActionAttribute())) {
formfound = true;
HtmlInput password = form.getInputByName("quantity");
password.setValueAttribute("131");
resultPage = (HtmlPage) form.submit();
// Check response from servlet
resultResponse = resultPage.getWebResponse();
assertTrue(resultResponse.getStatusCode() <= 200);
String response = resultResponse.getContentAsString();
assertTrue(-1 != response.indexOf("Account Information for"));
assertTrue(-1 != response.indexOf("Test"));
assertTrue(-1 != response.indexOf("134-42-6231"));
assertTrue(-1 != response.indexOf("123.43"));
assertTrue(-1 != response.indexOf("134-43-3941"));