View Javadoc

1   /**
2    * Copyright 2005-2013 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  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   * @author Kuali Rice Team (rice.collab@kuali.org)
27   */
28  public class LabsSessionPolicyRedirectHomeSTNGGen extends WebDriverLegacyITBase {
29  
30      /**
31       * Ajax Request
32       */
33      public static final String AJAX_REQUEST_BUTTON_TEXT = "Ajax Request";
34  
35      /**
36       * /kr-krad/sessionPolicy?viewId=Lab-SessionPolicy-RedirectHome
37       */
38      public static final String BOOKMARK_URL = "/kr-krad/sessionPolicy?viewId=Lab-SessionPolicy-RedirectHome";
39  
40      /**
41       * Kill Session
42       */
43      public static final String KILL_SESSION_BUTTON_TEXT = "Kill Session";
44  
45      /**
46       * KradSampleAppHome
47       */
48      public static final String KRAD_SAMPLE_APP_HOME_URL_PART = "KradSampleAppHome";
49  
50      /**
51       * Login
52       */
53      public static final String LOGIN_TEXT = "Login";
54  
55      /**
56       * NonAjax Request
57       */
58      public static final String NON_AJAX_REQUEST_BUTTON_TEXT = "NonAjax Request";
59  
60      /**
61       * Session Timeout - Redirect to Home
62       */
63      public static final String SESSION_TIMEOUT_REDIRECT_TO_HOME_HEADER_TEXT = "Session Timeout - Redirect to Home";
64  
65      /**
66       * uif-headerText
67       */
68      public static final String UIF_HEADER_TEXT_CLASS_NAME = "uif-headerText";
69  
70      /**
71       * UserName:
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 }