View Javadoc

1   /*
2    * Copyright 2006-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package edu.samplu.travel.krad.test;
18  
19  import com.thoughtworks.selenium.*;
20  import org.junit.After;
21  import org.junit.Before;
22  import org.junit.Test;
23  import java.util.regex.Pattern;
24  
25  import static junit.framework.Assert.assertTrue;
26  import static junit.framework.Assert.fail;
27  /**
28   * test that dirty fields check happens for all pages in a view
29   *
30   * @author Kuali Rice Team (rice.collab@kuali.org)
31   */
32  public class DirtyFieldsCheckIT {
33      private DefaultSelenium selenium;
34  
35      @Before
36  	public void setUp() throws Exception {
37  		selenium = new DefaultSelenium("localhost", 4444, "*chrome", System.getProperty("remote.public.url"));
38  		selenium.start();
39  	}
40  
41  	@Test
42  	public void testDirtyFieldsCheck() throws Exception {
43  		selenium.open("/kr-dev/portal.do");
44  		selenium.type("name=__login_user", "admin");
45  		selenium.click("css=input[type=\"submit\"]");
46  		selenium.waitForPageToLoad("30000");
47  		selenium.click("link=KRAD");
48  		selenium.waitForPageToLoad("30000");
49  		selenium.click("link=Uif Components (Kitchen Sink)");
50  		selenium.waitForPageToLoad("30000");
51  		selenium.selectFrame("iframeportlet");
52          Thread.sleep(3000);
53  		selenium.focus("id=u73_control");
54  		selenium.type("id=u73_control", "test 1");
55  		selenium.focus("id=u103_control");
56  		selenium.type("id=u103_control", "test 2");
57  		// 'Other Fields' navigation link
58  		selenium.click("id=u967");
59          assertTrue(selenium.getConfirmation().matches("^Form has unsaved data\\. Do you want to leave anyway[\\s\\S]$"));
60          Thread.sleep(3000);
61          for (int second = 0;; second++) {
62              if (second >= 60) fail("timeout");
63              try { if (selenium.isElementPresent("id=u51_control")) break; } catch (Exception e) {}
64              Thread.sleep(1000);
65          }
66          selenium.focus("id=u51_control");
67  		selenium.type("id=u51_control", "here");
68          selenium.focus("id=u81_control");
69  		selenium.type("id=u81_control", "there");
70  		// 'Validation' navigation link
71  		selenium.click("id=u970");
72          assertTrue(selenium.getConfirmation().matches("^Form has unsaved data\\. Do you want to leave anyway[\\s\\S]$"));
73          Thread.sleep(3000);
74          for (int second = 0;; second++) {
75              if (second >= 60) fail("timeout");
76              try { if (selenium.isElementPresent("id=u114_control")) break; } catch (Exception e) {}
77              Thread.sleep(1000);
78          }
79          selenium.focus("id=u114_control");
80  		selenium.type("id=u114_control", "this");
81          selenium.focus("id=u144_control");
82  		selenium.type("id=u144_control", "that");
83  		// 'Validation - Regex' navigation link
84  		selenium.click("id=u973");
85          assertTrue(selenium.getConfirmation().matches("^Form has unsaved data\\. Do you want to leave anyway[\\s\\S]$"));
86          Thread.sleep(2000);
87          for (int second = 0;; second++) {
88              if (second >= 60) fail("timeout");
89              try { if (selenium.isElementPresent("id=u44_control")) break; } catch (Exception e) {}
90              Thread.sleep(1000);
91          }
92          selenium.focus("id=u44_control");
93  		selenium.type("id=u44_control", "1");
94          selenium.focus("id=u74_control");
95  		selenium.type("id=u74_control", "2");
96          // 'Progressive Disclosure' navigation link
97  		selenium.click("id=u976");
98  		assertTrue(selenium.getConfirmation().matches("^Form has unsaved data\\. Do you want to leave anyway[\\s\\S]$"));
99  	}
100 
101 	@After
102 	public void tearDown() throws Exception {
103 		selenium.stop();
104 	}
105 }