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