001/* 002 * (C) Copyright 2016 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 * Sun Seng David TAN <stan@nuxeo.com> 018 * Yannis JULIENNE 019 */ 020package org.nuxeo.functionaltests.pages.tabs; 021 022import java.util.ArrayList; 023import java.util.List; 024 025import org.nuxeo.functionaltests.AjaxRequestManager; 026import org.nuxeo.functionaltests.Locator; 027import org.nuxeo.functionaltests.Required; 028import org.nuxeo.functionaltests.pages.AbstractPage; 029import org.openqa.selenium.By; 030import org.openqa.selenium.NoSuchElementException; 031import org.openqa.selenium.WebDriver; 032import org.openqa.selenium.WebElement; 033import org.openqa.selenium.support.FindBy; 034 035/** 036 * @author Sun Seng David TAN <stan@nuxeo.com> 037 */ 038public class SummaryTabSubPage extends AbstractPage { 039 040 private static final String COLLECTIONS_FORM_ID = "nxl_grid_summary_layout:nxw_summary_current_document_collections_form"; 041 042 public static final String WORKFLOW_START_BUTTON_XPATH = "//input[contains(@id, 'nxw_start_route_widget_start_route')]"; 043 044 public static final String WORKFLOW_SELECTOR_XPATH = "//select[contains(@id, 'nxw_start_route_widget')]"; 045 046 @FindBy(xpath = WORKFLOW_START_BUTTON_XPATH) 047 public WebElement startWorkflowBtn; 048 049 @FindBy(xpath = WORKFLOW_SELECTOR_XPATH) 050 public WebElement workflowSelector; 051 052 @FindBy(xpath = "//form[contains(@id, 'nxl_grid_summary_layout:nxw_summary_current_document_single_tasks')]") 053 public WebElement workflowTasksForm; 054 055 @FindBy(xpath = "//div[@class='nxw_lastContributor']") 056 public WebElement lastContributor; 057 058 @FindBy(xpath = "//div[@class='nxw_author']") 059 public WebElement creator; 060 061 @FindBy(xpath = "//span[@id='nxl_grid_summary_layout:nxw_summary_current_document_dublincore_form:nxl_dublincore:nxw_created']") 062 public WebElement createdAt; 063 064 @FindBy(xpath = "//span[@id='nxl_grid_summary_layout:nxw_summary_current_document_dublincore_form:nxl_dublincore:nxw_modified']") 065 public WebElement lastModifiedAt; 066 067 @FindBy(xpath = "//span[@class[starts-with(.,'nxw_contributors_')]]") 068 public List<WebElement> contributors; 069 070 @FindBy(xpath = "//form[@id='nxl_grid_summary_layout:nxw_summary_current_document_states_form']") 071 public WebElement lifeCycleState; 072 073 @Required 074 @FindBy(xpath = "//div[@class='publication_block']") 075 public WebElement publicationBlock; 076 077 public SummaryTabSubPage(WebDriver driver) { 078 super(driver); 079 } 080 081 public SummaryTabSubPage startDefaultWorkflow() { 082 AjaxRequestManager a = new AjaxRequestManager(driver); 083 a.watchAjaxRequests(); 084 selectItemInDropDownMenu(workflowSelector, "Serial document review"); 085 a.waitForAjaxRequests(); 086 Locator.waitUntilEnabledAndClick(startWorkflowBtn); 087 return asPage(SummaryTabSubPage.class); 088 } 089 090 public SummaryTabSubPage startDefaultParallelWorkflow() { 091 selectItemInDropDownMenu(workflowSelector, "Parallel document review"); 092 Locator.waitUntilEnabledAndClick(startWorkflowBtn); 093 return asPage(SummaryTabSubPage.class); 094 } 095 096 public boolean workflowAlreadyStarted() { 097 return findElementWithTimeout( 098 By.xpath("//*[@id='nxl_grid_summary_layout:nxw_summary_document_route_form']")).getText().contains( 099 "review has been started"); 100 } 101 102 public boolean openTaskForCurrentUser() { 103 return findElementWithTimeout(By.xpath( 104 "//form[contains(@id, 'nxl_grid_summary_layout:nxw_summary_current_document_single_tasks')]")).getText() 105 .contains( 106 "Please accept or reject the document"); 107 } 108 109 /** 110 * @since 5.8 111 */ 112 public boolean parallelOpenTaskForCurrentUser() { 113 return findElementWithTimeout(By.xpath( 114 "//form[contains(@id, 'nxl_grid_summary_layout:nxw_summary_current_document_single_tasks')]")).getText() 115 .contains( 116 "Please give your opinion. Click on N/A if you have no advice."); 117 } 118 119 public WorkflowTabSubPage getWorkflow() { 120 clickOnTabIfNotSelected("nxw_documentTabs_panel", "nxw_TAB_ROUTE_WORKFLOW"); 121 return asPage(WorkflowTabSubPage.class); 122 } 123 124 public boolean cantStartWorkflow() { 125 return findElementWithTimeout(By.xpath( 126 "//form[contains(@id, 'nxl_grid_summary_layout:nxw_summary_document_route_form')]")).getText().contains( 127 "No workflow process can be started on this document."); 128 } 129 130 /** 131 * Get the creator of the doc. 132 * 133 * @since 5.8 134 */ 135 public String getCreator() { 136 return creator.getText(); 137 } 138 139 /** 140 * Get the last contributor of the doc. 141 * 142 * @since 5.8 143 */ 144 public String getLastContributor() { 145 return lastContributor.getText(); 146 } 147 148 /** 149 * Get the list of contributors of the doc. 150 * 151 * @since 5.8 152 */ 153 public List<String> getContributors() { 154 List<String> result = new ArrayList<String>(); 155 for (WebElement contributor : contributors) { 156 result.add(contributor.getText()); 157 } 158 return result; 159 } 160 161 /** 162 * @since 5.8 163 */ 164 public String getCurrentLifeCycleState() { 165 return lifeCycleState.findElement(By.className("sticker")).getText(); 166 } 167 168 /** 169 * @since 5.9.3 170 */ 171 public boolean isCollectionsFormDisplayed() { 172 try { 173 driver.findElement(By.id(COLLECTIONS_FORM_ID)); 174 return true; 175 } catch (NoSuchElementException e) { 176 return false; 177 } 178 } 179 180 /** 181 * @since 5.9.3 182 */ 183 public int getCollectionCount() { 184 return driver.findElement(By.id(COLLECTIONS_FORM_ID)) 185 .findElements(By.xpath( 186 "div/span[@id='nxl_grid_summary_layout:nxw_summary_current_document_collections_form:collections']/span[@class='tag tagLink']")) 187 .size(); 188 } 189 190 /** 191 * @since 8.3 192 */ 193 public boolean isPublished() { 194 try { 195 return publicationBlock.getText().contains("This document is published."); 196 } catch (NoSuchElementException e) { 197 // no publication block 198 return false; 199 } 200 } 201 202 /** 203 * @since 8.3 204 */ 205 public boolean isAwaitingPublication() { 206 try { 207 return publicationBlock.getText().contains("This document is waiting for a publication approval."); 208 } catch (NoSuchElementException e) { 209 // no publication block 210 return false; 211 } 212 } 213 214 /** 215 * @since 8.3 216 */ 217 public boolean hasApprovePublicationButton() { 218 try { 219 return publicationBlock.findElement(By.xpath(".//input[@value='Approve']")) != null; 220 } catch (NoSuchElementException e) { 221 return false; 222 } 223 } 224 225 /** 226 * @since 8.3 227 */ 228 public SummaryTabSubPage approvePublication() { 229 Locator.findElementWaitUntilEnabledAndClick(publicationBlock, By.xpath(".//input[@value='Approve']")); 230 return asPage(SummaryTabSubPage.class); 231 } 232 233 /** 234 * @since 8.3 235 */ 236 public boolean hasRejectPublicationComment() { 237 try { 238 return publicationBlock.findElement(By.xpath(".//*[contains(@name, 'rejectPublishingComment')]")) != null; 239 } catch (NoSuchElementException e) { 240 return false; 241 } 242 } 243 244 /** 245 * @since 8.3 246 */ 247 public boolean hasRejectPublicationButton() { 248 try { 249 return publicationBlock.findElement(By.xpath(".//input[@value='Reject']")) != null; 250 } catch (NoSuchElementException e) { 251 return false; 252 } 253 } 254 255 /** 256 * @since 8.3 257 */ 258 public void rejectPublication(String comment) { 259 WebElement text = publicationBlock.findElement(By.xpath(".//*[contains(@name, 'rejectPublishingComment')]")); 260 text.sendKeys(comment); 261 Locator.findElementWaitUntilEnabledAndClick(publicationBlock, By.xpath(".//input[@value='Reject']")); 262 } 263}