001/*
002 * (C) Copyright 2014 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-2.1.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 *     Nelson Silva
016 */
017package org.nuxeo.functionaltests.contentView;
018
019import org.nuxeo.functionaltests.AjaxRequestManager;
020import org.nuxeo.functionaltests.Required;
021import org.nuxeo.functionaltests.fragment.WebFragmentImpl;
022import org.openqa.selenium.By;
023import org.openqa.selenium.WebDriver;
024import org.openqa.selenium.WebElement;
025import org.openqa.selenium.support.FindBy;
026
027/**
028 * Represents a content view element.
029 *
030 * @since 7.1
031 */
032public class ContentViewElement extends WebFragmentImpl {
033
034    public static enum ResultLayout {
035        THUMBNAIL("Thumbnail view"), LISTING("List view");
036
037        private final String title;
038
039        ResultLayout(String title) {
040            this.title = title;
041        }
042    }
043
044    @FindBy(className = "contentViewUpperActions")
045    @Required
046    private WebElement upperActions;
047
048    public ContentViewElement(WebDriver driver, WebElement element) {
049        super(driver, element);
050    }
051
052    public WebElement getActionByTitle(String title) {
053        return upperActions.findElement(By.xpath("//img[@alt=\"" + title + "\"]"));
054    }
055
056    public void switchToResultLayout(ResultLayout layout) {
057        AjaxRequestManager a = new AjaxRequestManager(driver);
058        a.watchAjaxRequests();
059        getActionByTitle(layout.title).click();
060        a.waitForAjaxRequests();
061    }
062}