Canoo Webtest WebTest Canoo

Extension Step storeInputFieldAttribute

Description

Retrieves the attribute value of a selected input field. Can be used to check whether an input field is enabled.

This step provides a mechanism to peek inside the state of input elements inside your HTML. It should be used with care as the user (via their browser) typically wouldn't have direct access to these states (but probably are given an alternative visual representation, e.g. if the state is disabled, the element will probably be greyed out). Because WebTest doesn't represent the page graphically, peeking at the states can be the next best thing to know what is going on.

Available states include: "checked" and "disabled".

Parameters

attributeName
Required? yes
The name of the attribute of interest, e.g. "disabled" or "checked".
name
Required? yes
The name of the input field of interest.
description
Required? no
The description of this test step.
fieldIndex
Required? no
The index (starting at 0) of the attribute of interest.
formName
Required? no, default is the last form selected using 'selectForm', otherwise searches all forms
The name of the form containing the field of interest.
property
Required? no
The name of the property in which to store the retrieved value.
propertyName
Required? no
Deprecated. Same as property.
propertyType
Required? no, default is the "defaultPropertyType" as specified in the "config" element is used.
The type of the property in which to store the retrieve value. Either "ant" or "dynamic".
value
Required? no
The value of the input field of interest.

Details

Consider the following HTML form:

inputFieldAttributePage.html
<html>
<head>
<title>InputField Attribute Test Page</title>
<script type="text/javascript">
<--
function checkEmpty(button, element) {
  if (element.value == "") button.disabled=true;
  else button.disabled=false;
}
// -->
</script>
</head>
<body>
...
<h1>Form 1</h1>
<form action="dummy.html" >
    Enter Value (then click outside box): <input name="value1onchange="checkEmpty(button1, this)"><br>
    <input type="submitvalue="Click Mename="button1id="button1disabled="true">
</form>
...
</html>

This page contains some JavaScript validation. We can use the storeInputFieldAttribute step to check that the validation is working. When the form is first loaded, the "Click Me" button should be disabled as the "value1" field is empty. We can then place some content into the field. We should then note that the "Click Me" button is now enabled (the onchange JavaScript event will do this). Here is the script code:

storeInputFieldAttribute Example
<webtest name="testInputFieldAttributeSteps: Show usage of storeInputFieldAttribute step using disabled attribute">
    <config ...>
    <steps>
        <invoke ...>
        <verifytitle description="check we are on the test pagetext="InputField Attribute Test Page" />
        <storeInputFieldAttribute propertyName="isDisabled1aname="button1attributeName="disabled"/>
        <verifyProperty description="check if button is disabledname="isDisabled1atext="true"/>
        <clickButton description="Attempt submit but should be ignored as button is disabledname="button1" />
        <verifytitle description="check we are still on the test pagetext="InputField Attribute Test Page" />
        <setInputField description="set field value should enabled buttonname="value1value="someText" />
        <clickButton description="Attempt submit should work as button is enabledname="button1" />
        <verifytitle description="check we are now on the dummy pagetext="Dummy" />
    </steps>
</webtest>

See also: the forceInputFieldAttribute step in order to set an input field attribute, and the storeElementAttribute step to be able to store an attribute using an XPath expression or an HTML id.

news

Latest build: development
Posted: 19-Jul-2016 17:36

WebTest 3.0 released, featuring upgrades to Java 5, Groovy 1.6, and HtmlUnit 2.4.
The release includes support for maven integration, IDE-integration like for unit tests, capturing of background JavaScript errors, new steps for mouseOver and mouseOut events, better parallel execution of tests and - as usual - lots of handling improvements.
Posted: 5 March 2009

WebTest @ JavaOne
Dierk König presented "Functional testing of web applications: scaling with Java" on Wed May 7, 13:30 at JavaOne 2008 in the Tools and Scripting Languages track.
Posted: 8 May 2008

New WebTest screencast available:
Data Driven WebTest
Posted: 13 November 2007

First WebTest screencast available:
Creating a first Webtest Project

Extend WebTest with Groovy! Groovy in Action is available in every good bookstore.
Groovy in Action
Posted: 29 January 2007