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 edu.sampleu.krad.configview; 017 018import org.junit.Test; 019import org.kuali.rice.testtools.selenium.WebDriverLegacyITBase; 020import org.openqa.selenium.By; 021 022/** 023 * @author Kuali Rice Team (rice.collab@kuali.org) 024 */ 025public class CollectionsAft extends WebDriverLegacyITBase { 026 027 /** 028 * /kr-krad/uicomponents?viewId=ConfigurationTestView-Collections&methodToCall=start 029 */ 030 public static final String BOOKMARK_URL = "/kr-krad/uicomponents?viewId=ConfigurationTestView-Collections&methodToCall=start"; 031 032 /** 033 * (//a[contains(text(),'Collections Configuration Test View')])[2] 034 */ 035 public static final String TEXT_COLLECTIONS_CONFIGURATION_TEST_VIEW_XPATH = 036 "(//a[contains(text(),'Collections Configuration Test View')])[1]"; 037 038 /** 039 * Kuali :: Collection Test View 040 */ 041 public static final String KUALI_COLLECTION_WINDOW_TITLE = "Kuali :: Collection Test View"; 042 043 @Override 044 protected String getBookmarkUrl() { 045 return BOOKMARK_URL; 046 } 047 048 protected void navigate() throws Exception { 049 waitAndClickKRAD(); 050 jGrowl("Click Collections Configuration Test View link"); 051 waitAndClickByXpath(TEXT_COLLECTIONS_CONFIGURATION_TEST_VIEW_XPATH); 052 switchToWindow(KUALI_COLLECTION_WINDOW_TITLE); 053 } 054 055 protected void testCollections() throws Exception { 056 testActionColumnPlacement(); 057 testAddViaLightbox(); 058 testColumnSequence(); 059 testSequencerow(); 060 passed(); 061 } 062 063 @Test 064 public void testCollectionsBookmark() throws Exception { 065 testCollections(); 066 } 067 068 @Test 069 public void testCollectionsNav() throws Exception { 070 testCollections(); 071 } 072 073 @Test 074 public void testAddBlankLineBookmark() throws Exception { 075 testAddBlankLine(); 076 passed(); 077 } 078 079 @Test 080 public void testAddBlankLineNav() throws Exception { 081 testAddBlankLine(); 082 passed(); 083 } 084 085 @Test 086 public void testAddDeleteBookmark() throws Exception { 087 testAddRowOfText(); 088 passed(); 089 } 090 091 @Test 092 public void testAddDeleteNav() throws Exception { 093 testAddRowOfText(); 094 passed(); 095 } 096 097 @Test 098 public void testSumBookmark() throws Exception { 099 testSum(); 100 passed(); 101 } 102 103 @Test 104 public void testSumNav() throws Exception { 105 testSum(); 106 passed(); 107 } 108 109 protected void testAddRowOfText() throws Exception { 110 assertTableLayout(); 111 waitAndTypeByName("newCollectionLines['list1'].field1", "asdf1"); 112 waitAndTypeByName("newCollectionLines['list1'].field2", "asdf2"); 113 waitAndTypeByName("newCollectionLines['list1'].field3", "asdf3"); 114 waitAndTypeByName("newCollectionLines['list1'].field4", "asdf4"); 115 clickAdd(); 116 117 for (int second = 0;; second++) { 118 if (second >= waitSeconds) 119 jiraAwareFail(TIMEOUT_MESSAGE); 120 try { 121 if (waitAndGetAttributeByName("newCollectionLines['list1'].field1", "value").equals("")) 122 break; 123 } catch (Exception e) {} 124 Thread.sleep(1000); 125 } 126 127 assertEquals("", waitAndGetAttributeByName("newCollectionLines['list1'].field1", "value")); 128 assertEquals("", waitAndGetAttributeByName("newCollectionLines['list1'].field2", "value")); 129 assertEquals("", waitAndGetAttributeByName("newCollectionLines['list1'].field3", "value")); 130 assertEquals("", waitAndGetAttributeByName("newCollectionLines['list1'].field4", "value")); 131 assertEquals("asdf1", waitAndGetAttributeByName("list1[0].field1", "value")); 132 assertEquals("asdf2", waitAndGetAttributeByName("list1[0].field2", "value")); 133 assertEquals("asdf3", waitAndGetAttributeByName("list1[0].field3", "value")); 134 assertEquals("asdf4", waitAndGetAttributeByName("list1[0].field4", "value")); 135 } 136 137 /** 138 * Test adding a column of values to the Add Blank Line Tests Table Layout 139 */ 140 protected void testAddBlankLine() throws Exception { 141 waitAndClickByLinkText("Add Blank Line"); 142 waitAndClickById("Collections-AddBlankLine-TableTop_del_line0"); // the line withe asdf1, etc. 143 waitForProgressLoading(); 144 waitAndClickByXpath("//button[contains(.,'Add Line')]"); 145 waitForProgressLoading(); 146 waitForElementPresentByName("list1[0].field1"); 147 assertTableLayout(); 148 waitForProgressAddingLine(); 149 assertEquals("", waitAndGetAttributeByName("list1[0].field1", "value")); 150 assertEquals("", waitAndGetAttributeByName("list1[0].field2", "value")); 151 assertEquals("", waitAndGetAttributeByName("list1[0].field3", "value")); 152 assertEquals("", waitAndGetAttributeByName("list1[0].field4", "value")); 153 } 154 155 private void testSum() throws InterruptedException { 156 assertEquals("5", waitAndGetAttributeByName("list1[0].field1", "value")); 157 assertEquals("6", waitAndGetAttributeByName("list1[0].field2", "value")); 158 assertEquals("7", waitAndGetAttributeByName("list1[0].field3", "value")); 159 assertEquals("8", waitAndGetAttributeByName("list1[0].field4", "value")); 160 Integer preValue= Integer.parseInt(driver.findElement(By.xpath("//fieldset/div/div[2]/p")).getText()); 161 waitAndTypeByName("list1[0].field1", "1"); 162 waitAndTypeByName("list1[0].field2", "1"); 163 waitAndTypeByName("list1[0].field3", "1"); 164 waitAndTypeByName("list1[0].field4", "1"); 165 Integer postValue= Integer.parseInt(driver.findElement(By.xpath("//fieldset/div/div[2]/p")).getText()); 166 if(preValue>postValue) { 167 jiraAwareFail("Totalling not working in " + getClass().toString()); 168 } 169 } 170 171 /** 172 * Test action column placement in table layout collections 173 */ 174 protected void testActionColumnPlacement() throws Exception { 175 //Lack of proper locators its not possible to uniquely identify/locate this elements without use of ID's. 176 //This restricts us to use the XPath to locate elements from the dome. 177 //This test is prone to throw error in case of any changes in the dom Html graph. 178 waitAndClickByLinkText("Column Sequence"); 179 Thread.sleep(2000); 180 181 //jiraAwareWaitAndClick("css=div.jGrowl-close"); 182 // check if actions column RIGHT by default 183 //assertTrue(isElementPresent("//div[@id='ConfigurationTestView-collection1']//tr[2]/td[6]//button[contains(.,\"delete\")]")); 184 for (int second = 0;; second++) { 185 if (second >= waitSeconds) 186 jiraAwareFail(TIMEOUT_MESSAGE); 187 try { 188 if (isElementPresentByXpath("//tr[2]/td[6]/div/fieldset/div/button")) 189 break; 190 } catch (Exception e) {} 191 Thread.sleep(1000); 192 } 193 assertTrue(getClass().toString(), isElementPresentByXpath("//tr[2]/td[6]/div/fieldset/div/button")); 194 195 // check if actions column is LEFT 196 //assertTrue(isElementPresent("//div[@id='ConfigurationTestView-collection2']//tr[2]/td[1]//button[contains(.,\"delete\")]")); 197 for (int second = 0;; second++) { 198 if (second >= waitSeconds) 199 jiraAwareFail(TIMEOUT_MESSAGE); 200 try { 201 if (isElementPresentByXpath("//tr/td/div/fieldset/div/button[@id='Collections-ColumnSequence-TableLeft_add']")) 202 break; 203 } catch (Exception e) {} 204 Thread.sleep(1000); 205 } 206 assertTrue(getClass().toString(), isElementPresentByXpath("//tr/td/div/fieldset/div/button[@id='Collections-ColumnSequence-TableLeft_add']")); 207 208 // check if actions column is 3rd in a sub collection 209 //assertTrue(isElementPresent("//div[@id='ConfigurationTestView-subCollection2_line0']//tr[2]/td[3]//button[contains(.,\"delete\")]")); 210 for (int second = 0;; second++) { 211 if (second >= waitSeconds) 212 jiraAwareFail(TIMEOUT_MESSAGE); 213 try { 214 if (isElementPresentByXpath("//tr[2]/td[3]/div/fieldset/div/button")) 215 break; 216 } catch (Exception e) {} 217 Thread.sleep(1000); 218 } 219 assertTrue(getClass().toString(), isElementPresentByXpath("//tr[2]/td[3]/div/fieldset/div/button")); 220 } 221 222 protected void testAddViaLightbox() throws Exception { 223 waitAndClickByLinkText("Add Via Lightbox"); 224 Integer preValue= Integer.parseInt(driver.findElement(By.xpath("//fieldset/div/div[2]/p")).getText()); 225 waitAndClickButtonByText("Add Line"); 226 waitForProgressAddingLine(); 227 waitAndTypeByXpath("//div[@class='modal-body']/div[2]/div/input", "1"); 228 waitAndTypeByXpath("//div[@class='modal-body']/div[4]/div/input", "1"); 229 waitAndTypeByXpath("//div[@class='modal-body']/div[6]/div/input", "1"); 230 waitAndTypeByXpath("//div[@class='modal-body']/div[8]/div/input", "1"); 231 waitAndClickByXpath("//button[@id='Collections-AddViaLightbox-TableTop_add']"); 232 waitForProgressAddingLine(); 233 Integer postValue= Integer.parseInt(driver.findElement(By.xpath("//fieldset/div/div[2]/p")).getText()); 234 if(preValue>postValue) { 235 jiraAwareFail("Totalling not working in " + getClass().toString()); 236 } 237 } 238 239 protected void testColumnSequence() throws Exception { 240 waitAndClickByLinkText("Column Sequence"); 241 acceptAlert(); 242 waitForProgressLoading(); 243 waitAndTypeByName("newCollectionLines['list1'].field1", "1"); 244 waitAndTypeByName("newCollectionLines['list1'].field2", "1"); 245 waitAndTypeByName("newCollectionLines['list1'].field3", "1"); 246 waitAndTypeByName("newCollectionLines['list1'].field4", "1"); 247 waitAndClick(By.id("Collections-ColumnSequence-TableDefault_add")); 248 waitForProgressAddingLine(); 249 250 //Check if row has been added really or not 251 testIfRowHasBeenAdded(); 252 253 //Check for the added if delete is present or not 254 assertTrue(getClass().toString(), isElementPresentByXpath("//div[@id='Collections-ColumnSequence-TableDefault_disclosureContent']/div[@class='dataTables_wrapper']/table/tbody/tr[2]/td[6]/div/fieldset/div/button")); 255 } 256 257 protected void testSequencerow() throws Exception { 258 waitAndClickByLinkText("Save Row"); 259 acceptAlert(); 260 waitForProgressLoading(); 261 waitAndTypeByName("newCollectionLines['list1'].field1", "1"); 262 waitAndTypeByName("newCollectionLines['list1'].field2", "1"); 263 waitAndTypeByName("newCollectionLines['list1'].field3", "1"); 264 waitAndTypeByName("newCollectionLines['list1'].field4", "1"); 265 clickAdd(); 266 waitForProgressAddingLine(); 267 268 //Check if row has been added really or not 269 testIfRowHasBeenAdded(); 270 271 //Check for the added if delete is present or not 272 assertTrue(getClass().toString(), isElementPresentByXpath("//div[@id='Collections-SaveRow-Table_disclosureContent']/div[@class='dataTables_wrapper']/table/tbody/tr[2]/td[6]/div/fieldset/div/button")); 273 // assertTrue(isElementPresentByXpath("//div[@id='Collections-SaveRow-Table_disclosureContent']/div[@class='dataTables_wrapper']/table/tbody/tr[2]/td[6]/div/fieldset/div/div[@class='uif-boxLayout uif-horizontalBoxLayout clearfix']/button[@class='uif-action uif-secondaryActionButton uif-smallActionButton uif-saveLineAction']")); 274 } 275 276 private void clickAdd() throws InterruptedException { 277 jGrowl("Click Add"); 278 waitAndClickByXpath("//button[contains(.,'Add')]"); 279 } 280 281 protected void testIfRowHasBeenAdded() throws Exception { 282 //Check if row has been added really or not 283 assertEquals("", waitAndGetAttributeByName("newCollectionLines['list1'].field1", "value")); 284 assertEquals("", waitAndGetAttributeByName("newCollectionLines['list1'].field2", "value")); 285 assertEquals("", waitAndGetAttributeByName("newCollectionLines['list1'].field3", "value")); 286 assertEquals("", waitAndGetAttributeByName("newCollectionLines['list1'].field4", "value")); 287 assertEquals("1", waitAndGetAttributeByName("list1[0].field1", "value")); 288 assertEquals("1", waitAndGetAttributeByName("list1[0].field2", "value")); 289 assertEquals("1", waitAndGetAttributeByName("list1[0].field3", "value")); 290 assertEquals("1", waitAndGetAttributeByName("list1[0].field4", "value")); 291 } 292}