Canoo Webtest WebTest Canoo

Core Step setCheckbox

Description

Provides the ability to check and uncheck checkboxes in HTML forms.

The checkbox to set/unset will be determined by finding the appropriate form followed by finding the appropriate field on that form.

Form Selection: in many cases, your page will only have one form - that form will be used - you don't need to worry about trying to select the form. For tricky cases, you might need to do extra work to select the appropriate form. See the setRadioButton step for further details on how to do this.

Field Selection: in many cases, only one field will match the name and value of the field you are interested in. In these cases, you don't need to worry about the remaining details for selecting fields. For tricky cases, you might need to do extra work to select the appropriate field. See the setRadioButton step for further details on how to do this.

Parameters

checked
Required? false, default is true
Specifies if the checkbox shall be checked (true) or unchecked (false).
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.
value
Required? no
The value to use to select the desired checkbox. If not present, the first possible checkbox is selected.
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 ( <setCheckbox> ) and the end tag ( </setCheckbox> ), including blanks, tabs or newlines. Using a pair of start/end tags ( <setCheckbox> </setCheckbox> ) has not the same behavior than the seemingly equivalent empty element tag ( <setCheckbox/> )! See this issue for an example.

Required? no
An alternative to the attribute value for e.g. large TextAreas.

Details

See the following example for plain vanilla checkbox selection. The resulting request submitted by <clickButton> will contain a parameter with the checkbox name and as value the default checkbox parameter value "on".

setCheckbox example1
<webtest name="Choose all desired pizza toppings by checking them">
  <config ... />
  <steps>
    <invoke ... />
      <setCheckbox description="Select the cheese option"
        name="Cheese"
        checked="true" />
      <clickButton description="Submit the selected options"
        label="Choose" />
    ...
  </steps>
</webtest>

The next example provides explicit values for a checkbox parameter to be submitted with the request. Note that a single parameter can have multiple values. This is the case here. The cheese parameter has the values "Gorgonzola" and "Mozzarella".

setCheckbox example2
<webtest name="Choose all desired pizza toppings by checking them">
  <config ... />
  <steps>
    <invoke ... />
      <setCheckbox description="Select toppings - Gorgonzola"
        name="topping"
        value="Gorgonzola" />
      <setCheckbox description="Select toppings - Mozzarella"
        name="topping"
        value="Mozzarella" />
      <clickButton description="Submit the selected options"
        label="Choose" />
    ...
  </steps>
</webtest>

See also: the verifyCheckbox and selectForm steps.

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