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 com.thoughtworks.selenium.SeleneseTestCase; 021 import junit.framework.Assert; 022 import org.openqa.selenium.firefox.FirefoxDriver; 023 import org.openqa.selenium.WebDriver; 024 import org.openqa.selenium.WebDriverBackedSelenium; 025 import org.junit.After; 026 import org.junit.Before; 027 import org.junit.Test; 028 import java.util.regex.Pattern; 029 030 public class ServerWarningsIT{ 031 private Selenium selenium; 032 033 @Before 034 public void setUp() throws Exception { 035 WebDriver driver = new FirefoxDriver(); 036 selenium = new WebDriverBackedSelenium(driver, 037 "http://localhost:8080/kr-dev/kr-krad/uicomponents?viewId=Demo-ValidationLayout&methodToCall=start"); 038 039 // Login 040 selenium.open( 041 "http://localhost:8080/kr-dev/kr-krad/uicomponents?viewId=Demo-ValidationLayout&methodToCall=start"); 042 Assert.assertEquals("Login", selenium.getTitle()); 043 selenium.type("__login_user", "admin"); 044 selenium.click("//input[@value='Login']"); 045 selenium.waitForPageToLoad("30000"); 046 } 047 048 @Test 049 public void testServerWarningsIT() throws Exception { 050 selenium.click("//button[contains(.,'Get Warning Messages')]"); 051 selenium.waitForPageToLoad("30000"); 052 Assert.assertTrue(selenium.isVisible("css=div[data-messagesfor=\"Demo-ValidationLayout-SectionsPage\"]")); 053 Assert.assertTrue(selenium.isElementPresent("css=div[data-messagesfor=\"Demo-ValidationLayout-SectionsPage\"] .uif-warningMessageItem")); 054 Assert.assertTrue(selenium.isVisible("css=div[data-messagesfor=\"Demo-ValidationLayout-Section1\"]")); 055 Assert.assertTrue(selenium.isElementPresent("css=div[data-messagesfor=\"Demo-ValidationLayout-Section1\"] .uif-warningMessageItem")); 056 Assert.assertTrue(selenium.isElementPresent("css=div[data-role=\"InputField\"] img[alt=\"Warning\"]")); 057 selenium.mouseOver("//a[contains(.,'Field 1')]"); 058 Assert.assertTrue(selenium.isElementPresent("css=.uif-warningHighlight")); 059 selenium.click("//a[contains(.,'Field 1')]"); 060 for (int second = 0;; second++) { 061 if (second >= 60) Assert.fail("timeout"); 062 try { if (selenium.isVisible("css=.jquerybubblepopup-innerHtml")) break; } catch (Exception e) {} 063 Thread.sleep(1000); 064 } 065 066 Assert.assertTrue(selenium.isVisible("css=.jquerybubblepopup-innerHtml > .uif-serverMessageItems")); 067 Assert.assertTrue(selenium.isVisible("css=.jquerybubblepopup-innerHtml > .uif-serverMessageItems .uif-warningMessageItem-field")); 068 selenium.type("name=field1", ""); 069 selenium.fireEvent("name=field1", "blur"); 070 selenium.fireEvent("name=field1", "focus"); 071 for (int second = 0;; second++) { 072 if (second >= 60) Assert.fail("timeout"); 073 try { if (selenium.isVisible("css=.jquerybubblepopup-innerHtml")) break; } catch (Exception e) {} 074 Thread.sleep(1000); 075 } 076 077 Assert.assertTrue(selenium.isVisible("css=.jquerybubblepopup-innerHtml > .uif-serverMessageItems .uif-warningMessageItem-field")); 078 for (int second = 0;; second++) { 079 if (second >= 60) Assert.fail("timeout"); 080 try { if (selenium.isVisible("css=.jquerybubblepopup-innerHtml > .uif-clientMessageItems")) break; } catch (Exception e) {} 081 Thread.sleep(1000); 082 } 083 084 Assert.assertTrue(selenium.isVisible("css=.jquerybubblepopup-innerHtml > .uif-clientMessageItems .uif-errorMessageItem-field")); 085 selenium.type("name=field1", "b"); 086 selenium.keyDown("name=field1", "b"); 087 selenium.keyUp("name=field1", "b"); 088 selenium.typeKeys("name=field1", "\b\b\b"); 089 for (int second = 0;; second++) { 090 if (second >= 60) Assert.fail("timeout"); 091 try { if (!selenium.isElementPresent("css=.jquerybubblepopup-innerHtml > .uif-clientMessageItems")) break; } catch (Exception e) {} 092 Thread.sleep(1000); 093 } 094 095 Assert.assertTrue(selenium.isVisible("css=.jquerybubblepopup-innerHtml > .uif-serverMessageItems .uif-warningMessageItem-field")); 096 Assert.assertFalse(selenium.isElementPresent("css=.jquerybubblepopup-innerHtml > .uif-clientMessageItems")); 097 selenium.type("name=field1", ""); 098 selenium.fireEvent("name=field1", "focus"); 099 selenium.fireEvent("name=field1", "blur"); 100 Assert.assertTrue(selenium.isElementPresent("css=.uif-hasError")); 101 Assert.assertTrue(selenium.isElementPresent("css=img[src*=\"error.png\"]")); 102 } 103 104 @After 105 public void tearDown() throws Exception { 106 selenium.stop(); 107 } 108 }