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