001/*
002 * (C) Copyright 2014 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 *     <a href="mailto:grenard@nuxeo.com">Guillaume</a>
018 */
019package org.nuxeo.functionaltests.pages.search;
020
021import java.util.List;
022
023import org.nuxeo.functionaltests.AbstractTest;
024import org.nuxeo.functionaltests.Required;
025import org.nuxeo.functionaltests.contentView.ContentViewElement;
026import org.nuxeo.functionaltests.pages.AbstractPage;
027import org.openqa.selenium.By;
028import org.openqa.selenium.NoSuchElementException;
029import org.openqa.selenium.WebDriver;
030import org.openqa.selenium.WebElement;
031import org.openqa.selenium.support.FindBy;
032
033/**
034 * @since 6.0
035 */
036public class SearchResultsSubPage extends AbstractPage {
037
038    private static final String CONTENT_VIEW_XPATH = "//div[@id='nxw_searchContentView']//div[contains(@id, 'nxw_searchContentView_panel')]";
039
040    @Required
041    @FindBy(xpath = "//div[@id='nxw_searchContentView']//div[contains(@id, 'nxw_searchContentView_resultsPanel')]/form")
042    protected WebElement resultForm;
043
044    @Required
045    @FindBy(xpath = "//div[@id='nxl_gridSearchLayout:nxw_searchResults_panel']/div/div/h3")
046    public WebElement searchViewTitle;
047
048    public SearchResultsSubPage(WebDriver driver) {
049        super(driver);
050    }
051
052    /**
053     * @since 9.3
054     */
055    public String getSearchViewTitle() {
056        return searchViewTitle.getText();
057    }
058
059    public int getNumberOfDocumentInCurrentPage() {
060        return getContentView().getItems().size();
061    }
062
063    /**
064     * @return the list of results of the search.
065     */
066    public List<WebElement> getListResults() {
067        try {
068            return getContentView().getItems();
069        } catch (NoSuchElementException e) {
070            return null;
071        }
072    }
073
074    /**
075     * @return the content view of results
076     * @since 8.4
077     */
078    public ContentViewElement getContentView() {
079        return AbstractTest.getWebFragment(By.xpath(CONTENT_VIEW_XPATH), ContentViewElement.class);
080    }
081
082}