[Webtest] Newbie forms submission question
Petter Måhlén
webtest@lists.canoo.com
Thu, 30 Mar 2006 10:04:49 +0200
Hi,
Not sure if the question I sent yesterday about using <scriptStep /> has
made it through the moderation procedure yet, but in any case, I have
figured out that that isn't the way I should go. The problem is this: I want
to verify a login page, where the user inputs login information into a Flash
clip that then uses Javascript to submit the actual login. (Guess that's due
to legacy code..) The relevant parts of the HTML page are:
<script language="JavaScript">
function login(email, password) {
var frm = document.forms.loginForm;
frm.email.value = email;
frm.password.value = password;
frm.submit();
}
</script>
<form action="/main/authentication/login" name="loginForm" method="post">
<input type="hidden" name="email" value="">
<input type="hidden" name="password" value="">
</form>
My first attempt at testing this was using the <scriptStep/> to call the
login() function. My second attempt was:
<selectForm description="select the login form" name="loginForm" />
<setInputField description="user name" name="email" value="${login.email}"
/>
<setInputField description="password" name="password"
value="${login.password}" />
<invoke description="submit the login form" url="authentication/login"
method="POST" />
That also doesn't work, due to the fact that hidden input fields cannot be
set with <setInputField/>. Is there a reason for that, or would it be OK to
change hasTextOrPasswordField() into hasSettableInputField() (or whatever
would be felt to be an appropriate name) along the below lines:
private static boolean hasSettableInputField(final HtmlForm form, final
String name) {
final List li = form.getInputsByName(name);
for (final Iterator iter = li.iterator(); iter.hasNext();) {
final HtmlInput element = (HtmlInput) iter.next();
if
(HtmlConstants.TEXT.equalsIgnoreCase(element.getTypeAttribute())
||
HtmlConstants.HIDDEN.equalsIgnoreCase(element.getTypeAttribute())
|| HtmlConstants.PASSWORD.equalsIgnoreCase(element.getTypeAttribute())) =
{
return true;
}
}
return false;
}
Thanks in advance,
Petter
Cell: +46 704 40 30 25
Direct: +46 8 442 75 95
Fax: +46 8 24 05 08
www.jadestone.se
Björns Trädgårdsgränd 1, 116 21 Stockholm, Sweden