001    /*
002     * Copyright 2006-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    package edu.samplu.travel.krad.test;
017    
018    import com.thoughtworks.selenium.DefaultSelenium;
019    import com.thoughtworks.selenium.Selenium;
020    import org.junit.After;
021    import org.junit.Before;
022    import org.junit.Test;
023    
024    import static org.junit.Assert.assertEquals;
025    import static org.junit.Assert.assertTrue;
026    
027    /**
028     * tests whether the watermarks is work as expected even when they contain an apostrophe
029     * 
030     * @author Kuali Rice Team (rice.collab@kuali.org)
031     */
032    public class WatermarkValidationIT {
033        private Selenium selenium;
034    
035        @Before
036        public void setUp() throws Exception {
037            selenium = new DefaultSelenium("localhost", 4444, "*firefox", System.getProperty("remote.public.url"));//was http://localhost:8080/
038            selenium.start();
039        }
040    
041        @Test
042        /**
043         * if watermarking is ok, the cancel link will bring up a confirmation if something was typed into a textbox i.e
044         * the scripts will be working ok
045         */
046        public void testWatermarking() throws Exception {
047            selenium.open(System.getProperty("remote.public.url"));
048                    selenium.type("name=__login_user", "quickstart");
049                    selenium.click("css=input[type=\"submit\"]");
050                    selenium.waitForPageToLoad("100000");
051                    selenium.click("link=KRAD");
052                    selenium.waitForPageToLoad("50000");
053                    selenium.click("link=Uif Components (Kitchen Sink)");
054                    selenium.waitForPageToLoad("100000");
055            selenium.selectFrame("iframeportlet");
056            selenium.focus("id=u73_control");
057                    selenium.type("id=u73_control", "something");
058            selenium.focus("id=u103_control");
059            selenium.type("id=u103_control", "something else");
060            assertEquals("something", selenium.getValue("xpath=//*[@id=\"u73_control\"]"));
061                    selenium.chooseCancelOnNextConfirmation();
062            // 'cancel' link
063                    selenium.click("id=u29");
064                    assertTrue(selenium.getConfirmation().matches("^Form has unsaved data\\. Do you want to leave anyway[\\s\\S]$"));
065        }
066    
067        @After
068        public void tearDown() throws Exception {
069            selenium.stop();
070        }
071        
072        public void clearText(String field) throws Exception {
073            selenium.focus(field);
074            selenium.type(field, "");  
075            Thread.sleep(100); 
076        }
077    }