1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package edu.samplu.krad.labs.sessionPolicy;
17
18 import edu.samplu.common.ITUtil;
19 import edu.samplu.common.WebDriverLegacyITBase;
20 import edu.samplu.common.WebDriverUtil;
21 import org.junit.Assert;
22 import org.testng.annotations.Parameters;
23 import org.testng.annotations.Test;
24
25
26
27
28 public class LabsSessionPolicyRedirectHomeSTNGGen extends WebDriverLegacyITBase {
29
30
31
32
33 public static final String AJAX_REQUEST_BUTTON_TEXT = "Ajax Request";
34
35
36
37
38 public static final String BOOKMARK_URL = "/kr-krad/sessionPolicy?viewId=Lab-SessionPolicy-RedirectHome";
39
40
41
42
43 public static final String KILL_SESSION_BUTTON_TEXT = "Kill Session";
44
45
46
47
48 public static final String KRAD_SAMPLE_APP_HOME_URL_PART = "KradSampleAppHome";
49
50
51
52
53 public static final String LOGIN_TEXT = "Login";
54
55
56
57
58 public static final String NON_AJAX_REQUEST_BUTTON_TEXT = "NonAjax Request";
59
60
61
62
63 public static final String SESSION_TIMEOUT_REDIRECT_TO_HOME_HEADER_TEXT = "Session Timeout - Redirect to Home";
64
65
66
67
68 public static final String UIF_HEADER_TEXT_CLASS_NAME = "uif-headerText";
69
70
71
72
73 public static final String USER_NAME_TEXT = "UserName:";
74
75 @Override
76 public void fail(String message) {
77 Assert.fail(message);
78 }
79
80 @Override
81 public String getTestUrl() {
82 return BOOKMARK_URL;
83 }
84
85 @Test(groups = { "all", "fast", "default", "bookmark" }, description = "testNonAjaxAjaxBookmark")
86 @Parameters( { "seleniumHost", "seleniumPort", "os", "browser", "version", "webSite" })
87 public void testNonAjaxAjaxBookmark() throws Exception {
88 assertHeaderTextRedirectHome();
89
90 waitAndClickButtonByText(AJAX_REQUEST_BUTTON_TEXT);
91 assertHeaderTextRedirectHome();
92
93 waitAndClickButtonByText(NON_AJAX_REQUEST_BUTTON_TEXT);
94 assertHeaderTextRedirectHome();
95
96 waitAndClickButtonByText(KILL_SESSION_BUTTON_TEXT);
97 waitAndClickButtonByText(NON_AJAX_REQUEST_BUTTON_TEXT);
98 assertHomeRedirect();
99
100 driver.navigate().to(ITUtil.getBaseUrlString() + BOOKMARK_URL);
101 assertHeaderTextRedirectHome();
102
103 waitAndClickButtonByText(KILL_SESSION_BUTTON_TEXT);
104 waitAndClickButtonByText(AJAX_REQUEST_BUTTON_TEXT);
105 assertHomeRedirect();
106
107 passed();
108 }
109
110 @Test(groups = { "all", "fast", "default", "bookmark" }, description = "testAjaxNonAjaxBookmark")
111 @Parameters( { "seleniumHost", "seleniumPort", "os", "browser", "version", "webSite" })
112 public void testAjaxNonAjaxBookmark() throws Exception {
113 assertHeaderTextRedirectHome();
114
115 waitAndClickButtonByText(NON_AJAX_REQUEST_BUTTON_TEXT);
116 assertHeaderTextRedirectHome();
117
118 waitAndClickButtonByText(AJAX_REQUEST_BUTTON_TEXT);
119 assertHeaderTextRedirectHome();
120
121 waitAndClickButtonByText(KILL_SESSION_BUTTON_TEXT);
122 waitAndClickButtonByText(AJAX_REQUEST_BUTTON_TEXT);
123 assertHomeRedirect();
124
125 driver.navigate().to(ITUtil.getBaseUrlString() + BOOKMARK_URL);
126 assertHeaderTextRedirectHome();
127
128 waitAndClickButtonByText(KILL_SESSION_BUTTON_TEXT);
129 waitAndClickButtonByText(NON_AJAX_REQUEST_BUTTON_TEXT);
130 assertHomeRedirect();
131
132 passed();
133 }
134
135 protected void assertHomeRedirect() throws InterruptedException {
136 waitForElementPresentByClassName(UIF_HEADER_TEXT_CLASS_NAME);
137 assertTextPresent(LOGIN_TEXT);
138 assertTextPresent(USER_NAME_TEXT);
139 WebDriverUtil.kradLogin(driver, user, this);
140 driver.getCurrentUrl().contains(KRAD_SAMPLE_APP_HOME_URL_PART);
141 }
142
143 protected void assertHeaderTextRedirectHome() throws InterruptedException {
144 waitForElementPresentByClassName(UIF_HEADER_TEXT_CLASS_NAME);
145 assertTextPresent(SESSION_TIMEOUT_REDIRECT_TO_HOME_HEADER_TEXT);
146 }
147 }