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 *     <a href="mailto:grenard@nuxeo.com">Guillaume</a>
016 */
017package org.nuxeo.functionaltests.pages;
018
019import java.util.ArrayList;
020import java.util.List;
021
022import org.nuxeo.functionaltests.Locator;
023import org.nuxeo.functionaltests.Required;
024import org.nuxeo.functionaltests.pages.tabs.CollectionContentTabSubPage;
025import org.openqa.selenium.By;
026import org.openqa.selenium.WebDriver;
027import org.openqa.selenium.WebElement;
028import org.openqa.selenium.support.FindBy;
029
030/**
031 * @since 5.9.3
032 */
033public class CollectionsPage extends HomePage {
034
035    @Required
036    @FindBy(id = "user_collection_contentview")
037    protected WebElement collectionContentView;
038
039    public CollectionsPage(final WebDriver driver) {
040        super(driver);
041    }
042
043    public List<WebElement> getCollectionRows() {
044        return driver.findElements(By.xpath("//form[@id='user_collection_contentview']/table/tbody/tr"));
045    }
046
047    public List<String> getCollectionNames() {
048        List<String> result = new ArrayList<String>();
049        for (WebElement collectionRow : getCollectionRows()) {
050            result.add(collectionRow.findElement(By.xpath("td[3]")).getText());
051        }
052        return result;
053    }
054
055    public CollectionContentTabSubPage goToCollection(final String collectionName) {
056        Locator.findElementWithTimeout(By.linkText(collectionName), collectionContentView).click();
057        return asPage(CollectionContentTabSubPage.class);
058    }
059
060}