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.krad.validationmessagesview;
18  
19  import com.thoughtworks.selenium.Selenium;
20  import com.thoughtworks.selenium.SeleneseTestCase;
21  import junit.framework.Assert;
22  import org.openqa.selenium.firefox.FirefoxDriver;
23  import org.openqa.selenium.WebDriver;
24  import org.openqa.selenium.WebDriverBackedSelenium;
25  import org.junit.After;
26  import org.junit.Before;
27  import org.junit.Test;
28  import java.util.regex.Pattern;
29  
30  public class ServerWarningsIT{
31      private Selenium selenium;
32  
33      @Before
34      public void setUp() throws Exception {
35          WebDriver driver = new FirefoxDriver();
36          selenium = new WebDriverBackedSelenium(driver,
37                  "http://localhost:8080/kr-dev/kr-krad/uicomponents?viewId=Demo-ValidationLayout&methodToCall=start");
38  
39          // Login
40          selenium.open(
41                  "http://localhost:8080/kr-dev/kr-krad/uicomponents?viewId=Demo-ValidationLayout&methodToCall=start");
42          Assert.assertEquals("Login", selenium.getTitle());
43          selenium.type("__login_user", "admin");
44          selenium.click("//input[@value='Login']");
45          selenium.waitForPageToLoad("30000");
46      }
47  
48  	@Test
49  	public void testServerWarningsIT() throws Exception {
50  		selenium.click("//button[contains(.,'Get Warning Messages')]");
51  		selenium.waitForPageToLoad("30000");
52  		Assert.assertTrue(selenium.isVisible("css=div[data-messagesfor=\"Demo-ValidationLayout-SectionsPage\"]"));
53  		Assert.assertTrue(selenium.isElementPresent("css=div[data-messagesfor=\"Demo-ValidationLayout-SectionsPage\"] .uif-warningMessageItem"));
54  		Assert.assertTrue(selenium.isVisible("css=div[data-messagesfor=\"Demo-ValidationLayout-Section1\"]"));
55  		Assert.assertTrue(selenium.isElementPresent("css=div[data-messagesfor=\"Demo-ValidationLayout-Section1\"] .uif-warningMessageItem"));
56  		Assert.assertTrue(selenium.isElementPresent("css=div[data-role=\"InputField\"] img[alt=\"Warning\"]"));
57  		selenium.mouseOver("//a[contains(.,'Field 1')]");
58  		Assert.assertTrue(selenium.isElementPresent("css=.uif-warningHighlight"));
59  		selenium.click("//a[contains(.,'Field 1')]");
60  		for (int second = 0;; second++) {
61  			if (second >= 60) Assert.fail("timeout");
62  			try { if (selenium.isVisible("css=.jquerybubblepopup-innerHtml")) break; } catch (Exception e) {}
63  			Thread.sleep(1000);
64  		}
65  
66  		Assert.assertTrue(selenium.isVisible("css=.jquerybubblepopup-innerHtml > .uif-serverMessageItems"));
67  		Assert.assertTrue(selenium.isVisible("css=.jquerybubblepopup-innerHtml > .uif-serverMessageItems .uif-warningMessageItem-field"));
68  		selenium.type("name=field1", "");
69  		selenium.fireEvent("name=field1", "blur");
70  		selenium.fireEvent("name=field1", "focus");
71  		for (int second = 0;; second++) {
72  			if (second >= 60) Assert.fail("timeout");
73  			try { if (selenium.isVisible("css=.jquerybubblepopup-innerHtml")) break; } catch (Exception e) {}
74  			Thread.sleep(1000);
75  		}
76  
77  		Assert.assertTrue(selenium.isVisible("css=.jquerybubblepopup-innerHtml > .uif-serverMessageItems .uif-warningMessageItem-field"));
78  		for (int second = 0;; second++) {
79  			if (second >= 60) Assert.fail("timeout");
80  			try { if (selenium.isVisible("css=.jquerybubblepopup-innerHtml > .uif-clientMessageItems")) break; } catch (Exception e) {}
81  			Thread.sleep(1000);
82  		}
83  
84  		Assert.assertTrue(selenium.isVisible("css=.jquerybubblepopup-innerHtml > .uif-clientMessageItems  .uif-errorMessageItem-field"));
85  		selenium.type("name=field1", "b");
86  		selenium.keyDown("name=field1", "b");
87  		selenium.keyUp("name=field1", "b");
88          selenium.typeKeys("name=field1", "\b\b\b");
89  		for (int second = 0;; second++) {
90  			if (second >= 60) Assert.fail("timeout");
91  			try { if (!selenium.isElementPresent("css=.jquerybubblepopup-innerHtml > .uif-clientMessageItems")) break; } catch (Exception e) {}
92  			Thread.sleep(1000);
93  		}
94  
95  		Assert.assertTrue(selenium.isVisible("css=.jquerybubblepopup-innerHtml > .uif-serverMessageItems .uif-warningMessageItem-field"));
96  		Assert.assertFalse(selenium.isElementPresent("css=.jquerybubblepopup-innerHtml > .uif-clientMessageItems"));
97  		selenium.type("name=field1", "");
98  		selenium.fireEvent("name=field1", "focus");
99  		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 }