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 * Mariana Cedica 018 * Yannis JULIENNE 019 */ 020package org.nuxeo.functionaltests.pages; 021 022import org.apache.commons.logging.Log; 023import org.apache.commons.logging.LogFactory; 024import org.nuxeo.functionaltests.Locator; 025import org.nuxeo.functionaltests.Required; 026import org.nuxeo.functionaltests.forms.Select2WidgetElement; 027import org.nuxeo.functionaltests.fragment.WebFragmentImpl; 028import org.nuxeo.functionaltests.pages.tabs.SummaryTabSubPage; 029import org.openqa.selenium.By; 030import org.openqa.selenium.WebDriver; 031import org.openqa.selenium.WebElement; 032import org.openqa.selenium.support.FindBy; 033 034/** 035 * @since 5.8 036 */ 037public class WorkflowHomePage extends AbstractPage { 038 039 protected static final Log log = LogFactory.getLog(WorkflowHomePage.class); 040 041 public WorkflowHomePage(WebDriver driver) { 042 super(driver); 043 } 044 045 @Required 046 @FindBy(xpath = "//div[contains(@id, 'cv_user_open_tasks_nxw_current_user_open_tasks_resultsPanel')]") 047 protected WebElement userTasksPanel; 048 049 @Required 050 @FindBy(id = "nxl_userOpenTasksLayout:nxw_contentViewActions_refreshContentView_form:nxw_contentViewActions_refreshContentView") 051 protected WebElement refreshTask; 052 053 @Required 054 @FindBy(linkText = "Workflow") 055 public WebElement workflowLink; 056 057 public boolean taskExistsOnTasksDashboard(String taskName) { 058 WebElement taskNameEl = Locator.findElementWithTimeout( 059 By.xpath("//span[contains(@id, 'nxw_routing_task_name')]"), userTasksPanel); 060 return taskName.equals(taskNameEl.getText()); 061 } 062 063 public boolean taskDisplaysDocumentOnTasksDashboard(String docTitle) { 064 WebElement targetDocumentTd = Locator.findElementWithTimeout( 065 By.xpath("//td[contains(text(), '" + docTitle + "')]"), userTasksPanel); 066 return targetDocumentTd != null; 067 } 068 069 public void processFirstTask() { 070 WebElement processButton = userTasksPanel.findElement(By.xpath("//input[@type='submit' and @value='Process']")); 071 waitUntilEnabledAndClick(processButton); 072 } 073 074 public SummaryTabSubPage redirectToTask(String taskTitle) { 075 findElementWaitUntilEnabledAndClick(By.linkText(taskTitle)); 076 return new SummaryTabSubPage(driver); 077 } 078 079 public boolean isTasksDashboardEmpty() { 080 return !userTasksPanel.getText().contains("Task Name"); 081 } 082 083 /** 084 * @since 5.9.1 085 */ 086 public void reassignTask(String taskDirective, String user) { 087 TaskFancyBoxFragment taskBox = showTaskFancyBox("Reassign Task"); 088 taskBox.waitForTextToBePresent(taskDirective); 089 Select2WidgetElement particpants = new Select2WidgetElement(driver, 090 driver.findElement(By 091 .xpath("//div[contains(@id, 'nxl_workflowTaskReassignmentLayout_1:nxw_task_reassignment_actors_1_select2')]")), 092 true); 093 particpants.selectValue(user); 094 taskBox.submit(); 095 } 096 097 /** 098 * @since 5.9.1 099 */ 100 public void delegateTask(String taskDirective, String user) { 101 TaskFancyBoxFragment taskBox = showTaskFancyBox("Delegate Task"); 102 taskBox.waitForTextToBePresent(taskDirective); 103 Select2WidgetElement particpants = new Select2WidgetElement(driver, 104 driver.findElement(By 105 .xpath("//div[contains(@id, 'nxl_workflowTaskReassignmentLayout:nxw_task_reassignment_actors_select2')]")), 106 true); 107 particpants.selectValue(user); 108 taskBox.submit(); 109 } 110 111 /** 112 * @since 5.9.1 113 */ 114 public TaskFancyBoxFragment showTaskFancyBox(String taskAction) { 115 findElementWaitUntilEnabledAndClick( 116 By.xpath(String.format("//input[@type='submit' and @value='%s']", taskAction))); 117 WebElement element = AbstractPage.getFancyBoxContent(); 118 return getWebFragment(element, WorkflowHomePage.TaskFancyBoxFragment.class); 119 } 120 121 /** 122 * @since 5.9.1 123 */ 124 public static class TaskFancyBoxFragment extends WebFragmentImpl { 125 126 @FindBy(xpath = "//div[@id='fancybox-content']//input[@value='Cancel']") 127 public WebElement cancelButton; 128 129 @FindBy(xpath = "//div[@id='fancybox-content']//input[@type='submit']") 130 public WebElement sumbitButton; 131 132 public TaskFancyBoxFragment(WebDriver driver, WebElement element) { 133 super(driver, element); 134 } 135 136 public void cancel() { 137 Locator.waitUntilEnabledAndClick(cancelButton); 138 AbstractPage.waitForFancyBoxClosed(); 139 } 140 141 @Override 142 public void submit() { 143 Locator.waitUntilEnabledAndClick(sumbitButton); 144 AbstractPage.waitForFancyBoxClosed(); 145 } 146 147 } 148}