001    /**
002     * Copyright 2005-2011 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     */
016    
017    package edu.sampleu.admin;
018    
019    import org.junit.Ignore;
020    import org.junit.Test;
021    import org.kuali.rice.testtools.selenium.AutomatedFunctionalTestUtils;
022    import org.kuali.rice.testtools.selenium.WebDriverLegacyITBase;
023    import org.kuali.rice.testtools.selenium.WebDriverUtils;
024    import org.openqa.selenium.By;
025    import org.openqa.selenium.WebElement;
026    
027    import java.util.List;
028    
029    import static org.junit.Assert.assertEquals;
030    
031    /**
032     * @author Kuali Rice Team (rice.collab@kuali.org)
033     */
034    public class DocSearchAft extends WebDriverLegacyITBase {
035    
036        public static String BOOKMARK_URL = AutomatedFunctionalTestUtils.PORTAL + "?channelTitle=Document%20Type&channelUrl=" + WebDriverUtils
037                .getBaseUrlString() + "/kr/lookup.do?methodToCall=start&businessObjectClassName=org.kuali.rice.kew.doctype.bo.DocumentType&returnLocation=" + AutomatedFunctionalTestUtils.PORTAL_URL + AutomatedFunctionalTestUtils.HIDE_RETURN_LINK;
038    
039        String docId;
040        String parentName;
041    
042        @Override
043        protected String getBookmarkUrl() {
044            return BOOKMARK_URL;
045        }
046    
047       public void createAndSaveDoc() throws Exception{
048            waitForTitleToEqualKualiPortalIndex();
049            waitAndClickByLinkText("Administration");
050            waitForTitleToEqualKualiPortalIndex();
051            waitAndClickByLinkText("Document Type");
052            waitForTitleToEqualKualiPortalIndex();
053            selectFrame("iframeportlet");
054            waitAndClickByXpath("//img[contains(@alt,'create new')]");
055            waitForElementPresentByXpath("//*[@name='methodToCall.route' and @alt='submit']","save button does not exist on the page");
056            waitForElementPresentByXpath("//div[@id='headerarea']/div/table/tbody/tr[1]/td[1]");
057            docId = driver.findElement(By.xpath("//div[@id='headerarea']/div/table/tbody/tr[1]/td[1]")).getText();
058            waitAndTypeByXpath("//input[@id='document.documentHeader.documentDescription']", "Creating new Document Type");
059            String parentDocType = "//input[@name='methodToCall.performLookup.(!!org.kuali.rice.kew.doctype.bo.DocumentType!!).(((name:document.newMaintainableObject.parentDocType.name,documentTypeId:document.newMaintainableObject.docTypeParentId,))).((`document.newMaintainableObject.parentDocType.name:name,`)).((<>)).(([])).((**)).((^^)).((&&)).((//)).((~~)).(::::;" + getBaseUrlString() + "/kr/lookup.do;::::).anchor4']";
060            waitAndClickByXpath(parentDocType);
061            waitAndClickByXpath("//input[@name='methodToCall.search' and @value='search']");
062            waitForPageToLoad();
063            parentName= driver.findElement(By.xpath("//table[@id='row']/tbody/tr[1]/td[3]")).getText();
064            waitAndClickByLinkText("return value");
065            String docTypeName = "TestDocType " + AutomatedFunctionalTestUtils.DTS;
066            waitForElementPresentByXpath("//input[@id='document.newMaintainableObject.name']");
067            waitAndTypeByXpath("//input[@id='document.newMaintainableObject.name']", docTypeName);
068            waitAndTypeByXpath("//input[@id='document.newMaintainableObject.unresolvedDocHandlerUrl']", "${kr.url}/maintenance.do?methodToCall=docHandler");
069            waitAndTypeByXpath("//input[@id='document.newMaintainableObject.actualNotificationFromAddress']", "NFA");
070            waitAndTypeByXpath("//input[@id='document.newMaintainableObject.label']", "TestDocument Label");
071            waitAndTypeByXpath("//input[@id='document.newMaintainableObject.unresolvedHelpDefinitionUrl']", "default.htm?turl=WordDocuments%2Fdocumenttype.htm");
072            waitAndClickByXpath("//input[@name='methodToCall.save' and @alt='save']");
073            // TODO wait for save confirmation
074            //checkForIncidentReport();
075            selectTopFrame();
076        }
077        @Test
078        public void testBasicDocSearch() throws Exception {
079            createAndSaveDoc();
080            waitAndClickByXpath("//a/img[@alt='doc search']");
081            waitForPageToLoad();
082            selectFrame("iframeportlet");
083            waitForElementPresentByXpath("//div[@class='lookupcreatenew']/input[@alt='detailed search']");
084            waitForElementPresentByXpath("//div[@class='lookupcreatenew']/input[@alt='superuser search']");
085            waitForElementPresentByXpath("//div[@class='lookupcreatenew']/input[@alt='clear saved searches search']");
086            waitAndTypeByName("documentTypeName", parentName);
087            waitAndTypeByName("initiatorPrincipalName", "admin");
088            waitAndTypeByName("documentId", docId);
089            //waitAndTypeByName("rangeLowerBoundKeyPrefix_dateCreated", "10/01/2010");
090            //waitAndTypeByName("dateCreated", "10/13/2010");
091            waitAndClickByXpath("//input[@name='methodToCall.search' and @alt='search']");
092            assertEquals(docId, waitFor(By.xpath("//table[@id='row']/tbody/tr[1]/td[1]/a")).getText());
093            //Thread.sleep(2000);
094            waitAndClickByXpath("//input[@name='methodToCall.clearValues' and @alt='clear']");
095            assertEquals("", driver.findElement(By.xpath("//input[@name='documentTypeName']")).getAttribute("value"));
096            assertEquals("", driver.findElement(By.xpath("//input[@name='initiatorPrincipalName']")).getAttribute("value"));
097            assertEquals("", driver.findElement(By.xpath("//input[@name='documentId']")).getAttribute("value"));
098            assertEquals("", driver.findElement(By.xpath("//input[@name='rangeLowerBoundKeyPrefix_dateCreated']")).getAttribute("value"));
099            assertEquals("", driver.findElement(By.xpath("//input[@name='dateCreated']")).getAttribute("value"));
100            waitAndClickByXpath("//a[@title='cancel']");
101        }
102        
103        @Ignore // TODO fix
104        @Test
105        public void testDetailedDocSearch() throws Exception{
106            //createAndSaveDoc();
107            waitAndClickByXpath("//a/img[@alt='doc search']");
108            waitForPageToLoad();
109            selectFrame("iframeportlet");
110            waitForElementPresentByXpath("//div[@class='lookupcreatenew']/input[@alt='detailed search']");
111            waitForElementPresentByXpath("//div[@class='lookupcreatenew']/input[@alt='superuser search']");
112            waitForElementPresentByXpath("//div[@class='lookupcreatenew']/input[@alt='clear saved searches search']");
113            waitAndClickByXpath("//div[@class='lookupcreatenew']/input[@alt='detailed search']");
114            waitForElementPresentByXpath("//div[@class='lookupcreatenew']/input[@alt='basic search']");
115            //waitAndTypeByName("documentTypeName", parentName);
116            waitAndTypeByName("initiatorPrincipalName", "admin");
117            //waitAndTypeByName("documentId", docId);
118            //waitAndTypeByName("rangeLowerBoundKeyPrefix_dateCreated", "10/01/2010");
119            //waitAndTypeByName("dateCreated", "10/13/2010");
120            assertElementPresentByName("approverPrincipalName", "Approver input field is not there in the detailed search");
121            //waitAndTypeByName("approverPrincipalName", "director");
122            assertElementPresentByName("viewerPrincipalName", "Viewer input field is not there in the detailed search");
123            //waitAndTypeByName("viewerPrincipalName", "superviser");
124            assertElementPresentByXpath("//select[@id='statusCode']", "Document Status select field is not there in the detailed search");
125            selectByXpath("//select[@id='statusCode']", "- SAVED");
126            waitAndClickByXpath("//input[@name='methodToCall.search' and @alt='search']");
127            waitForPageToLoad();
128            assertTrue(driver.findElement(By.id("row")).getText().contains("SAVED"));
129            assertElementPresentByXpath("//table[@id='row']/tbody/tr[1]/td[contains(a,'admin')]");
130            //Thread.sleep(2000);
131            waitAndClickByXpath("//input[@name='methodToCall.clearValues' and @alt='clear']");
132            //assertEquals("", driver.findElement(By.xpath("//input[@name='documentTypeName']")).waitAndGetAttribute("value"));
133            assertEquals("", driver.findElement(By.xpath("//input[@name='initiatorPrincipalName']")).getAttribute("value"));
134            //assertEquals("", driver.findElement(By.xpath("//input[@name='documentId']")).waitAndGetAttribute("value"));
135            //assertEquals("", driver.findElement(By.xpath("//input[@name='rangeLowerBoundKeyPrefix_dateCreated']")).waitAndGetAttribute("value"));
136            //assertEquals("", driver.findElement(By.xpath("//input[@name='dateCreated']")).waitAndGetAttribute("value"));
137            waitAndClickByXpath("//a[@title='cancel']");
138            passed();
139        }
140        
141        @Test
142        public void testSuperUserSearch() throws Exception{
143            //createAndSaveDoc();
144            waitAndClickByXpath("//a/img[@alt='doc search']");
145            waitForPageToLoad();
146            selectFrame("iframeportlet");
147            waitForElementPresentByXpath("//div[@class='lookupcreatenew']/input[@alt='detailed search']");
148            waitForElementPresentByXpath("//div[@class='lookupcreatenew']/input[@alt='superuser search']");
149            waitForElementPresentByXpath("//div[@class='lookupcreatenew']/input[@alt='clear saved searches search']");
150            waitAndClickByXpath("//div[@class='lookupcreatenew']/input[@alt='superuser search']");
151            waitForElementPresentByXpath("//div[@class='lookupcreatenew']/input[@alt='non-superuser search']");
152            waitAndClickByXpath("//input[@name='methodToCall.search' and @alt='search']");
153            waitAndClickByXpath("//table[@id='row']/tbody/tr[1]/td[1]/a");
154            selectTopFrame();
155            Thread.sleep(3000);
156            switchToWindow("Kuali :: Superuser Document Service");
157            waitForPageToLoad();
158            //Thread.sleep(4000);
159    
160            waitAndClickByXpath("//input[@src='images/buttonsmall_complete.gif']");
161            waitForElementPresentByName("methodToCall.approve","approve button does not exist on the page");
162            assertElementPresentByName("methodToCall.disapprove","disapprove button does not exist on the page");
163            assertElementPresentByName("methodToCall.cancel","cancel button does not exist on the page");
164            waitAndClickByName("methodToCall.approve","approve button does not exist on the page");
165            waitAndClickByXpath("//a[@href='DocumentSearch.do']/img[@alt='cancel']");
166            waitAndClickByXpath("//input[@name='methodToCall.search' and @alt='search']");
167            waitForPageToLoad();
168            assertEquals("FINAL", driver.findElement(By.xpath("//table[@id='row']/tbody/tr[1]/td[4]")).getText());
169            passed();
170        }
171        
172        @Test
173        public void testClearSavedSearches() throws Exception{
174            waitAndClickByXpath("//a/img[@alt='doc search']");
175            waitForPageToLoad();
176            selectFrame("iframeportlet");
177            waitForElementPresentByXpath("//div[@class='lookupcreatenew']/input[@alt='detailed search']");
178            waitForElementPresentByXpath("//div[@class='lookupcreatenew']/input[@alt='superuser search']");
179            waitForElementPresentByXpath("//div[@class='lookupcreatenew']/input[@alt='clear saved searches search']");
180            waitAndClickByXpath("//div[@class='lookupcreatenew']/input[@alt='clear saved searches search']");
181            waitForPageToLoad();
182            WebElement select1 = driver.findElement(By.xpath("//select[@id='savedSearchToLoadAndExecute']"));
183            List<WebElement> options = select1.findElements(By.tagName("option"));
184            int count= options.size();
185            assertEquals(5,count);
186            passed();
187        }
188        
189        @Test
190        public void testAjaxPageReload() throws Exception{
191            waitAndClickByXpath("//a/img[@alt='doc search']");
192            waitForPageToLoad();
193            selectFrame("iframeportlet");
194            waitForElementPresentByXpath("//div[@class='lookupcreatenew']/input[@alt='detailed search']");
195            waitForElementPresentByXpath("//div[@class='lookupcreatenew']/input[@alt='superuser search']");
196            waitForElementPresentByXpath("//div[@class='lookupcreatenew']/input[@alt='clear saved searches search']");
197            waitForElementPresentByXpath("//select[@id='savedSearchToLoadAndExecute']");
198            waitAndTypeByName("documentTypeName", "KualiNotification");
199            Thread.sleep(2000);
200            fireEvent("documentTypeName", "blur");
201            waitForElementPresentByName("documentAttribute.notificationContentType");
202            assertElementPresentByName("documentAttribute.notificationChannel");
203            assertElementPresentByName("documentAttribute.notificationProducer");
204            assertElementPresentByName("documentAttribute.notificationPriority");
205            assertElementPresentByName("documentAttribute.notificationRecipients");
206            assertElementPresentByName("documentAttribute.notificationSenders");
207            waitAndClickByXpath("//a[@title='cancel']");
208            passed();
209        }
210    }