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.ITUtil; 020 import edu.samplu.common.UpgradedSeleniumITBase; 021 import org.junit.Assert; 022 import org.junit.Test; 023 024 /** 025 * Selenium test that tests collections 026 * 027 * @author Kuali Rice Team (rice.collab@kuali.org) 028 */ 029 public class CollectionsIT extends UpgradedSeleniumITBase { 030 031 @Override 032 public String getTestUrl() { 033 return "/kr-krad/uicomponents?viewId=ConfigurationTestView-Collections&methodToCall=start"; 034 } 035 036 /** 037 * Test adding a column of values to the Default Tests Table Layout 038 */ 039 @Test 040 public void testDefaultTestsTableLayout() throws Exception{ 041 //Thread.sleep(30000); 042 Assert.assertTrue(isTextPresent("Default Tests")); 043 assertTableLayout(); 044 045 waitAndType("name=newCollectionLines['list1'].field1", "asdf1"); 046 waitAndType("name=newCollectionLines['list1'].field2", "asdf2"); 047 waitAndType("name=newCollectionLines['list1'].field3", "asdf3"); 048 waitAndType("name=newCollectionLines['list1'].field4", "asdf4"); 049 waitAndClick("//button[contains(.,'add')]"); // the first button is the one we want 050 051 for (int second = 0;; second++) { 052 if (second >= 60) Assert.fail("timeout"); 053 try { if (getValue("name=newCollectionLines['list1'].field1").equals("")) break; } catch (Exception e) {} 054 Thread.sleep(1000); 055 } 056 057 Assert.assertEquals("", getValue("name=newCollectionLines['list1'].field1")); 058 Assert.assertEquals("", getValue("name=newCollectionLines['list1'].field2")); 059 Assert.assertEquals("", getValue("name=newCollectionLines['list1'].field3")); 060 Assert.assertEquals("", getValue("name=newCollectionLines['list1'].field4")); 061 Assert.assertEquals("asdf1", getValue("name=list1[0].field1")); 062 Assert.assertEquals("asdf2", getValue("name=list1[0].field2")); 063 Assert.assertEquals("asdf3", getValue("name=list1[0].field3")); 064 Assert.assertEquals("asdf4", getValue("name=list1[0].field4")); 065 // TODO how to figure out which delete button for the one we just added? 066 } 067 068 private void assertTableLayout() { 069 Assert.assertTrue(isTextPresent("Table Layout")); 070 Assert.assertTrue(isTextPresent("* Field 1")); 071 Assert.assertTrue(isTextPresent("* Field 2")); 072 Assert.assertTrue(isTextPresent("* Field 3")); 073 Assert.assertTrue(isTextPresent("* Field 4")); 074 Assert.assertTrue(isTextPresent("Actions")); 075 } 076 077 /** 078 * Test adding a column of values to the Add Blank Line Tests Table Layout 079 */ 080 @Test 081 public void testAddBlankLine() throws Exception { 082 waitAndClick("link=Add Blank Line"); 083 waitAndClick("//button[contains(.,'Add Line')]"); 084 085 waitForElementPresent("name=list1[0].field1"); 086 assertTableLayout(); 087 Assert.assertEquals("", getValue("name=list1[0].field1")); 088 Assert.assertEquals("", getValue("name=list1[0].field2")); 089 Assert.assertEquals("", getValue("name=list1[0].field3")); 090 Assert.assertEquals("", getValue("name=list1[0].field4")); 091 Assert.assertEquals("5", getValue("name=list1[1].field1")); 092 Assert.assertEquals("6", getValue("name=list1[1].field2")); 093 Assert.assertEquals("7", getValue("name=list1[1].field3")); 094 Assert.assertEquals("8", getValue("name=list1[1].field4")); 095 // TODO type in new numbers into list1[0] fields and check that sums are updated and correct 096 } 097 098 // TODO similar tests for other Collection Tabs 099 100 /** 101 * Test action column placement in table layout collections 102 */ 103 @Test 104 public void testActionColumnPlacement() throws Exception { 105 106 //Lack of proper locators its not possible to uniquely identify/locate this elements without use of ID's. 107 //This restricts us to use the XPath to locate elements from the dome. 108 //This test is prone to throw error in case of any changes in the dom Html graph. 109 110 111 112 waitAndClick("link=Column Sequence"); 113 Thread.sleep(2000); 114 //waitAndClick("css=div.jGrowl-close"); 115 // check if actions column RIGHT by default 116 //Assert.assertTrue(isElementPresent("//div[@id='ConfigurationTestView-collection1']//tr[2]/td[6]//button[contains(.,\"delete\")]")); 117 for (int second = 0;; second++) { 118 if (second >= 60) Assert.fail("timeout"); 119 try { if (isElementPresent("//tr[2]/td[6]/div/fieldset/div/div[2]/button")) break; } catch (Exception e) {} 120 Thread.sleep(1000); 121 } 122 Assert.assertTrue(isElementPresent("//tr[2]/td[6]/div/fieldset/div/div[2]/button")); 123 124 // check if actions column is LEFT 125 //Assert.assertTrue(isElementPresent("//div[@id='ConfigurationTestView-collection2']//tr[2]/td[1]//button[contains(.,\"delete\")]")); 126 for (int second = 0;; second++) { 127 if (second >= 60) Assert.fail("timeout"); 128 try { if (isElementPresent("//div[2]/div[2]/div[2]/table/tbody/tr[2]/td/div/fieldset/div/div[2]/button")) break; } catch (Exception e) {} 129 Thread.sleep(1000); 130 } 131 Assert.assertTrue(isElementPresent("//div[2]/div[2]/div[2]/table/tbody/tr[2]/td/div/fieldset/div/div[2]/button")); 132 133 // check if actions column is 3rd in a sub collection 134 //Assert.assertTrue(isElementPresent("//div[@id='ConfigurationTestView-subCollection2_line0']//tr[2]/td[3]//button[contains(.,\"delete\")]")); 135 for (int second = 0;; second++) { 136 if (second >= 60) Assert.fail("timeout"); 137 try { if (isElementPresent("//tr[2]/td[3]/div/fieldset/div/div[2]/button")) break; } catch (Exception e) {} 138 Thread.sleep(1000); 139 } 140 Assert.assertTrue(isElementPresent("//tr[2]/td[3]/div/fieldset/div/div[2]/button")); 141 142 143 } 144 }