View Javadoc
1   /**
2    * Copyright 2005-2015 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 org.kuali.rice.krad.demo.uif.library.clientresponsiveness;
17  
18  import org.junit.Ignore;
19  import org.junit.Test;
20  
21  import org.kuali.rice.testtools.selenium.WebDriverLegacyITBase;
22  import org.kuali.rice.testtools.selenium.WebDriverUtils;
23  import org.openqa.selenium.By;
24  import org.openqa.selenium.Keys;
25  import org.openqa.selenium.WebElement;
26  
27  /**
28   * @author Kuali Rice Team (rice.collab@kuali.org)
29   */
30  public class LibraryClientResponsivenessAjaxFieldQueryAft extends WebDriverLegacyITBase {
31  
32      /**
33       * /kr-krad/kradsampleapp?viewId=Demo-AjaxFieldQueryView
34       */
35      public static final String BOOKMARK_URL = "/kr-krad/kradsampleapp?viewId=Demo-AjaxFieldQueryView";
36  
37      @Override
38      protected String getBookmarkUrl() {
39          return BOOKMARK_URL;
40      }
41  
42      @Override
43      protected void navigate() throws Exception {
44          waitAndClickLibraryLink();
45          waitAndClickByLinkText("Client Responsiveness");
46          waitAndClickByLinkText("AJAX Field Query");
47      }
48  
49      protected void testClientResponsivenessAjaxFieldQuery() throws Exception {
50          waitAndClickByLinkText("Ajax Field Query");
51          waitForElementPresentByXpath("//input[@name='inputField3' and @value='a1']");
52          clearTypeAndFocus("inputField3", "a1");
53          checkIfFocusSuccessful("inputField3", "a1", "Travel Account 1");
54          assertTextPresent(new String[] {"Travel Account 1", "fred"});
55      }
56      
57      protected void testClientResponsivenessAjaxFieldQueryCustomMethod() throws Exception {
58          waitAndClickByLinkText("Ajax Field Query Custom Method");
59          waitForElementPresentByXpath("//input[@name='inputField6' and @value='a2']");
60          clearTypeAndFocus("inputField6", "a2");
61          checkIfFocusSuccessful("inputField6", "a2", "Travel Account 2");
62          assertTextPresent(new String[] {"Travel Account 2", "fran"});
63      }
64      
65      protected void testClientResponsivenessAjaxFieldQueryCustomMethodAndService() throws Exception {
66          waitAndClickByLinkText("Ajax Field Query Custom Method and Service");
67      	waitForElementPresentByXpath("//input[@name='inputField9' and @value='a3']");
68          clearTypeAndFocus("inputField9", "a3");
69          checkIfFocusSuccessful("inputField9", "a3", "Travel Account 3");
70          assertTextPresent(new String[] {"Travel Account 3", "frank"});
71      }
72  
73      /**
74       * focus, blur seem real flaky on xvfb, maybe clear, enter value, and tab will be better
75       *
76       * @param fieldName name of the field that needs to be focused on.
77       * @param fieldValue value to be placed in field
78       *
79       * @throws InterruptedException
80       */
81      private void clearTypeAndFocus(String fieldName, String fieldValue) throws InterruptedException {
82          clearTextByName(fieldName);
83          WebElement element = WebDriverUtils.waitFor(driver, WebDriverUtils.configuredImplicityWait(), By.name(
84                  fieldName), this.getClass().toString());
85          element.sendKeys("", fieldValue);
86          fireEvent(fieldName, "focus");
87          fireEvent(fieldName, "blur");
88          assertTextPresent(fieldValue);
89      }
90  
91      /**
92       * If the expected message did not appear it means that the field did not gain focus so there was no tab off of the
93       * field.  This will attempt to regain focus of the page and try again.
94       *
95       * @param fieldName name of the field that needs to be focused on.
96       * @param fieldValue value to be placed in field
97       * @param expectedMessage message that should be present on the screen after tabbing out of the field
98       *
99       * @throws InterruptedException
100      */
101     private void checkIfFocusSuccessful(String fieldName, String fieldValue, String expectedMessage)
102             throws InterruptedException {
103         for (int i = 0; i < 5; i++) {
104             Thread.sleep(3000);
105             if (isTextPresent(expectedMessage)) {
106                 break;
107             } else {
108                 jGrowl("Focus failed - Focusing back on the test window before trying to enter text again.");
109                 driver.switchTo().window(driver.getWindowHandle());
110                 clearTypeAndFocus(fieldName, fieldValue);
111             }
112         }
113     }
114 
115     @Test
116     public void testClientResponsivenessAjaxFieldQueryBookmark() throws Exception {
117         testClientResponsivenessAjaxFieldQuery();
118         testClientResponsivenessAjaxFieldQueryCustomMethod();
119         passed();
120     }
121 
122     @Test
123     public void testClientResponsivenessAjaxFieldQueryNav() throws Exception {
124         testClientResponsivenessAjaxFieldQuery();
125         testClientResponsivenessAjaxFieldQueryCustomMethod();
126         passed();
127     }
128 
129     @Test
130     @Ignore //Ignore this test due to the issues found in KULRICE-13108.  They will fail until a solution can be found.
131     public void testClientResponsivenessAjaxFieldQueryCustomMethodAndServiceBookmark() throws Exception {
132         testClientResponsivenessAjaxFieldQueryCustomMethodAndService();
133         passed();
134     }
135 
136     @Test
137     @Ignore //Ignore this test due to the issues found in KULRICE-13108.  They will fail until a solution can be found.
138     public void testClientResponsivenessAjaxFieldQueryCustomMethodAndServiceNav() throws Exception {
139         testClientResponsivenessAjaxFieldQueryCustomMethodAndService();
140         passed();
141     }
142 }