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.travel.krad.test; 018 019 import com.thoughtworks.selenium.*; 020 import org.junit.After; 021 import org.junit.Before; 022 import org.junit.Test; 023 import java.util.regex.Pattern; 024 025 import static junit.framework.Assert.assertTrue; 026 import static junit.framework.Assert.fail; 027 /** 028 * test that dirty fields check happens for all pages in a view 029 * 030 * @author Kuali Rice Team (rice.collab@kuali.org) 031 */ 032 public class DirtyFieldsCheckIT { 033 private DefaultSelenium selenium; 034 035 @Before 036 public void setUp() throws Exception { 037 selenium = new DefaultSelenium("localhost", 4444, "*chrome", System.getProperty("remote.public.url")); 038 selenium.start(); 039 } 040 041 @Test 042 public void testDirtyFieldsCheck() throws Exception { 043 selenium.open("/kr-dev/portal.do"); 044 selenium.type("name=__login_user", "admin"); 045 selenium.click("css=input[type=\"submit\"]"); 046 selenium.waitForPageToLoad("30000"); 047 selenium.click("link=KRAD"); 048 selenium.waitForPageToLoad("30000"); 049 selenium.click("link=Uif Components (Kitchen Sink)"); 050 selenium.waitForPageToLoad("30000"); 051 selenium.selectFrame("iframeportlet"); 052 Thread.sleep(3000); 053 selenium.focus("id=u73_control"); 054 selenium.type("id=u73_control", "test 1"); 055 selenium.focus("id=u103_control"); 056 selenium.type("id=u103_control", "test 2"); 057 // 'Other Fields' navigation link 058 selenium.click("id=u967"); 059 assertTrue(selenium.getConfirmation().matches("^Form has unsaved data\\. Do you want to leave anyway[\\s\\S]$")); 060 Thread.sleep(3000); 061 for (int second = 0;; second++) { 062 if (second >= 60) fail("timeout"); 063 try { if (selenium.isElementPresent("id=u51_control")) break; } catch (Exception e) {} 064 Thread.sleep(1000); 065 } 066 selenium.focus("id=u51_control"); 067 selenium.type("id=u51_control", "here"); 068 selenium.focus("id=u81_control"); 069 selenium.type("id=u81_control", "there"); 070 // 'Validation' navigation link 071 selenium.click("id=u970"); 072 assertTrue(selenium.getConfirmation().matches("^Form has unsaved data\\. Do you want to leave anyway[\\s\\S]$")); 073 Thread.sleep(3000); 074 for (int second = 0;; second++) { 075 if (second >= 60) fail("timeout"); 076 try { if (selenium.isElementPresent("id=u114_control")) break; } catch (Exception e) {} 077 Thread.sleep(1000); 078 } 079 selenium.focus("id=u114_control"); 080 selenium.type("id=u114_control", "this"); 081 selenium.focus("id=u144_control"); 082 selenium.type("id=u144_control", "that"); 083 // 'Validation - Regex' navigation link 084 selenium.click("id=u973"); 085 assertTrue(selenium.getConfirmation().matches("^Form has unsaved data\\. Do you want to leave anyway[\\s\\S]$")); 086 Thread.sleep(2000); 087 for (int second = 0;; second++) { 088 if (second >= 60) fail("timeout"); 089 try { if (selenium.isElementPresent("id=u44_control")) break; } catch (Exception e) {} 090 Thread.sleep(1000); 091 } 092 selenium.focus("id=u44_control"); 093 selenium.type("id=u44_control", "1"); 094 selenium.focus("id=u74_control"); 095 selenium.type("id=u74_control", "2"); 096 // 'Progressive Disclosure' navigation link 097 selenium.click("id=u976"); 098 assertTrue(selenium.getConfirmation().matches("^Form has unsaved data\\. Do you want to leave anyway[\\s\\S]$")); 099 } 100 101 @After 102 public void tearDown() throws Exception { 103 selenium.stop(); 104 } 105 }