001/* 002 * (C) Copyright 2017 Nuxeo (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 * Kevin Leturc 018 */ 019package org.nuxeo.functionaltests.pages.tabs; 020 021import java.util.List; 022 023import org.nuxeo.functionaltests.AbstractTest; 024import org.nuxeo.functionaltests.contentView.ContentViewElement; 025import org.nuxeo.functionaltests.pages.DocumentBasePage; 026import org.openqa.selenium.By; 027import org.openqa.selenium.NoSuchElementException; 028import org.openqa.selenium.WebDriver; 029import org.openqa.selenium.WebElement; 030import org.openqa.selenium.support.FindBy; 031 032/** 033 * All resolutions of sub element are made based on contentForm id. 034 * 035 * @since 9.1 036 */ 037public abstract class AbstractContentTabSubPage extends DocumentBasePage { 038 039 /** 040 * @deprecated since 9.1 use filter methods on {@link ContentViewElement} 041 */ 042 @Deprecated 043 @FindBy(id = "cv_document_content_0_quickFilterForm:nxl_document_content_filter:nxw_search_title") 044 WebElement filterInput; 045 046 /** 047 * @deprecated since 9.1 use filter methods on {@link ContentViewElement} 048 */ 049 @Deprecated 050 @FindBy(id = "cv_document_content_0_quickFilterForm:submitFilter") 051 WebElement filterButton; 052 053 /** 054 * @deprecated since 9.1 use filter methods on {@link ContentViewElement} 055 */ 056 @Deprecated 057 @FindBy(id = "cv_document_content_0_resetFilterForm:resetFilter") 058 WebElement clearFilterButton; 059 060 public AbstractContentTabSubPage(WebDriver driver) { 061 super(driver); 062 } 063 064 /** 065 * @return the content view element for this content view tab 066 */ 067 protected abstract WebElement getContentViewElement(); 068 069 public ContentViewElement getContentView() { 070 return AbstractTest.getWebFragment(getContentViewElement(), ContentViewElement.class); 071 } 072 073 public List<WebElement> getChildDocumentRows() { 074 return getContentView().getItems(); 075 } 076 077 public boolean hasDocumentLink(String title) { 078 try { 079 WebElement element = getContentView().findElement(By.linkText(title)); 080 return element != null; 081 } catch (NoSuchElementException e) { 082 return false; 083 } 084 } 085 086 /** 087 * Clicking on one of the child with the title. 088 * 089 * @param documentTitle the document title 090 */ 091 public DocumentBasePage goToDocument(String documentTitle) { 092 getContentView().clickOnItemTitle(documentTitle); 093 return asPage(DocumentBasePage.class); 094 } 095 096 public DocumentBasePage goToDocumentWithVersion(String title, String version) { 097 getContentView().clickOnItemTitleAndVersion(title, version); 098 return asPage(DocumentBasePage.class); 099 } 100 101 public DocumentBasePage goToDocument(int index) { 102 getContentView().clickOnItemIndex(index); 103 return asPage(DocumentBasePage.class); 104 } 105 106 /** 107 * Perform filter on the given string. 108 * 109 * @param filter the string to filter 110 */ 111 public DocumentBasePage filterDocument(String filter) { 112 return filterDocument(filter, DocumentBasePage.class); 113 } 114 115 /** 116 * Perform filter on the given string. 117 * 118 * @param filter the string to filter 119 */ 120 public <T extends DocumentBasePage> T filterDocument(String filter, Class<T> pageClassToProxy) { 121 getContentView().filterDocument(filter); 122 return asPage(pageClassToProxy); 123 } 124 125 /** 126 * Clear the current filter and refresh content view. 127 */ 128 public DocumentBasePage clearFilter() { 129 return clearFilter(DocumentBasePage.class); 130 } 131 132 /** 133 * Clear the current filter and refresh content view. 134 */ 135 public <T extends DocumentBasePage> T clearFilter(Class<T> pageClassToProxy) { 136 getContentView().clearFilter(); 137 return asPage(pageClassToProxy); 138 } 139 140 public DocumentBasePage removeDocument(String documentTitle) { 141 return getContentView().selectByTitle(documentTitle).delete(); 142 } 143 144 public <T extends DocumentBasePage> T removeDocument(String documentTitle, Class<T> pageClassToProxy) { 145 return getContentView().selectByTitle(documentTitle).delete(pageClassToProxy); 146 } 147 148 /** 149 * Removes all documents visible on current page. 150 */ 151 public DocumentBasePage removeAllDocuments() { 152 return removeAllDocuments(DocumentBasePage.class); 153 } 154 @SuppressWarnings("unchecked") 155 public <T extends DocumentBasePage> T removeAllDocuments(Class<T> pageClassToProxy) { 156 ContentViewElement cv = getContentView(); 157 if (cv.getItems().size() == 0) { 158 // no document to remove 159 if (pageClassToProxy.isInstance(this)) { 160 return (T) this; 161 } 162 return null; 163 } 164 return getContentView().selectAll().delete(pageClassToProxy); 165 } 166 167}