001/** 002 * Copyright 2005-2015 The Kuali Foundation 003 * 004 * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php 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 */ 016package edu.sampleu.main; 017 018import org.junit.Before; 019import org.kuali.rice.testtools.selenium.AutomatedFunctionalTestUtils; 020import org.kuali.rice.testtools.selenium.WebDriverLegacyITBase; 021import org.kuali.rice.testtools.selenium.WebDriverUtils; 022import org.junit.Test; 023import org.openqa.selenium.By; 024 025/** 026 * @author Kuali Rice Team (rice.collab@kuali.org) 027 */ 028public class CreateNewAgendaAft extends WebDriverLegacyITBase { 029 030 protected static final String NAME_LABEL = "Name:"; 031 protected static final String NAMESPACE_LABEL = "Namespace:"; 032 protected static final String CONTEXT_LABEL = "Context:"; 033 private boolean useUi = false; 034 035 protected static String[][] inputVerifyDetails; 036 037 /** 038 * ITUtil.PORTAL + "?channelTitle=Create%20New%20Agenda&channelUrl=" + WebDriverUtils.getBaseUrlString() + 039 * "/kr-krad/krmsAgendaEditor?methodToCall=start&dataObjectClassName=org.kuali.rice.krms.impl.ui.AgendaEditor&returnLocation=" + 040 * ITUtil.PORTAL_URL + ITUtil.HIDE_RETURN_LINK; 041 */ 042 public static final String BOOKMARK_URL = AutomatedFunctionalTestUtils.PORTAL + "?channelTitle=Create%20New%20Agenda&channelUrl=" + WebDriverUtils 043 .getBaseUrlString() +"/kr-krad/krmsAgendaEditor?methodToCall=start&dataObjectClassName=org.kuali.rice.krms.impl.ui.AgendaEditor&returnLocation=" + 044 AutomatedFunctionalTestUtils.PORTAL_URL + AutomatedFunctionalTestUtils.HIDE_RETURN_LINK; 045 046 @Before 047 @Override 048 public void testSetUp() { 049 super.testSetUp(); 050 inputVerifyDetails = new String[][] { 051 {NAME_LABEL, getDescriptionUnique()}, 052 {NAMESPACE_LABEL, "Kuali Rules Test"}, 053 {CONTEXT_LABEL, "Context1"} 054 }; 055 056 } 057 058 @Override 059 protected String getBookmarkUrl() { 060 return BOOKMARK_URL; 061 } 062 063 // Lots of Overrides as KRMS was early KRAD 064 @Override 065 protected void assertBlanketApproveButtonsPresent() { 066 assertTrue(isVisible(By.xpath("//button[contains( text(), 'Cancel')]"))); 067 assertTrue(isVisible(By.xpath("//button[contains( text(), 'Save')]"))); 068 assertTrue(isVisible(By.xpath("//button[contains( text(), 'Blanket Approve')]"))); 069 assertTrue(isVisible(By.xpath("//button[contains( text(), 'Submit')]"))); 070 } 071 072 @Override 073 protected void assertRouteStatus(String status) throws InterruptedException { 074 super.assertRouteStatus(status); 075 } 076 077 private void verify(String docId) throws InterruptedException { 078 waitAndClickLinkContainingText(docId); 079 080 driver.switchTo().window((String) driver.getWindowHandles().toArray()[1]); 081 082 waitIsVisible(By.xpath("//tr/th/label[contains(text(), '" + CONTEXT_LABEL + "')]")); 083 assertLabeledTextPresent(inputVerifyDetails); 084 screenshot(); 085 } 086 087 private void verifyInputs(String docId) throws InterruptedException { 088 waitAndClickLinkContainingText(docId); 089 090 driver.switchTo().window((String) driver.getWindowHandles().toArray()[1]); 091 092 waitIsVisible(By.xpath("//tr/th/label[contains(text(), '" + CONTEXT_LABEL + "')]")); 093 assertLabeledInputTextPresent(inputVerifyDetails); 094 screenshot(); 095 } 096 097 @Override 098 public void checkForDocError() { 099 checkForDocErrorKrad(); 100 } 101 102 @Override 103 protected void waitAndClickBlanketApproveKns() throws InterruptedException { 104 waitAndClickBlanketApprove(); 105 waitAndClickConfirmBlanketApproveOk(); 106 acceptAlertIfPresent(); 107 waitForProgressLoading(); 108 } 109 110 @Override 111 protected void waitAndCancelConfirmation() throws InterruptedException { 112 waitAndClickCancel(); 113 acceptAlertIfPresent(); 114 waitAndClickConfirmCancelOk(); 115 } 116 117 @Override 118 protected void waitAndClickCancel() throws InterruptedException { 119 waitAndClickCancelByText(); 120 } 121 122 @Override 123 protected void waitAndCreateNew() { 124 // no-op as the create new link is on the portal page. 125 } 126 127 @Override 128 protected String waitForDocId() throws InterruptedException { 129 checkForDocError(); 130 String docId = waitForLabeledText("Document Number:"); 131 jGrowl("Document Number is " + docId); 132 return docId; 133 } 134 135 @Override 136 protected void waitAndClickSave() throws InterruptedException { 137 waitAndClickSaveByText(); 138 } 139 140 @Override 141 protected void waitAndClickSubmit() throws InterruptedException { 142 waitAndClickSubmitByText(); 143 } 144 145 @Override 146 protected void waitForSuccessfulSaveMessage() throws InterruptedException { 147 assertTrue(waitForElementVisibleBy(By.xpath("//div[@id='AgendaEditorView-Agenda-Page_messages']")).getText() 148 .contains("Document was successfully saved.")); 149 } 150 151 @Override 152 protected void waitForSuccessfulSubmitMessage() throws InterruptedException { 153 waitAndClickConfirmSubmitOk(); 154 checkForDocErrorKrad(); 155 assertTrue(waitForElementVisibleBy(By.xpath("//div[@id='AgendaEditorView-Agenda-Page_messages']")).getText().contains("Document was successfully submitted.")); 156 } 157 158 @Override 159 protected void testCreateNewRequired() throws Exception { 160 selectFrameIframePortlet(); 161 waitAndCreateNew(); 162 waitAndClickSubmit(); 163 String mainError = waitForElementVisibleBy(By.xpath("//div[@id='AgendaEditorView-Agenda-Page_messages']")).getText(); 164 assertTrue(mainError + " does not contain Agenda: 3 errors", mainError.contains("Agenda: 3 errors")); 165 String detailError = waitForElementVisibleBy(By.xpath("//section[@data-parent='AgendaEditorView-Agenda-Page']/div/div")).getText(); 166 assertTrue(detailError + " does not contain 3 errors", detailError.contains("3 errors")); 167 assertTrue(detailError + " does not contain Namespace: Required", detailError.contains("Namespace: Required")); 168 assertTrue(detailError + " does not contain Name: Required", detailError.contains("Name: Required")); 169 assertTrue(detailError + " does not contain Context: Required", detailError.contains("Context: Required")); 170 171 // verify required fields divs have the uif-hasError class 172 isVisible(By.xpath("//select[@name='document.newMaintainableObject.dataObject.namespace']/../../div[@class='uif-inputField uif-hasError']")); 173 isVisible(By.xpath("//input[@name='document.newMaintainableObject.dataObject.agenda.name']/../../div[@class='uif-inputField uif-hasError']")); 174 isVisible(By.xpath("//input[@name='document.newMaintainableObject.dataObject.contextName']/../../div[@class='uif-inputField uif-hasError']")); 175 } 176 177 @Override 178 protected String verifyDocInitiated() throws InterruptedException { 179 String docId = waitForDocId(); 180 assertEquals("INITIATED", waitForLabeledText("Document Status:")); 181 assertEquals(getUserName(), waitForLabeledText(" Initiator Network Id:")); 182 return docId; 183 } 184 185 @Override 186 protected void navigate() throws Exception { 187 useUi = true; // nav test will use UI components (lookups), bookmark types it in 188 waitForTitleToEqualKualiPortalIndex(); 189 selectTopFrame(); 190 waitAndClickByLinkText("Main Menu",""); 191 waitForTitleToEqualKualiPortalIndex(); 192 waitAndClickByLinkText("Create New Agenda", ""); 193 waitForTitleToEqualKualiPortalIndex(""); 194 selectFrameIframePortlet(); 195 checkForIncidentReport("Create New Agenda", ""); 196 } 197 198 protected void createNewEnterDetails() throws InterruptedException { 199 selectFrameIframePortlet(); 200 waitAndSelectLabeled(NAMESPACE_LABEL, inputVerifyDetails[1][1]); 201 inputDetails(); 202 203 if (useUi) { 204 waitAndClickLabeledQuickFinder(CONTEXT_LABEL); 205 waitForProgressLoading(); 206 gotoIframeByXpath("//iframe"); 207 waitAndClickSearchByText(); 208 waitAndClickReturnValue(); // Context1 209 selectTopFrame(); 210 gotoNestedFrame(); 211 } 212 } 213 214 @Override 215 protected void createNewLookupDetails() throws InterruptedException { 216 createNewEnterDetails(); 217 } 218 219 private void inputDetails() throws InterruptedException { 220 waitAndTypeLabeledInput(NAME_LABEL, inputVerifyDetails[0][1]); 221 if (!useUi) { 222 waitAndTypeLabeledInput(CONTEXT_LABEL, inputVerifyDetails[2][1]); 223 } 224 } 225 226 @Test 227 public void testCreateNewCancelBookmark() throws Exception { 228 // Use the UI to populate the context so that the cancel confirmation popups are the same for both the 229 // nav and bookmark tests. 230 useUi = true; 231 testCreateNewCancel(); 232 passed(); 233 } 234 235 @Test 236 public void testCreateNewCancelNav() throws Exception { 237 testCreateNewCancel(); 238 passed(); 239 } 240 241 @Test 242 public void testCreateNewRequiredBookmark() throws Exception { 243 testCreateNewRequired(); 244 passed(); 245 } 246 247 @Test 248 public void testCreateNewRequiredNav() throws Exception { 249 testCreateNewRequired(); 250 passed(); 251 } 252 253 @Test 254 public void testCreateNewSaveBookmark() throws Exception { 255 verifyInputs(testCreateNewSave()); 256 passed(); 257 } 258 259 @Test 260 public void testCreateNewSaveNav() throws Exception { 261 verifyInputs(testCreateNewSave()); 262 passed(); 263 } 264 265 @Test 266 public void testCreateNewSaveSubmitBookmark() throws Exception { 267 verify(testCreateNewSaveSubmit()); 268 passed(); 269 } 270 271 @Test 272 public void testCreateNewSaveSubmitNav() throws Exception { 273 verify(testCreateNewSaveSubmit()); 274 passed(); 275 } 276 277 @Test 278 public void testCreateNewSubmitBookmark() throws Exception { 279 verify(testCreateNewSubmit()); 280 passed(); 281 } 282 283 @Test 284 public void testCreateNewSubmitNav() throws Exception { 285 verify(testCreateNewSubmit()); 286 passed(); 287 } 288 289 @Test 290 public void testBlanketAppBookmark() throws Exception { 291 verify(testBlanketApprove()); 292 passed(); 293 } 294 295 @Test 296 public void testBlanketAppNav() throws Exception { 297 verify(testBlanketApprove()); 298 passed(); 299 } 300}