001    /*
002     * Copyright 2006-2012 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.krad.validationmessagesview;
018    
019    import com.thoughtworks.selenium.Selenium;
020    import junit.framework.Assert;
021    import org.openqa.selenium.firefox.FirefoxDriver;
022    import org.openqa.selenium.WebDriver;
023    import org.openqa.selenium.WebDriverBackedSelenium;
024    import org.junit.After;
025    import org.junit.Before;
026    import org.junit.Test;
027    
028    public class ServerErrorsIT {
029        private Selenium selenium;
030    
031        @Before
032        public void setUp() throws Exception {
033            WebDriver driver = new FirefoxDriver();
034            selenium = new WebDriverBackedSelenium(driver,
035                    "http://localhost:8080/kr-dev/kr-krad/uicomponents?viewId=Demo-ValidationLayout&methodToCall=start");
036    
037            // Login
038            selenium.open(
039                    "http://localhost:8080/kr-dev/kr-krad/uicomponents?viewId=Demo-ValidationLayout&methodToCall=start");
040            Assert.assertEquals("Login", selenium.getTitle());
041            selenium.type("__login_user", "admin");
042            selenium.click("//input[@value='Login']");
043            selenium.waitForPageToLoad("30000");
044        }
045    
046        @Test
047        public void testServerErrorsIT() throws Exception {
048            selenium.click("//button[contains(.,'Get Error Messages')]");
049            selenium.waitForPageToLoad("30000");
050            Assert.assertTrue(selenium.isVisible("css=div[data-messagesfor=\"Demo-ValidationLayout-SectionsPage\"]"));
051            Assert.assertTrue(selenium.isElementPresent(
052                    "css=div[data-messagesfor=\"Demo-ValidationLayout-SectionsPage\"] .uif-errorMessageItem"));
053            Assert.assertTrue(selenium.isVisible("css=div[data-messagesfor=\"Demo-ValidationLayout-Section1\"]"));
054            Assert.assertTrue(selenium.isElementPresent(
055                    "css=div[data-messagesfor=\"Demo-ValidationLayout-Section1\"] .uif-errorMessageItem"));
056            Assert.assertTrue(selenium.isElementPresent("css=div[data-role=\"InputField\"] img[alt=\"Error\"]"));
057            selenium.click("//a[contains(.,'\"Section 1 Title\"')]");
058            selenium.mouseOver("//a[contains(.,'Field 1')]");
059            Assert.assertTrue(selenium.isElementPresent("css=.uif-errorHighlight"));
060            selenium.click("//a[contains(.,'Field 1')]");
061            for (int second = 0; ; second++) {
062                if (second >= 60) {
063                    Assert.fail("timeout");
064                }
065                try {
066                    if (selenium.isVisible("css=.jquerybubblepopup-innerHtml")) {
067                        break;
068                    }
069                } catch (Exception e) {
070                }
071                Thread.sleep(1000);
072            }
073    
074            Assert.assertTrue(selenium.isVisible("css=.jquerybubblepopup-innerHtml > .uif-serverMessageItems"));
075            Assert.assertTrue(selenium.isVisible(
076                    "css=.jquerybubblepopup-innerHtml > .uif-serverMessageItems .uif-errorMessageItem-field"));
077            selenium.type("name=field1", "");
078            selenium.fireEvent("name=field1", "blur");
079            selenium.fireEvent("name=field1", "focus");
080            for (int second = 0; ; second++) {
081                if (second >= 60) {
082                    Assert.fail("timeout");
083                }
084                try {
085                    if (selenium.isVisible("css=.jquerybubblepopup-innerHtml")) {
086                        break;
087                    }
088                } catch (Exception e) {
089                }
090                Thread.sleep(1000);
091            }
092    
093            Assert.assertTrue(selenium.isVisible(
094                    "css=.jquerybubblepopup-innerHtml > .uif-serverMessageItems .uif-errorMessageItem-field"));
095            for (int second = 0; ; second++) {
096                if (second >= 60) {
097                    Assert.fail("timeout");
098                }
099                try {
100                    if (selenium.isVisible("css=.jquerybubblepopup-innerHtml > .uif-clientMessageItems")) {
101                        break;
102                    }
103                } catch (Exception e) {
104                }
105                Thread.sleep(1000);
106            }
107    
108            Assert.assertTrue(selenium.isVisible(
109                    "css=.jquerybubblepopup-innerHtml > .uif-clientMessageItems  .uif-errorMessageItem-field"));
110            selenium.keyDown("name=field1", "t");
111            selenium.keyPress("name=field1", "t");
112            selenium.keyUp("name=field1", "t");
113            for (int second = 0; ; second++) {
114                if (second >= 60) {
115                    Assert.fail("timeout");
116                }
117                try {
118                    if (!selenium.isElementPresent("css=.jquerybubblepopup-innerHtml > .uif-clientMessageItems")) {
119                        break;
120                    }
121                } catch (Exception e) {
122                }
123                Thread.sleep(1000);
124            }
125    
126            Assert.assertTrue(selenium.isVisible(
127                    "css=.jquerybubblepopup-innerHtml > .uif-serverMessageItems .uif-errorMessageItem-field"));
128            Assert.assertFalse(selenium.isElementPresent("css=.jquerybubblepopup-innerHtml > .uif-clientMessageItems"));
129        }
130    
131        @After
132        public void tearDown() throws Exception {
133            selenium.stop();
134        }
135    }