001/** 002 * Copyright 2005-2013 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.samplu.mainmenu.test; 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.openqa.selenium.By; 025 026import java.io.File; 027 028/** 029 * Tests the Notes and Attachments in the People Flow screen. 030 * 031 * @author Kuali Rice Team (rice.collab@kuali.org) 032 */ 033public class PeopleFlowCreateNewNotesAndAttachmentsSmokeTest extends PeopleFlowCreateNewSTJUnitBase { 034 035 /** 036 * Provider of the temporary folder. 037 */ 038 @Rule 039 public TemporaryFolder temporaryFolder = new TemporaryFolder(); 040 041 private static final String NOTES_AND_ATTACHMENTS_PREFIX = UifPropertyPaths.NEW_COLLECTION_LINES 042 + "['" 043 + KRADConstants.DOCUMENT_PROPERTY_NAME 044 + "." 045 + KRADConstants.NOTES_PROPERTY_NAME 046 + "']"; 047 048 @Override 049 public String getBookmarkUrl() { 050 return BOOKMARK_URL; 051 } 052 053 @Override 054 public String getTestUrl() { 055 return BOOKMARK_URL; 056 } 057 058 /** 059 * Tests adding both the required note and an optional attachment. 060 * 061 * @throws Exception when an error is encountered in the test 062 */ 063 @Test 064 public void testPeopleFlowCreateNewNotesAndAttachments_DefaultAttachment() throws Exception { 065 navigateToPeopleFlowNotesAndAttachments(); 066 067 waitAndTypeByName(NOTES_AND_ATTACHMENTS_PREFIX + "." + KRADConstants.NOTE_TEXT_PROPERTY_NAME, 068 "Attachment_Note"); 069 waitAndAddAttachment("attachment.txt", "Testing123"); 070 waitAndClick(By.cssSelector("button[title='Add a Note']")); 071 072 Thread.sleep(2000); 073 074 assertTextPresent("Attachment_Note"); 075 assertTextPresent("attachment.txt"); 076 assertTextNotPresent("Note Text is a required field."); 077 } 078 079 /** 080 * Tests adding just the required note. 081 * 082 * @throws Exception when an error is encountered in the test 083 */ 084 @Test 085 public void testPeopleFlowCreateNewNotesAndAttachments_DefaultNoAttachment() throws Exception { 086 navigateToPeopleFlowNotesAndAttachments(); 087 088 waitAndTypeByName(NOTES_AND_ATTACHMENTS_PREFIX + "." + KRADConstants.NOTE_TEXT_PROPERTY_NAME, 089 "Attachment_Note"); 090 waitAndClick(By.cssSelector("button[title='Add a Note']")); 091 092 Thread.sleep(2000); 093 094 assertTextPresent("Attachment_Note"); 095 assertTextNotPresent("Note Text is a required field."); 096 } 097 098 /** 099 * Tests adding just the optional attachment, which should result in an error. 100 * 101 * @throws Exception when an error is encountered in the test 102 */ 103 @Test 104 public void testPeopleFlowCreateNewNotesAndAttachments_NoNoteText() throws Exception { 105 navigateToPeopleFlowNotesAndAttachments(); 106 107 waitAndAddAttachment("attachment.txt", "Testing123"); 108 waitAndClick(By.cssSelector("button[title='Add a Note']")); 109 110 Thread.sleep(2000); 111 112 assertTextPresent("Note Text is a required field."); 113 assertTextNotPresent("attachment.txt"); 114 } 115 116 private void navigateToPeopleFlowNotesAndAttachments() throws Exception { 117 selectFrameIframePortlet(); 118 119 waitAndClickByLinkText("Create New"); 120 waitForElementPresent( 121 "div[data-header_for='PeopleFlow-MaintenanceView'] div[data-label='Document Number'] > span"); 122 123 waitAndClickByLinkText("Notes and Attachments (0)"); 124 } 125 126 private void waitAndAddAttachment(String fileName, String content) throws Exception { 127 File file = temporaryFolder.newFile(fileName); 128 FileUtils.writeStringToFile(file, content); 129 String path = file.getAbsolutePath().toString(); 130 driver.findElement(By.name("attachmentFile")).sendKeys(path); 131 } 132}