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.tabs; 018 019import static org.junit.Assert.assertEquals; 020 021import org.nuxeo.functionaltests.Required; 022import org.nuxeo.functionaltests.pages.AbstractPage; 023import org.openqa.selenium.Alert; 024import org.openqa.selenium.By; 025import org.openqa.selenium.NoSuchElementException; 026import org.openqa.selenium.WebDriver; 027import org.openqa.selenium.WebElement; 028import org.openqa.selenium.support.FindBy; 029 030import java.util.List; 031 032/** 033 * @since 5.9.3 034 */ 035public class TrashSubPage extends AbstractPage { 036 037 protected static final String SELECT_ALL_BUTTON_ID = "document_trash_content:nxl_document_listing_table:listing_table_selection_box_with_current_document_header"; 038 039 protected static final String PERMANENT_DELETE_BUTTON_ID = "document_trash_content_buttons:nxw_CURRENT_SELECTION_DELETE_form:nxw_CURRENT_SELECTION_DELETE"; 040 041 protected static final String EMPTY_TRASH_BUTTON_ID = "document_trash_content_buttons:nxw_CURRENT_SELECTION_EMPTY_TRASH_form:nxw_CURRENT_SELECTION_EMPTY_TRASH"; 042 043 @FindBy(xpath = "//form[@id=\"document_trash_content\"]//tbody//tr") 044 List<WebElement> childDocumentRows; 045 046 public List<WebElement> getChildDocumentRows() { 047 return childDocumentRows; 048 } 049 050 @Required 051 @FindBy(id = "cv_document_trash_content_0_resultsPanel") 052 protected WebElement documentContentForm; 053 054 public TrashSubPage(WebDriver driver) { 055 super(driver); 056 } 057 058 public TrashSubPage emptyTrash() { 059 TrashSubPage page = asPage(TrashSubPage.class); 060 findElementWaitUntilEnabledAndClick(By.id(EMPTY_TRASH_BUTTON_ID)); 061 Alert alert = driver.switchTo().alert(); 062 assertEquals("Permanently delete all documents in trash?", alert.getText()); 063 alert.accept(); 064 return page; 065 } 066 067 public TrashSubPage purgeAllDocuments() { 068 TrashSubPage page = asPage(TrashSubPage.class); 069 By locator = By.id(SELECT_ALL_BUTTON_ID); 070 if (!hasElement(locator)) { 071 // no document to remove 072 return page; 073 } 074 findElementWaitUntilEnabledAndClick(By.id(SELECT_ALL_BUTTON_ID)); 075 deleteSelectedDocuments(); 076 077 try { 078 documentContentForm.findElement(By.tagName("tbody")); 079 } catch (NoSuchElementException e) { 080 // no more document to remove 081 return page; 082 } 083 return purgeAllDocuments(); 084 } 085 086 protected void deleteSelectedDocuments() { 087 findElementWaitUntilEnabledAndClick(By.id(PERMANENT_DELETE_BUTTON_ID)); 088 Alert alert = driver.switchTo().alert(); 089 assertEquals("Permanently delete selected document(s)?", alert.getText()); 090 alert.accept(); 091 } 092 093}