001/** 002 * Copyright 2005-2014 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.krad.demo.uif.library.clientresponsiveness; 017 018import org.junit.Ignore; 019import org.junit.Test; 020 021import org.kuali.rice.testtools.selenium.WebDriverLegacyITBase; 022import org.kuali.rice.testtools.selenium.WebDriverUtils; 023import org.openqa.selenium.By; 024import org.openqa.selenium.Keys; 025import org.openqa.selenium.WebElement; 026 027/** 028 * @author Kuali Rice Team (rice.collab@kuali.org) 029 */ 030public class LibraryClientResponsivenessAjaxFieldQueryAft extends WebDriverLegacyITBase { 031 032 /** 033 * /kr-krad/kradsampleapp?viewId=Demo-AjaxFieldQueryView 034 */ 035 public static final String BOOKMARK_URL = "/kr-krad/kradsampleapp?viewId=Demo-AjaxFieldQueryView"; 036 037 @Override 038 protected String getBookmarkUrl() { 039 return BOOKMARK_URL; 040 } 041 042 @Override 043 protected void navigate() throws Exception { 044 waitAndClickLibraryLink(); 045 waitAndClickByLinkText("Client Responsiveness"); 046 waitAndClickByLinkText("AJAX Field Query"); 047 } 048 049 protected void testClientResponsivenessAjaxFieldQuery() throws Exception { 050 waitAndClickByLinkText("Ajax Field Query"); 051 waitForElementPresentByXpath("//input[@name='inputField3' and @value='a1']"); 052 clearTypeAndFocus("inputField3", "a1"); 053 checkIfFocusSuccessful("inputField3", "a1", "Travel Account 1"); 054 assertTextPresent(new String[] {"Travel Account 1", "fred"}); 055 } 056 057 protected void testClientResponsivenessAjaxFieldQueryCustomMethod() throws Exception { 058 waitAndClickByLinkText("Ajax Field Query Custom Method"); 059 waitForElementPresentByXpath("//input[@name='inputField6' and @value='a2']"); 060 clearTypeAndFocus("inputField6", "a2"); 061 checkIfFocusSuccessful("inputField6", "a2", "Travel Account 2"); 062 assertTextPresent(new String[] {"Travel Account 2", "fran"}); 063 } 064 065 protected void testClientResponsivenessAjaxFieldQueryCustomMethodAndService() throws Exception { 066 waitAndClickByLinkText("Ajax Field Query Custom Method and Service"); 067 waitForElementPresentByXpath("//input[@name='inputField9' and @value='a3']"); 068 clearTypeAndFocus("inputField9", "a3"); 069 checkIfFocusSuccessful("inputField9", "a3", "Travel Account 3"); 070 assertTextPresent(new String[] {"Travel Account 3", "frank"}); 071 } 072 073 /** 074 * focus, blur seem real flaky on xvfb, maybe clear, enter value, and tab will be better 075 * 076 * @param fieldName name of the field that needs to be focused on. 077 * @param fieldValue value to be placed in field 078 * 079 * @throws InterruptedException 080 */ 081 private void clearTypeAndFocus(String fieldName, String fieldValue) throws InterruptedException { 082 clearTextByName(fieldName); 083 WebElement element = WebDriverUtils.waitFor(driver, WebDriverUtils.configuredImplicityWait(), By.name( 084 fieldName), this.getClass().toString()); 085 element.sendKeys("", fieldValue); 086 fireEvent(fieldName, "focus"); 087 fireEvent(fieldName, "blur"); 088 assertTextPresent(fieldValue); 089 } 090 091 /** 092 * If the expected message did not appear it means that the field did not gain focus so there was no tab off of the 093 * field. This will attempt to regain focus of the page and try again. 094 * 095 * @param fieldName name of the field that needs to be focused on. 096 * @param fieldValue value to be placed in field 097 * @param expectedMessage message that should be present on the screen after tabbing out of the field 098 * 099 * @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}