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 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 if (!isDefaultSearch()) { 059 selectSearch(DEFAULT_SEARCH); 060 } 061 return asPage(DefaultSearchSubPage.class); 062 } 063 064 public NXQLSearchSubPage getNXQLSearch() { 065 if (!isNXQLSearch()) { 066 selectSearch(NXQL_SEARCH); 067 } 068 return asPage(NXQLSearchSubPage.class); 069 } 070 071 public QuickSearchSubPage getQuickSearch() { 072 if (!isQuickSearch()) { 073 selectSearch(QUICK_SEARCH); 074 } 075 return asPage(QuickSearchSubPage.class); 076 } 077 078 public SearchResultsSubPage getSearchResultsSubPage() { 079 return asPage(SearchResultsSubPage.class); 080 } 081 082 public String getSelectedSearch() { 083 Select2WidgetElement s2 = new Select2WidgetElement(driver, 084 searchFormPanel.findElement(By.id(S2_SEARCH_TYPE_ID))); 085 return s2.getSelectedValue().getText(); 086 } 087 088 public boolean isDefaultSearch() { 089 return isSearchSelected(DEFAULT_SEARCH); 090 } 091 092 public boolean isNXQLSearch() { 093 return isSearchSelected(NXQL_SEARCH); 094 } 095 096 public boolean isQuickSearch() { 097 return isSearchSelected(QUICK_SEARCH); 098 } 099 100 protected boolean isSearchSelected(final String searchType) { 101 String selected = getSelectedSearch(); 102 return selected != null && selected.equals(searchType); 103 } 104 105 public void selectSearch(String searchLabel) { 106 Select2WidgetElement s2 = new Select2WidgetElement(driver, 107 searchFormPanel.findElement(By.id(S2_SEARCH_TYPE_ID))); 108 AjaxRequestManager am = new AjaxRequestManager(driver); 109 am.watchAjaxRequests(); 110 s2.selectValue(searchLabel); 111 am.waitForAjaxRequests(); 112 } 113 114}