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.nuxeo.functionaltests.Locator; 023import org.nuxeo.functionaltests.pages.profile.ProfilePage; 024import org.nuxeo.functionaltests.pages.tabs.SummaryTabSubPage; 025import org.openqa.selenium.By; 026import org.openqa.selenium.NoSuchElementException; 027import org.openqa.selenium.WebDriver; 028import org.openqa.selenium.WebElement; 029import org.openqa.selenium.support.FindBy; 030 031/** 032 * @since 5.7 033 */ 034public class UserHomePage extends AbstractPage { 035 036 private static final String TASK_XPATH_BASE = ".//table[@class='dataOutput']/tbody/tr[td[normalize-space(text())='%s']]"; 037 038 private static final String DOCUMENT_XPATH_BASE = ".//table[@class='dataOutput']/tbody/tr[td/div/a/span[normalize-space(text())='%s']]"; 039 040 @FindBy(id = "nxw_dashboard_user_tasks") 041 WebElement userTasks; 042 043 @FindBy(id = "nxw_dashboard_user_workspaces") 044 WebElement userWorkspaces; 045 046 @FindBy(id = "nxw_dashboard_user_documents") 047 WebElement userDocuments; 048 049 @FindBy(id = "nxw_dashboard_domain_documents") 050 WebElement domainDocuments; 051 052 @FindBy(id = "selectDashboardDomain:selectDashboardDomainMenu") 053 WebElement selectDomainInput; 054 055 @FindBy(id = "selectDashboardDomain:dashboardDomainSubmitButton") 056 WebElement selectDomainSubmitButton; 057 058 public UserHomePage(WebDriver driver) { 059 super(driver); 060 } 061 062 /** 063 * @since 8.3 064 */ 065 public boolean taskExistsOnUserTasks(String taskName) { 066 try { 067 return getUserTask(taskName).isDisplayed(); 068 } catch (NoSuchElementException e) { 069 return false; 070 } 071 } 072 073 public SummaryTabSubPage redirectToTask(String taskTitle) { 074 waitUntilEnabledAndClick(userTasks.findElement(By.linkText(taskTitle))); 075 return asPage(SummaryTabSubPage.class); 076 } 077 078 /** 079 * @since 8.3 080 */ 081 public boolean isUserTasksEmpty() { 082 return userTasks.getText().contains("Your dashboard is empty"); 083 } 084 085 /** 086 * @since 5.8 087 */ 088 public WorkflowHomePage getWorkflowHomePage() { 089 goToTab("nxw_WorkflowHome"); 090 return asPage(WorkflowHomePage.class); 091 } 092 093 public UserHomePage goToDashboard() { 094 goToTab("nxw_Dashboard"); 095 return this; 096 } 097 098 public ProfilePage goToProfile() { 099 goToTab("nxw_Profile"); 100 return asPage(ProfilePage.class); 101 } 102 103 /** 104 * @since 8.3 105 */ 106 public boolean hasSelectDomainInput() { 107 try { 108 return selectDomainInput.isDisplayed(); 109 } catch (NoSuchElementException e) { 110 return false; 111 } 112 } 113 114 /** 115 * @since 8.3 116 */ 117 public UserHomePage selectDomain(String domainName) { 118 selectItemInDropDownMenu(selectDomainInput, domainName); 119 Locator.waitUntilEnabledAndClick(selectDomainSubmitButton); 120 return asPage(UserHomePage.class); 121 } 122 123 /** 124 * @since 8.3 125 */ 126 public boolean hasUserWorkspace(String workspaceName) { 127 try { 128 return getUserWorkspace(workspaceName) != null; 129 } catch (NoSuchElementException e) { 130 return false; 131 } 132 } 133 134 /** 135 * @since 8.3 136 */ 137 public boolean hasUserDocument(String docName) { 138 try { 139 return getUserDocument(docName) != null; 140 } catch (NoSuchElementException e) { 141 return false; 142 } 143 } 144 145 /** 146 * @since 8.3 147 */ 148 public boolean hasDomainDocument(String docName) { 149 try { 150 return getDomainDocument(docName) != null; 151 } catch (NoSuchElementException e) { 152 return false; 153 } 154 } 155 156 /** 157 * @since 8.3 158 */ 159 public DocumentBasePage goToDomainDocument(String docName) { 160 Locator.findElementWaitUntilEnabledAndClick(getDomainDocument(docName), By.className("documentTitle")); 161 return asPage(DocumentBasePage.class); 162 } 163 164 protected void goToTab(String id) { 165 clickOnTabIfNotSelected("nxw_homeTabs_panel", id); 166 } 167 168 protected WebElement getUserTask(String taskName) { 169 String xpath = String.format(TASK_XPATH_BASE, taskName); 170 return userTasks.findElement(By.xpath(xpath)); 171 } 172 173 protected WebElement getUserWorkspace(String workspaceName) { 174 String xpath = String.format(DOCUMENT_XPATH_BASE, workspaceName); 175 return userWorkspaces.findElement(By.xpath(xpath)); 176 } 177 178 protected WebElement getUserDocument(String docName) { 179 String xpath = String.format(DOCUMENT_XPATH_BASE, docName); 180 return userDocuments.findElement(By.xpath(xpath)); 181 } 182 183 protected WebElement getDomainDocument(String docName) { 184 String xpath = String.format(DOCUMENT_XPATH_BASE, docName); 185 return domainDocuments.findElement(By.xpath(xpath)); 186 } 187 188}