001/*
002 * (C) Copyright 2012 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Anahide Tchertchian
018 */
019package org.nuxeo.functionaltests.forms;
020
021import org.openqa.selenium.WebDriver;
022import org.openqa.selenium.WebElement;
023
024/**
025 * Base class to handle widgets
026 * <p>
027 * Needs a constructor accepting {@link WebDriver} and {@link String} as id to be instantiated by the
028 * {@link LayoutElement#getWidget(String, Class)} method.
029 *
030 * @since 5.7
031 */
032public abstract class AbstractWidgetElement extends LayoutElement {
033
034    public AbstractWidgetElement(WebDriver driver, String id) {
035        super(driver, id);
036    }
037
038    public String getWidgetId() {
039        String res = id;
040        if (res.contains(":")) {
041            res = res.substring(res.lastIndexOf(":") + 1);
042        }
043        return res;
044    }
045
046    /**
047     * Returns the message element value, e.g. errors for this widget.
048     *
049     * @since 7.2
050     */
051    public String getMessageValue() {
052        return getMessageValue("_message");
053    }
054
055    /**
056     * Returns the message element value, e.g. errors for this widget.
057     *
058     * @since 7.2
059     */
060    public String getMessageValue(String suffix) {
061        WebElement el = getElement(id + suffix);
062        if (el != null) {
063            return el.getText();
064        }
065        return null;
066    }
067
068}