001/*
002 * (C) Copyright 2012 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Anahide Tchertchian
016 */
017package org.nuxeo.functionaltests.forms;
018
019import org.openqa.selenium.WebDriver;
020import org.openqa.selenium.WebElement;
021
022/**
023 * Represents a simple widget element, with helper methods to set/get values on it, depending on the mode.
024 *
025 * @since 5.7
026 */
027public class WidgetElement extends AbstractWidgetElement {
028
029    public WidgetElement(WebDriver driver, String id) {
030        super(driver, id);
031    }
032
033    public WidgetElement(WebDriver driver, WebElement element) {
034        super(driver, element.getAttribute("id"));
035    }
036
037    public WebElement getInputElement() {
038        return getElement(id);
039    }
040
041    public WebElement getOutputElement() {
042        return getElement(id);
043    }
044
045    public String getValue(boolean isEdit) {
046        if (isEdit) {
047            return getInputValue();
048        } else {
049            return getOutputValue();
050        }
051    }
052
053    public String getOutputValue() {
054        return getOutputElement().getText();
055    }
056
057    public void setInputValue(String value) {
058        setInput(getInputElement(), value);
059    }
060
061    public String getInputValue() {
062        return getInputElement().getAttribute("value");
063    }
064
065}