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.apache.commons.io.FileUtils; 019import org.junit.Rule; 020import org.junit.Test; 021import org.junit.rules.TemporaryFolder; 022import org.kuali.rice.krad.uif.UifPropertyPaths; 023import org.kuali.rice.krad.util.KRADConstants; 024import org.kuali.rice.testtools.selenium.AutomatedFunctionalTestUtils; 025import org.kuali.rice.testtools.selenium.WebDriverUtils; 026import org.openqa.selenium.By; 027 028import java.io.File; 029 030/** 031 * Tests the Notes and Attachments in the People Flow screen. 032 * 033 * @author Kuali Rice Team (rice.collab@kuali.org) 034 */ 035public class PeopleFlowCreateNewNotesAndAttachmentsAft extends PeopleFlowCreateNewAftBase { 036 037 /** 038 * WebDriverUtils.getBaseUrlString() + "/kr-krad/peopleFlowMaintenance?" + 039 * "viewTypeName=MAINTENANCE&returnLocation=" + AutomatedFunctionalTestUtils.PORTAL_URL_ENCODED + "&methodToCall=start&" + 040 * "dataObjectClassName=org.kuali.rice.kew.impl.peopleflow.PeopleFlowBo" 041 */ 042 public static final String BOOKMARK_URL = WebDriverUtils.getBaseUrlString() + "/kr-krad/peopleFlowMaintenance?" + 043 "viewTypeName=MAINTENANCE&returnLocation=" + AutomatedFunctionalTestUtils.PORTAL_URL_ENCODED + "&methodToCall=start&" + 044 "dataObjectClassName=org.kuali.rice.kew.impl.peopleflow.PeopleFlowBo"; 045 046 /** 047 * Provider of the temporary folder. 048 */ 049 @Rule 050 public TemporaryFolder temporaryFolder = new TemporaryFolder(); 051 052 private static final String NOTES_AND_ATTACHMENTS_PREFIX = UifPropertyPaths.NEW_COLLECTION_LINES 053 + "['" 054 + KRADConstants.DOCUMENT_PROPERTY_NAME 055 + "." 056 + KRADConstants.NOTES_PROPERTY_NAME 057 + "']"; 058 059 @Override 060 public String getBookmarkUrl() { 061 return BOOKMARK_URL; 062 } 063 064 /** 065 * Tests adding both the required note and an optional attachment. 066 * 067 * @throws Exception when an error is encountered in the test 068 */ 069 @Test 070 public void testPeopleFlowCreateNewNotesAndAttachments_DefaultAttachmentBookmark() throws Exception { 071 testDefaultAttachement(); 072 } 073 074 /** 075 * Tests adding both the required note and an optional attachment. 076 * 077 * @throws Exception when an error is encountered in the test 078 */ 079 @Test 080 public void testPeopleFlowCreateNewNotesAndAttachments_DefaultAttachmentNav() throws Exception { 081 navigateToCreateNew(); 082 083 testDefaultAttachement(); 084 } 085 086 protected void testDefaultAttachement() throws Exception { 087 navigateToNotesAndAttachments(); 088 waitAndTypeByName(NOTES_AND_ATTACHMENTS_PREFIX + "." + KRADConstants.NOTE_TEXT_PROPERTY_NAME, 089 "Attachment_Note"); 090 waitAndAddAttachment("attachment.txt", "Testing123"); 091 waitAndClick(By.cssSelector("button[title='Add a Note']")); 092 093 Thread.sleep(2000); 094 095 waitForTextPresent("Attachment_Note"); 096 assertTextPresent("attachment.txt"); 097 assertTextNotPresent("Note Text is a required field."); 098 passed(); 099 } 100 101 /** 102 * Tests adding just the required note. 103 * 104 * @throws Exception when an error is encountered in the test 105 */ 106 @Test 107 public void testPeopleFlowCreateNewNotesAndAttachments_DefaultNoAttachmentBookmark() throws Exception { 108 testDefaultNoAttachment(); 109 } 110 111 /** 112 * Tests adding just the required note. 113 * 114 * @throws Exception when an error is encountered in the test 115 */ 116 @Test 117 public void testPeopleFlowCreateNewNotesAndAttachments_DefaultNoAttachmentNav() throws Exception { 118 navigateToCreateNew(); 119 120 testDefaultNoAttachment(); 121 } 122 123 protected void testDefaultNoAttachment() throws InterruptedException { 124 navigateToNotesAndAttachments(); 125 waitAndTypeByName(NOTES_AND_ATTACHMENTS_PREFIX + "." + KRADConstants.NOTE_TEXT_PROPERTY_NAME, 126 "Attachment_Note"); 127 waitAndClick(By.cssSelector("button[title='Add a Note']")); 128 129 waitForTextPresent("Attachment_Note"); 130 assertTextNotPresent("Note Text is a required field"); 131 passed(); 132 } 133 134 /** 135 * Tests adding just the optional attachment, which should result in an error. 136 * 137 * @throws Exception when an error is encountered in the test 138 */ 139 @Test 140 public void testPeopleFlowCreateNewNotesAndAttachments_NoNoteTextBookmark() throws Exception { 141 testNoNoteText(); 142 } 143 144 /** 145 * Tests adding just the optional attachment, which should result in an error. 146 * 147 * @throws Exception when an error is encountered in the test 148 */ 149 @Test 150 public void testPeopleFlowCreateNewNotesAndAttachments_NoNoteTextNav() throws Exception { 151 navigateToCreateNew(); 152 153 testNoNoteText(); 154 } 155 156 protected void testNoNoteText() throws Exception { 157 navigateToNotesAndAttachments(); 158 waitAndAddAttachment("attachment.txt", "Testing123"); 159 waitAndClick(By.cssSelector("button[title='Add a Note']")); 160 161 Thread.sleep(2000); 162 waitForTextPresent("Note Text is a required field"); 163 assertTextNotPresent("attachment.txt"); 164 passed(); 165 } 166 167 protected void navigateToCreateNew() throws Exception { 168 selectFrameIframePortlet(); 169 waitAndClickByLinkText("Create New"); 170 } 171 172 private void navigateToNotesAndAttachments() throws InterruptedException { 173 waitForElementPresent( 174 "div[data-header_for='PeopleFlow-MaintenanceView'] div[data-label='Document Number'] > span"); 175 176 waitAndClickByLinkText("Notes and Attachments (0)"); 177 } 178 179 private void waitAndAddAttachment(String fileName, String content) throws Exception { 180 File file = temporaryFolder.newFile(fileName); 181 FileUtils.writeStringToFile(file, content); 182 String path = file.getAbsolutePath().toString(); 183 waitAndTypeByName("attachmentFile", path); 184 } 185}