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