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