Canoo Webtest WebTest Canoo

Core Step verifyCheckbox

Description

This step is used to verify the state of a checkbox (checked/unchecked). A particular checkbox can be specified via name and optionally value (or alternatively by fieldIndex).

Parameters

checked
Required? yes
Specifies if the checkbox shall be checked (true) or unchecked (false).
name
Required? yes
The xpath of the input field of interest. One of name, htmlId or xpath is required.
description
Required? no
The description of this test step.
fieldIndex
Required? no
The index (starting at 0) of the field of interest (if more than one).
formName
Required? no
The name of the form containing the field of interest.
htmlId
Required? yes/no
The id of the input field of interest. One of name, htmlId or xpath is required.
value
Required? no
The value of the input field of interest.
xpath
Required? yes/no
The xpath of the input field of interest. One of name, htmlId or xpath is required.

Details

Here is a simple example for verifying that a particular checkbox is not selected. The checkbox is uniquely identified by its name.

verifyCheckbox 1
<webtest name="Check all links on current page, on subpages and on their subpages">
  <config ... />
  <steps>
    <invoke ... />
        <verifyCheckbox
            description="Verify that option is not selected"
            name="anchovis"
            checked="false"/>
  </steps>
</webtest>

A more complex scenario would allow multiple checkboxes that all have the same name but different values. The resulting request would also contain multiple value for one parameter (the checkbox name). Each of the parameter values corresponds to the value of a checked checkbox.
In order to uniquely identify checkboxes like this for verification, an optional value attribute can be specified as shown in the next example.

verifyCheckbox 2
<webtest name="Place order and verify">
  <config ... />
  <steps>
    <invoke ... />
        <verifyCheckbox description="Verify toppings - Mozzarella"
            name="toppingvalue="Mozzarella"
            checked="true" />
        <verifyCheckbox description="Verify toppings - Gorgonzola"
            name="toppingvalue="Gorgonzola"
            checked="true" />
        <verifyCheckbox description="Verify toppings - Anchovis not!"
            name="toppingvalue="Anchovis"
            checked="false" />
  </steps>
</webtest>

See also: the setCheckbox 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