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 org.nuxeo.functionaltests.AjaxRequestManager; 020import org.nuxeo.functionaltests.Required; 021import org.nuxeo.functionaltests.forms.Select2WidgetElement; 022import org.nuxeo.functionaltests.pages.DocumentBasePage; 023import org.openqa.selenium.By; 024import org.openqa.selenium.WebDriver; 025import org.openqa.selenium.WebElement; 026import org.openqa.selenium.support.FindBy; 027 028/** 029 * @since 6.0 030 */ 031public class SearchPage extends DocumentBasePage { 032 033 public static final String SEARCH_TAB = "SEARCH"; 034 035 public static final String DEFAULT_SEARCH = "Faceted Search"; 036 037 public static final String NXQL_SEARCH = "NXQL Search"; 038 039 public static final String QUICK_SEARCH = "Quick Search"; 040 041 private static final String S2_SEARCH_TYPE_ID = "s2id_nxl_gridSearchLayout:nxw_searchesSelector_form:nxw_searchesSelector"; 042 043 @FindBy(id = "nxl_gridSearchLayout:nxw_searchForm_panel") 044 @Required 045 protected WebElement searchFormPanel; 046 047 @FindBy(id = "nxl_gridSearchLayout:nxw_searchResults_panel") 048 @Required 049 protected WebElement searchResultPanel; 050 051 public SearchPage(WebDriver driver) { 052 super(driver); 053 } 054 055 public DefaultSearchSubPage getDefaultSearch() { 056 if (!isDefaultSearch()) { 057 selectSearch(DEFAULT_SEARCH); 058 } 059 return asPage(DefaultSearchSubPage.class); 060 } 061 062 public NXQLSearchSubPage getNXQLSearch() { 063 if (!isNXQLSearch()) { 064 selectSearch(NXQL_SEARCH); 065 } 066 return asPage(NXQLSearchSubPage.class); 067 } 068 069 public QuickSearchSubPage getQuickSearch() { 070 if (!isQuickSearch()) { 071 selectSearch(QUICK_SEARCH); 072 } 073 return asPage(QuickSearchSubPage.class); 074 } 075 076 public SearchResultsSubPage getSearchResultsSubPage() { 077 return asPage(SearchResultsSubPage.class); 078 } 079 080 public String getSelectedSearch() { 081 Select2WidgetElement s2 = new Select2WidgetElement(driver, 082 searchFormPanel.findElement(By.id(S2_SEARCH_TYPE_ID))); 083 return s2.getSelectedValue().getText(); 084 } 085 086 public boolean isDefaultSearch() { 087 return isSearchSelected(DEFAULT_SEARCH); 088 } 089 090 public boolean isNXQLSearch() { 091 return isSearchSelected(NXQL_SEARCH); 092 } 093 094 public boolean isQuickSearch() { 095 return isSearchSelected(QUICK_SEARCH); 096 } 097 098 protected boolean isSearchSelected(final String searchType) { 099 String selected = getSelectedSearch(); 100 return selected != null && selected.equals(searchType); 101 } 102 103 public void selectSearch(String searchLabel) { 104 Select2WidgetElement s2 = new Select2WidgetElement(driver, 105 searchFormPanel.findElement(By.id(S2_SEARCH_TYPE_ID))); 106 AjaxRequestManager am = new AjaxRequestManager(driver); 107 am.watchAjaxRequests(); 108 s2.selectValue(searchLabel); 109 am.waitForAjaxRequests(); 110 } 111 112}