001/* 002 * (C) Copyright 2011 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.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 * Sun Seng David TAN <stan@nuxeo.com> 016 */ 017package org.nuxeo.functionaltests.pages.tabs; 018 019import java.util.ArrayList; 020import java.util.List; 021 022import org.nuxeo.functionaltests.AjaxRequestManager; 023import org.nuxeo.functionaltests.pages.AbstractPage; 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 030/** 031 * @author Sun Seng David TAN <stan@nuxeo.com> 032 */ 033public class SummaryTabSubPage extends AbstractPage { 034 035 private static final String COLLECTIONS_FORM_ID = "nxl_grid_summary_layout:nxw_summary_current_document_collections_form"; 036 037 public static final String WORKFLOW_START_BUTTON_XPATH = "//input[contains(@id, 'nxw_start_route_widget_start_route')]"; 038 039 public static final String WORKFLOW_SELECTOR_XPATH = "//select[contains(@id, 'nxw_start_route_widget')]"; 040 041 @FindBy(xpath = WORKFLOW_START_BUTTON_XPATH) 042 public WebElement startWorkflowBtn; 043 044 @FindBy(xpath = WORKFLOW_SELECTOR_XPATH) 045 public WebElement workflowSelector; 046 047 @FindBy(xpath = "//form[contains(@id, 'nxl_grid_summary_layout:nxw_summary_current_document_single_tasks')]") 048 public WebElement workflowTasksForm; 049 050 @FindBy(xpath = "//div[@class='nxw_lastContributor']") 051 public WebElement lastContributor; 052 053 @FindBy(xpath = "//div[@class='nxw_author']") 054 public WebElement creator; 055 056 @FindBy(xpath = "//span[@id='nxl_grid_summary_layout:nxw_summary_current_document_dublincore_form:nxl_dublincore:nxw_created']") 057 public WebElement createdAt; 058 059 @FindBy(xpath = "//span[@id='nxl_grid_summary_layout:nxw_summary_current_document_dublincore_form:nxl_dublincore:nxw_modified']") 060 public WebElement lastModifiedAt; 061 062 @FindBy(xpath = "//span[@class[starts-with(.,'nxw_contributors_')]]") 063 public List<WebElement> contributors; 064 065 @FindBy(xpath = "//form[@id='nxl_grid_summary_layout:nxw_summary_current_document_states_form']") 066 public WebElement lifeCycleState; 067 068 public SummaryTabSubPage(WebDriver driver) { 069 super(driver); 070 } 071 072 public void startDefaultWorkflow() { 073 AjaxRequestManager a = new AjaxRequestManager(driver); 074 a.watchAjaxRequests(); 075 selectItemInDropDownMenu(workflowSelector, "Serial document review"); 076 a.waitForAjaxRequests(); 077 startWorkflowBtn.click(); 078 } 079 080 public void startDefaultParallelWorkflow() { 081 selectItemInDropDownMenu(workflowSelector, "Parallel document review"); 082 083 startWorkflowBtn.click(); 084 } 085 086 public boolean workflowAlreadyStarted() { 087 return findElementWithTimeout(By.xpath("//*[@id='nxl_grid_summary_layout:nxw_summary_document_route_form']")).getText().contains( 088 "review has been started"); 089 } 090 091 public boolean openTaskForCurrentUser() { 092 return findElementWithTimeout( 093 By.xpath("//form[contains(@id, 'nxl_grid_summary_layout:nxw_summary_current_document_single_tasks')]")).getText().contains( 094 "Please accept or reject the document"); 095 } 096 097 /** 098 * @since 5.8 099 */ 100 public boolean parallelOpenTaskForCurrentUser() { 101 return findElementWithTimeout( 102 By.xpath("//form[contains(@id, 'nxl_grid_summary_layout:nxw_summary_current_document_single_tasks')]")).getText().contains( 103 "Please give your opinion. Click on N/A if you have no advice."); 104 } 105 106 public WorkflowTabSubPage getWorkflow() { 107 clickOnTabIfNotSelected("nxw_documentTabs_panel", "nxw_TAB_ROUTE_WORKFLOW"); 108 return asPage(WorkflowTabSubPage.class); 109 } 110 111 public boolean cantStartWorkflow() { 112 return findElementWithTimeout( 113 By.xpath("//form[contains(@id, 'nxl_grid_summary_layout:nxw_summary_document_route_form')]")).getText().contains( 114 "No workflow process can be started on this document."); 115 } 116 117 /** 118 * Get the creator of the doc. 119 * 120 * @since 5.8 121 */ 122 public String getCreator() { 123 return creator.getText(); 124 } 125 126 /** 127 * Get the last contributor of the doc. 128 * 129 * @since 5.8 130 */ 131 public String getLastContributor() { 132 return lastContributor.getText(); 133 } 134 135 /** 136 * Get the list of contributors of the doc. 137 * 138 * @since 5.8 139 */ 140 public List<String> getContributors() { 141 List<String> result = new ArrayList<String>(); 142 for (WebElement contributor : contributors) { 143 result.add(contributor.getText()); 144 } 145 return result; 146 } 147 148 /** 149 * @since 5.8 150 */ 151 public String getCurrentLifeCycleState() { 152 return lifeCycleState.findElement(By.className("sticker")).getText(); 153 } 154 155 /** 156 * @since 5.9.3 157 */ 158 public boolean isCollectionsFormDisplayed() { 159 try { 160 driver.findElement(By.id(COLLECTIONS_FORM_ID)); 161 return true; 162 } catch (NoSuchElementException e) { 163 return false; 164 } 165 } 166 167 /** 168 * @since 5.9.3 169 */ 170 public int getCollectionCount() { 171 return driver.findElement(By.id(COLLECTIONS_FORM_ID)).findElements( 172 By.xpath("div/span[@id='nxl_grid_summary_layout:nxw_summary_current_document_collections_form:collections']/span[@class='tag tagLink']")).size(); 173 } 174}