001/* 002 * (C) Copyright 2013 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 * Mariana Cedica 016 */ 017package org.nuxeo.functionaltests.pages; 018 019import org.apache.commons.logging.Log; 020import org.apache.commons.logging.LogFactory; 021import org.nuxeo.functionaltests.AbstractTest; 022import org.nuxeo.functionaltests.Locator; 023import org.nuxeo.functionaltests.Required; 024import org.nuxeo.functionaltests.forms.Select2WidgetElement; 025import org.nuxeo.functionaltests.fragment.WebFragmentImpl; 026import org.nuxeo.functionaltests.pages.tabs.SummaryTabSubPage; 027import org.openqa.selenium.By; 028import org.openqa.selenium.WebDriver; 029import org.openqa.selenium.WebElement; 030import org.openqa.selenium.support.FindBy; 031import org.openqa.selenium.support.ui.ExpectedConditions; 032import org.openqa.selenium.support.ui.WebDriverWait; 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 void processFirstTask() { 064 userTasksPanel.findElement(By.xpath("//input[@type='submit' and @value='Process']")).click(); 065 } 066 067 public SummaryTabSubPage redirectToTask(String taskTitle) { 068 driver.findElement(By.linkText(taskTitle)).click(); 069 return new SummaryTabSubPage(driver); 070 } 071 072 public boolean isTasksDashboardEmpty() { 073 return !userTasksPanel.getText().contains("Task Name"); 074 } 075 076 /** 077 * @since 5.9.1 078 */ 079 public void reassignTask(String taskDirective, String user) { 080 TaskFancyBoxFragment taskBox = showTaskFancyBox("Reassign Task"); 081 taskBox.waitForTextToBePresent(taskDirective); 082 Select2WidgetElement particpants = new Select2WidgetElement( 083 driver, 084 driver.findElement(By.xpath("//div[contains(@id, 'nxl_workflowTaskReassignmentLayout_1:nxw_task_reassignment_actors_1_select2')]")), 085 true); 086 particpants.selectValue(user); 087 taskBox.submit(); 088 } 089 090 /** 091 * @since 5.9.1 092 */ 093 public void delegateTask(String taskDirective, String user) { 094 TaskFancyBoxFragment taskBox = showTaskFancyBox("Delegate Task"); 095 taskBox.waitForTextToBePresent(taskDirective); 096 Select2WidgetElement particpants = new Select2WidgetElement( 097 driver, 098 driver.findElement(By.xpath("//div[contains(@id, 'nxl_workflowTaskReassignmentLayout:nxw_task_reassignment_actors_select2')]")), 099 true); 100 particpants.selectValue(user); 101 taskBox.submit(); 102 } 103 104 /** 105 * @since 5.9.1 106 */ 107 public TaskFancyBoxFragment showTaskFancyBox(String taskAction) { 108 driver.findElement(By.xpath(String.format("//input[@type='submit' and @value='%s']", taskAction))).click(); 109 WebElement element = getFancyBoxContent(); 110 return getWebFragment(element, WorkflowHomePage.TaskFancyBoxFragment.class); 111 } 112 113 /** 114 * @since 5.9.1 115 */ 116 public static class TaskFancyBoxFragment extends WebFragmentImpl { 117 118 @FindBy(xpath = "//div[@id='fancybox-content']//input[@value='Cancel']") 119 public WebElement cancelButton; 120 121 @FindBy(xpath = "//div[@id='fancybox-content']//input[@type='submit']") 122 public WebElement sumbitButton; 123 124 public TaskFancyBoxFragment(WebDriver driver, WebElement element) { 125 super(driver, element); 126 } 127 128 public void cancel() { 129 cancelButton.click(); 130 // make sure the fancybox content is not loaded anymore 131 WebDriverWait wait = new WebDriverWait(driver, AbstractTest.LOAD_TIMEOUT_SECONDS); 132 wait.until(ExpectedConditions.invisibilityOfElementLocated(By.id("fancybox-content"))); 133 } 134 135 @Override 136 public void submit() { 137 sumbitButton.click(); 138 // make sure the fancybox content is not loaded anymore 139 WebDriverWait wait = new WebDriverWait(driver, AbstractTest.LOAD_TIMEOUT_SECONDS); 140 wait.until(ExpectedConditions.invisibilityOfElementLocated(By.id("fancybox-content"))); 141 } 142 } 143}