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 ServerInfoIT{
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 testServerInfoIT() throws Exception {
048 selenium.click("//button[contains(.,'Get Info Messages')]");
049 selenium.waitForPageToLoad("30000");
050 Assert.assertTrue(selenium.isVisible("css=div[data-messagesfor=\"Demo-ValidationLayout-SectionsPage\"]"));
051 Assert.assertTrue(selenium.isElementPresent("css=div[data-messagesfor=\"Demo-ValidationLayout-SectionsPage\"] .uif-infoMessageItem"));
052 Assert.assertTrue(selenium.isVisible("css=div[data-messagesfor=\"Demo-ValidationLayout-Section1\"]"));
053 Assert.assertTrue(selenium.isElementPresent("css=div[data-messagesfor=\"Demo-ValidationLayout-Section1\"] .uif-infoMessageItem"));
054 Assert.assertTrue(selenium.isElementPresent("css=div[data-role=\"InputField\"] img[alt=\"Information\"]"));
055 selenium.mouseOver("//a[contains(.,'Field 1')]");
056 Assert.assertTrue(selenium.isElementPresent("css=.uif-infoHighlight"));
057 selenium.click("//a[contains(.,'Field 1')]");
058 for (int second = 0;; second++) {
059 if (second >= 60) Assert.fail("timeout");
060 try { if (selenium.isVisible("css=.jquerybubblepopup-innerHtml")) break; } catch (Exception e) {}
061 Thread.sleep(1000);
062 }
063
064 Assert.assertTrue(selenium.isVisible("css=.jquerybubblepopup-innerHtml > .uif-serverMessageItems"));
065 Assert.assertTrue(selenium.isVisible("css=.jquerybubblepopup-innerHtml > .uif-serverMessageItems .uif-infoMessageItem-field"));
066 selenium.type("name=field1", "");
067 selenium.fireEvent("name=field1", "blur");
068 selenium.fireEvent("name=field1", "focus");
069 for (int second = 0;; second++) {
070 if (second >= 60) Assert.fail("timeout");
071 try { if (selenium.isVisible("css=.jquerybubblepopup-innerHtml")) break; } catch (Exception e) {}
072 Thread.sleep(1000);
073 }
074
075 Assert.assertTrue(selenium.isVisible("css=.jquerybubblepopup-innerHtml > .uif-serverMessageItems .uif-infoMessageItem-field"));
076 for (int second = 0;; second++) {
077 if (second >= 60) Assert.fail("timeout");
078 try { if (selenium.isVisible("css=.jquerybubblepopup-innerHtml > .uif-clientMessageItems")) break; } catch (Exception e) {}
079 Thread.sleep(1000);
080 }
081
082 Assert.assertTrue(selenium.isVisible("css=.jquerybubblepopup-innerHtml > .uif-clientMessageItems .uif-errorMessageItem-field"));
083 selenium.type("name=field1", "b");
084 selenium.keyDown("name=field1", "b");
085 selenium.keyUp("name=field1", "b");
086 selenium.typeKeys("name=field1", "\b\b\b");
087 for (int second = 0;; second++) {
088 if (second >= 60) Assert.fail("timeout");
089 try { if (!selenium.isElementPresent("css=.jquerybubblepopup-innerHtml > .uif-clientMessageItems")) break; } catch (Exception e) {}
090 Thread.sleep(1000);
091 }
092
093 Assert.assertTrue(selenium.isVisible("css=.jquerybubblepopup-innerHtml > .uif-serverMessageItems .uif-infoMessageItem-field"));
094 Assert.assertFalse(selenium.isElementPresent("css=.jquerybubblepopup-innerHtml > .uif-clientMessageItems"));
095 selenium.type("name=field1", "");
096 selenium.fireEvent("name=field1", "focus");
097 selenium.fireEvent("name=field1", "blur");
098 Assert.assertTrue(selenium.isElementPresent("css=.uif-hasError"));
099 Assert.assertTrue(selenium.isElementPresent("css=img[src*=\"error.png\"]"));
100 }
101
102 @After
103 public void tearDown() throws Exception {
104 selenium.stop();
105 }
106 }