Extension Step forceInputFieldAttribute
Description
Sets (or removes) the attribute value of a selected input field. An example usage would be to enable a disabled input field (perhaps to mimic some unsupported JavaScript).
Parameters
- attributeName
- Required? yes
- The name of the attribute of interest, e.g. "disabled" or "checked".
- attributeValue
- Required? yes
- The value to set for the attribute of interest; causes the attribute to be removed if set to the empty string (i.e. "").
- value
- Required? yes
- The value to use when setting the field of interest.
- description
- Required? no
- The description of this test step.
- fieldIndex
- Required? no, default is the first field found that matches criteria
- The index of the field of interest (starting at 0) if more than one field matches criteria. Ignored if htmlId or xpath is used.
- forLabel
- Required? yes/no
- The text of the label field associated with the input field of interest. One of forLabel, htmlId, name, or xpath is required.
- 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. Ignored if htmlId is used.
- htmlId
- Required? yes/no
- The id of the input field of interest. One of forLabel, htmlId, name, or xpath is required.
- name
- Required? yes/no
- The name of the input field of interest. One of forLabel, htmlId, name, or xpath is required.
- save
- Required? no
- A shorthand: save='prefixName' is the same as savePrefix='prefixName' saveResponse='true'.
- savePrefix
- Required? no, default is the 'savePrefix' parameter as specified in <config>.
- A name prefix can be specified for making a permanent copy of received responses. A unique number and the file extension (depending on the MIME-Type) will be appended. The resultpath attribute of the <config> element is used for determining the location of the saved result.
- saveResponse
- Required? no
- Whether to make a permanent copy of received responses. Overrides the default value set in the <config> element.
- tagName
- Required? no, default is input
- The name of the tag of interest, e.g. "input" or "select".
- xpath
- Required? yes/no
- The xpath of the input field of interest. One of forLabel, htmlId, name, or xpath is required.
Inline Text
The inline text is all the text between the start tag ( <forceInputFieldAttribute> ) and the end tag ( </forceInputFieldAttribute> ), including blanks, tabs or newlines. Using a pair of start/end tags ( <forceInputFieldAttribute> </forceInputFieldAttribute> ) has not the same behavior than the seemingly equivalent empty element tag ( <forceInputFieldAttribute/> ).
- Required? no
- An alternative to the attribute value for e.g. large TextAreas.
Details
Consider the following HTML form:
<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 2</h1>
<form action="dummy.html" >
Enter Value (auto checks): <input name="value2" onkeyup="checkEmpty(button2, this)"><br>
<input type="submit" value="Click Me" name="button2" id="button2" disabled="true">
</form>
...
</html>
This page contains some JavaScript validation. We would like to 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. However because the onkeyup JavaScript event is not supported, we note that the "Click Me" button is still disabled. We can use the <forceInputFieldAttribute> to force the button to become enabled. For the enabled attribute, we need to remove the "disabled" attribute to enable the button. We do this by setting the "attributeValue" to the empty string "". Here is the script code:
<config ...>
<steps>
<invoke ...>
<verifytitle description="check we are on the test page" text="InputField Attribute Test Page" />
<storeInputFieldAttribute propertyName="isDisabled2a" name="button2" attributeName="disabled"/>
<verifyProperty description="check if button is disabled" name="isDisabled2a" text="true"/>
<clickButton description="Attempt submit but should be ignored as button is disabled" name="button2" />
<verifytitle description="check we are still on the test page" text="InputField Attribute Test Page" />
<setInputField description="set field value would enabled button if onkeyup() was supported event in htmlunit"
name="value2" value="someText" />
<clickButton description="Attempt submit should fail because of onkeyup() limitation" name="button2" />
<verifytitle description="check we are still on the test page" text="InputField Attribute Test Page" />
<forceInputFieldAttribute name="button2" attributeName="disabled" attributeValue=""/>
<storeInputFieldAttribute propertyName="isDisabled2b" name="button2" attributeName="disabled"/>
<verifyProperty name="isDisabled2b" text="false"/>
<clickButton description="Attempt submit should work as button is enabled" name="button2" />
<verifytitle description="check we are now on the dummy page" text="Dummy" />
</steps>
</webtest>
See also: the storeInputFieldAttribute step.