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