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.search;
018
019import java.util.List;
020
021import org.nuxeo.functionaltests.Required;
022import org.nuxeo.functionaltests.pages.AbstractPage;
023import org.openqa.selenium.By;
024import org.openqa.selenium.NoSuchElementException;
025import org.openqa.selenium.WebDriver;
026import org.openqa.selenium.WebElement;
027import org.openqa.selenium.support.FindBy;
028
029/**
030 * @since 6.0
031 */
032public class SearchResultsSubPage extends AbstractPage {
033
034    private static final String SEARCH_RESULTS_XPATH = "//div[contains(@class,'bubbleBox')]";
035
036    @Required
037    @FindBy(xpath = "//div[@id='nxw_searchContentView']//div[contains(@id, 'nxw_searchContentView_resultsPanel')]/form")
038    protected WebElement resultForm;
039
040    @Required
041    @FindBy(xpath = "//div[@id='nxl_gridSearchLayout:nxw_searchResults_panel']/div/div/h3")
042    public WebElement searchViewTitle;
043
044    public SearchResultsSubPage(WebDriver driver) {
045        super(driver);
046    }
047
048    public int getNumberOfDocumentInCurrentPage() {
049        List<WebElement> result = resultForm.findElements(By.xpath(SEARCH_RESULTS_XPATH));
050        return result.size();
051    }
052
053    /**
054     * @return the list of results of the search.
055     */
056    public List<WebElement> getListResults() {
057        try {
058            return resultForm.findElements(By.xpath(SEARCH_RESULTS_XPATH));
059        } catch (NoSuchElementException e) {
060            return null;
061        }
062    }
063
064}