
org.testatoo.cartridge.html4.element.Select Maven / Gradle / Ivy
The newest version!
/**
* Copyright (C) 2008 Ovea
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.testatoo.cartridge.html4.element;
import org.testatoo.cartridge.html4.HtmlEvaluator;
import org.testatoo.core.ComponentException;
import org.testatoo.core.ListSelection;
import org.testatoo.core.Selection;
import org.testatoo.core.nature.LabelSupport;
import org.testatoo.core.nature.MultiSelectable;
import java.util.ArrayList;
import java.util.List;
/**
* This class allows the testing of the "select" element properties for html4.
* Select is a drop-down list ; each list item of a select is an option element.
*
* @author [email protected]
* @see "select" specification
*/
public final class Select extends org.testatoo.core.component.ListModel implements MultiSelectable, LabelSupport, Coreattrs, I18n {
private HtmlEvaluator evaluator;
private CoreAttributeSupport coreAttributeSupport;
private I18nAttributeSupport i18nAttributeSupport;
private AttributeSupport attributeSupport;
/**
* Class constructor specifying the evaluator to use and the id of the "select" element we want to test.
*
* @param evaluator a UI Test engine specific html evaluator
* @param id the id (unique) of the "select" element
*/
public Select(HtmlEvaluator evaluator, String id) {
super(evaluator, id);
this.evaluator = evaluator;
coreAttributeSupport = new CoreAttributeSupport(evaluator);
i18nAttributeSupport = new I18nAttributeSupport(evaluator);
attributeSupport = new AttributeSupport(evaluator);
}
/**
* To get the "label" corresponding to the "select" element
* the label of the select is the content of the "label" element with a "for" attribute equals to the select id
*
* @return the content of label attribute corresponding to the "select" element
*/
public String label() {
return evaluator.label(this);
}
/**
* @see CoreAttributeSupport
*/
public String classname() {
return coreAttributeSupport.classname(this);
}
/**
* @see CoreAttributeSupport
*/
public String style() {
return coreAttributeSupport.style(this);
}
/**
* @see CoreAttributeSupport
*/
public String title() {
return coreAttributeSupport.title(this);
}
/**
* @see I18nAttributeSupport
*/
public String language() {
return i18nAttributeSupport.language(this);
}
/**
* @see I18nAttributeSupport
*/
public Direction direction() {
return i18nAttributeSupport.direction(this);
}
/**
* To get the selected values in the list.
*
* @return a list of String
* @see #listSelectedValues
*/
public Selection selectedValues() {
return lstSelectedValues();
}
/**
* To get the selected values in the list.
*
* @return a list of String
* @see #selectedValues
*/
protected Selection listSelectedValues() {
return lstSelectedValues();
}
/**
* To select in the list an item with a given value.
* If the item has no value, the item with the content equals to the value is selected
*
* @param value the value of the item we want to select
*/
public void select(String value) {
evaluator.select(value, this);
}
/**
* To unselect in the list an item with a given value.
* If the item has no value, the item with the content equals to the value is deselected
*
* @param value the value of the item we want to unselect
*/
public void unselect(String value) {
if (isMultiple())
evaluator.unselect(value, this);
else
throw new ComponentException("Unable to unselect a value : Select is no a multi select.");
}
/**
* To get the values in the list.
*
* @return a list of String
*/
public Selection values() {
List optionsValue = new ArrayList();
for (Option option : options()) {
optionsValue.add(option.content());
}
return ListSelection.from(optionsValue);
}
/**
* To unselect all the selected values of the list.
*/
public void unselectAll() {
if (isMultiple())
evaluator.unselectAll(this);
else
throw new ComponentException("Unable to unselect all values : Select is no a multi select.");
}
/**
* To know if a list is multi-selectable.
*
* @return true if the list is multi-selectable
*/
public boolean isMultiple() {
return Boolean.valueOf(evaluator.attribute(id(), Attribute.multiple));
}
/**
* To get the options in the list.
*
* @return a list of options
*/
public Selection
© 2015 - 2025 Weber Informatics LLC | Privacy Policy