001 /* 002 * Copyright 2006-2012 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 */ 016 017 package edu.samplu.krad.configview; 018 019 import edu.samplu.common.WebDriverLegacyITBase; 020 import org.junit.Assert; 021 import org.junit.Test; 022 import org.openqa.selenium.By; 023 024 /** 025 * Selenium test that tests collections 026 * 027 * @author Kuali Rice Team (rice.collab@kuali.org) 028 */ 029 public class CollectionsLegacyIT extends WebDriverLegacyITBase { 030 031 032 @Override 033 public String getTestUrl() { 034 return "/kr-krad/uicomponents?viewId=ConfigurationTestView-Collections&methodToCall=start"; 035 } 036 037 /** 038 * Test adding a column of values to the Default Tests Table Layout 039 */ 040 @Test 041 public void testDefaultTestsTableLayout() throws Exception{ 042 043 assertTableLayout(); 044 waitAndTypeByName("newCollectionLines['list1'].field1", "asdf1"); 045 waitAndTypeByName("newCollectionLines['list1'].field2", "asdf2"); 046 waitAndTypeByName("newCollectionLines['list1'].field3", "asdf3"); 047 waitAndTypeByName("newCollectionLines['list1'].field4", "asdf4"); 048 waitAndClickByXpath("//button[contains(.,'add')]"); // the first button is the one we want 049 050 for (int second = 0;; second++) { 051 if (second >= 60) Assert.fail("timeout"); 052 try { if ( getAttributeByName("newCollectionLines['list1'].field1","value").equals("")) break; } catch (Exception e) {} 053 Thread.sleep(1000); 054 } 055 056 Assert.assertEquals("",getAttributeByName("newCollectionLines['list1'].field1","value")); 057 Assert.assertEquals("", getAttributeByName("newCollectionLines['list1'].field2","value")); 058 Assert.assertEquals("", getAttributeByName("newCollectionLines['list1'].field3","value")); 059 Assert.assertEquals("", getAttributeByName("newCollectionLines['list1'].field4","value")); 060 Assert.assertEquals("asdf1", getAttributeByName("list1[0].field1","value")); 061 Assert.assertEquals("asdf2", getAttributeByName("list1[0].field2","value")); 062 Assert.assertEquals("asdf3", getAttributeByName("list1[0].field3","value")); 063 Assert.assertEquals("asdf4", getAttributeByName("list1[0].field4","value")); 064 065 Assert.assertTrue(isElementPresentByXpath("//div[@id='Collections-Base-TableLayout_disclosureContent']/div/table/tbody/tr[2]/td[6]/div/fieldset/div/div[@class='uif-boxLayout uif-horizontalBoxLayout clearfix']/button")); 066 passed(); 067 } 068 069 070 private void assertTableLayout() { 071 Assert.assertTrue(driver.getPageSource().contains("Table Layout")); 072 Assert.assertTrue(driver.getPageSource().contains("Field 1")); 073 Assert.assertTrue(driver.getPageSource().contains("Field 2")); 074 Assert.assertTrue(driver.getPageSource().contains("Field 3")); 075 Assert.assertTrue(driver.getPageSource().contains("Field 4")); 076 Assert.assertTrue(driver.getPageSource().contains("Actions")); 077 } 078 079 /** 080 * Test adding a column of values to the Add Blank Line Tests Table Layout 081 */ 082 @Test 083 public void testAddBlankLine() throws Exception { 084 waitAndClickByLinkText("Add Blank Line"); 085 waitAndClickByXpath("//button[contains(.,'Add Line')]"); 086 Thread.sleep(3000); // TODO a wait until the loading.gif isn't visible woudl be better 087 assertElementPresentByName("list1[0].field1"); 088 089 assertTableLayout(); 090 Assert.assertEquals("", getAttributeByName("list1[0].field1","value")); 091 Assert.assertEquals("", getAttributeByName("list1[0].field2","value")); 092 Assert.assertEquals("", getAttributeByName("list1[0].field3","value")); 093 Assert.assertEquals("", getAttributeByName("list1[0].field4","value")); 094 Assert.assertEquals("5", getAttributeByName("list1[1].field1","value")); 095 Assert.assertEquals("6", getAttributeByName("list1[1].field2","value")); 096 Assert.assertEquals("7", getAttributeByName("list1[1].field3","value")); 097 Assert.assertEquals("8", getAttributeByName("list1[1].field4","value")); 098 099 100 Assert.assertEquals("Total: 419", driver.findElement(By.xpath("//fieldset/div/div[2]/div[2]")).getText()); 101 waitAndTypeByName("list1[0].field1", "1"); 102 waitAndTypeByName("list1[0].field2", "1"); 103 waitAndTypeByName("list1[0].field3", "1"); 104 waitAndTypeByName("list1[0].field4", "1"); 105 Assert.assertEquals("Total: 420", driver.findElement(By.xpath("//fieldset/div/div[2]/div[2]")).getText()); 106 passed(); 107 108 } 109 110 111 /** 112 * Test action column placement in table layout collections 113 */ 114 @Test 115 public void testActionColumnPlacement() throws Exception { 116 117 //Lack of proper locators its not possible to uniquely identify/locate this elements without use of ID's. 118 //This restricts us to use the XPath to locate elements from the dome. 119 //This test is prone to throw error in case of any changes in the dom Html graph. 120 121 122 123 waitAndClickByLinkText("Column Sequence"); 124 Thread.sleep(2000); 125 //waitAndClick("css=div.jGrowl-close"); 126 // check if actions column RIGHT by default 127 //Assert.assertTrue(isElementPresent("//div[@id='ConfigurationTestView-collection1']//tr[2]/td[6]//button[contains(.,\"delete\")]")); 128 for (int second = 0;; second++) { 129 if (second >= 60) Assert.fail("timeout"); 130 try { if (isElementPresentByXpath("//tr[2]/td[6]/div/fieldset/div/div[2]/button")) break; } catch (Exception e) {} 131 Thread.sleep(1000); 132 } 133 Assert.assertTrue(isElementPresentByXpath("//tr[2]/td[6]/div/fieldset/div/div[2]/button")); 134 135 // check if actions column is LEFT 136 //Assert.assertTrue(isElementPresent("//div[@id='ConfigurationTestView-collection2']//tr[2]/td[1]//button[contains(.,\"delete\")]")); 137 for (int second = 0;; second++) { 138 if (second >= 60) Assert.fail("timeout"); 139 try { if (isElementPresentByXpath("//div[2]/div[2]/div[2]/table/tbody/tr[2]/td/div/fieldset/div/div[2]/button")) break; } catch (Exception e) {} 140 Thread.sleep(1000); 141 } 142 Assert.assertTrue(isElementPresentByXpath("//div[2]/div[2]/div[2]/table/tbody/tr[2]/td/div/fieldset/div/div[2]/button")); 143 144 // check if actions column is 3rd in a sub collection 145 //Assert.assertTrue(isElementPresent("//div[@id='ConfigurationTestView-subCollection2_line0']//tr[2]/td[3]//button[contains(.,\"delete\")]")); 146 for (int second = 0;; second++) { 147 if (second >= 60) Assert.fail("timeout"); 148 try { if (isElementPresentByXpath("//tr[2]/td[3]/div/fieldset/div/div[2]/button")) break; } catch (Exception e) {} 149 Thread.sleep(1000); 150 } 151 Assert.assertTrue(isElementPresentByXpath("//tr[2]/td[3]/div/fieldset/div/div[2]/button")); 152 passed(); 153 154 } 155 156 157 @Test 158 public void testAddViaLightbox() throws Exception { 159 160 waitAndClickByLinkText("Add Via Lightbox"); 161 Assert.assertEquals("Total: 419", driver.findElement(By.xpath("//fieldset/div/div[2]/div[2]")).getText()); 162 waitAndClickByXpath("//button[contains(.,'Add Line')]"); 163 Thread.sleep(3000); 164 waitAndTypeByXpath("//form/div/table/tbody/tr/td/div/input", "1"); 165 waitAndTypeByXpath("//form/div/table/tbody/tr[2]/td/div/input", "1"); 166 waitAndTypeByXpath("//form/div/table/tbody/tr[3]/td/div/input", "1"); 167 waitAndTypeByXpath("//form/div/table/tbody/tr[4]/td/div/input", "1"); 168 waitAndClickByXpath("//button[@id='uif-addLine_add']"); 169 Thread.sleep(3000); 170 Assert.assertEquals("Total: 420", driver.findElement(By.xpath("//fieldset/div/div[2]/div[2]")).getText()); 171 passed(); 172 } 173 174 @Test 175 public void testColumnSequence() throws Exception { 176 177 waitAndClickByLinkText("Column Sequence"); 178 Thread.sleep(3000); 179 waitAndTypeByName("newCollectionLines['list1'].field1", "1"); 180 waitAndTypeByName("newCollectionLines['list1'].field2", "1"); 181 waitAndTypeByName("newCollectionLines['list1'].field3", "1"); 182 waitAndTypeByName("newCollectionLines['list1'].field4", "1"); 183 waitAndClick(By.id("uif-addLine_add")); 184 Thread.sleep(3000); 185 186 //Check if row has been added really or not 187 Assert.assertEquals("", getAttributeByName("newCollectionLines['list1'].field1","value")); 188 Assert.assertEquals("", getAttributeByName("newCollectionLines['list1'].field2","value")); 189 Assert.assertEquals("", getAttributeByName("newCollectionLines['list1'].field3","value")); 190 Assert.assertEquals("", getAttributeByName("newCollectionLines['list1'].field4","value")); 191 Assert.assertEquals("1", getAttributeByName("list1[0].field1","value")); 192 Assert.assertEquals("1", getAttributeByName("list1[0].field2","value")); 193 Assert.assertEquals("1", getAttributeByName("list1[0].field3","value")); 194 Assert.assertEquals("1", getAttributeByName("list1[0].field4","value")); 195 196 //Check for the added if delete is present or not 197 Assert.assertTrue(isElementPresentByXpath("//div[@id='Collections-ColumnSequence-TableDefault_disclosureContent']/div[@class='dataTables_wrapper']/table/tbody/tr[2]/td[6]/div/fieldset/div/div[@class='uif-boxLayout uif-horizontalBoxLayout clearfix']/button")); 198 passed(); 199 } 200 201 @Test 202 public void testSequencerow() throws Exception { 203 waitAndClickByLinkText("Save Row"); 204 Thread.sleep(3000); 205 waitAndTypeByName("newCollectionLines['list1'].field1", "1"); 206 waitAndTypeByName("newCollectionLines['list1'].field2", "1"); 207 waitAndTypeByName("newCollectionLines['list1'].field3", "1"); 208 waitAndTypeByName("newCollectionLines['list1'].field4", "1"); 209 210 waitAndClickByXpath("//button[contains(.,'add')]"); 211 Thread.sleep(3000); 212 213 //Check if row has been added really or not 214 Assert.assertEquals("", getAttributeByName("newCollectionLines['list1'].field1","value")); 215 Assert.assertEquals("", getAttributeByName("newCollectionLines['list1'].field2","value")); 216 Assert.assertEquals("", getAttributeByName("newCollectionLines['list1'].field3","value")); 217 Assert.assertEquals("", getAttributeByName("newCollectionLines['list1'].field4","value")); 218 Assert.assertEquals("1",getAttributeByName("list1[0].field1","value")); 219 Assert.assertEquals("1",getAttributeByName("list1[0].field2","value")); 220 Assert.assertEquals("1",getAttributeByName("list1[0].field3","value")); 221 Assert.assertEquals("1",getAttributeByName("list1[0].field4","value")); 222 223 //Check for the added if delete is present or not 224 Assert.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")); 225 Assert.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']")); 226 passed(); 227 } 228 229 230 }