1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 ServerErrorsIT {
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
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 testServerErrorsIT() throws Exception {
48 selenium.click("//button[contains(.,'Get Error Messages')]");
49 selenium.waitForPageToLoad("30000");
50 Assert.assertTrue(selenium.isVisible("css=div[data-messagesfor=\"Demo-ValidationLayout-SectionsPage\"]"));
51 Assert.assertTrue(selenium.isElementPresent(
52 "css=div[data-messagesfor=\"Demo-ValidationLayout-SectionsPage\"] .uif-errorMessageItem"));
53 Assert.assertTrue(selenium.isVisible("css=div[data-messagesfor=\"Demo-ValidationLayout-Section1\"]"));
54 Assert.assertTrue(selenium.isElementPresent(
55 "css=div[data-messagesfor=\"Demo-ValidationLayout-Section1\"] .uif-errorMessageItem"));
56 Assert.assertTrue(selenium.isElementPresent("css=div[data-role=\"InputField\"] img[alt=\"Error\"]"));
57 selenium.click("//a[contains(.,'\"Section 1 Title\"')]");
58 selenium.mouseOver("//a[contains(.,'Field 1')]");
59 Assert.assertTrue(selenium.isElementPresent("css=.uif-errorHighlight"));
60 selenium.click("//a[contains(.,'Field 1')]");
61 for (int second = 0; ; second++) {
62 if (second >= 60) {
63 Assert.fail("timeout");
64 }
65 try {
66 if (selenium.isVisible("css=.jquerybubblepopup-innerHtml")) {
67 break;
68 }
69 } catch (Exception e) {
70 }
71 Thread.sleep(1000);
72 }
73
74 Assert.assertTrue(selenium.isVisible("css=.jquerybubblepopup-innerHtml > .uif-serverMessageItems"));
75 Assert.assertTrue(selenium.isVisible(
76 "css=.jquerybubblepopup-innerHtml > .uif-serverMessageItems .uif-errorMessageItem-field"));
77 selenium.type("name=field1", "");
78 selenium.fireEvent("name=field1", "blur");
79 selenium.fireEvent("name=field1", "focus");
80 for (int second = 0; ; second++) {
81 if (second >= 60) {
82 Assert.fail("timeout");
83 }
84 try {
85 if (selenium.isVisible("css=.jquerybubblepopup-innerHtml")) {
86 break;
87 }
88 } catch (Exception e) {
89 }
90 Thread.sleep(1000);
91 }
92
93 Assert.assertTrue(selenium.isVisible(
94 "css=.jquerybubblepopup-innerHtml > .uif-serverMessageItems .uif-errorMessageItem-field"));
95 for (int second = 0; ; second++) {
96 if (second >= 60) {
97 Assert.fail("timeout");
98 }
99 try {
100 if (selenium.isVisible("css=.jquerybubblepopup-innerHtml > .uif-clientMessageItems")) {
101 break;
102 }
103 } catch (Exception e) {
104 }
105 Thread.sleep(1000);
106 }
107
108 Assert.assertTrue(selenium.isVisible(
109 "css=.jquerybubblepopup-innerHtml > .uif-clientMessageItems .uif-errorMessageItem-field"));
110 selenium.keyDown("name=field1", "t");
111 selenium.keyPress("name=field1", "t");
112 selenium.keyUp("name=field1", "t");
113 for (int second = 0; ; second++) {
114 if (second >= 60) {
115 Assert.fail("timeout");
116 }
117 try {
118 if (!selenium.isElementPresent("css=.jquerybubblepopup-innerHtml > .uif-clientMessageItems")) {
119 break;
120 }
121 } catch (Exception e) {
122 }
123 Thread.sleep(1000);
124 }
125
126 Assert.assertTrue(selenium.isVisible(
127 "css=.jquerybubblepopup-innerHtml > .uif-serverMessageItems .uif-errorMessageItem-field"));
128 Assert.assertFalse(selenium.isElementPresent("css=.jquerybubblepopup-innerHtml > .uif-clientMessageItems"));
129 }
130
131 @After
132 public void tearDown() throws Exception {
133 selenium.stop();
134 }
135 }