View Javadoc

1   /*
2    * Copyright 2006-2012 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  
17  package edu.samplu.krad.configview;
18  
19  import edu.samplu.common.WebDriverLegacyITBase;
20  import org.junit.Assert;
21  import org.junit.Test;
22  import org.openqa.selenium.By;
23  
24  /**
25   * Selenium test that tests collections
26   *
27   * @author Kuali Rice Team (rice.collab@kuali.org)
28   */
29  public class CollectionsLegacyIT extends WebDriverLegacyITBase {
30  	
31  	
32      @Override
33      public String getTestUrl() {
34          return "/kr-krad/uicomponents?viewId=ConfigurationTestView-Collections&methodToCall=start";
35      }
36  
37      /**
38       * Test adding a column of values to the Default Tests Table Layout
39       */
40      @Test
41      public void testDefaultTestsTableLayout() throws Exception{
42          
43          assertTableLayout();        
44          waitAndTypeByName("newCollectionLines['list1'].field1", "asdf1");
45          waitAndTypeByName("newCollectionLines['list1'].field2", "asdf2");
46          waitAndTypeByName("newCollectionLines['list1'].field3", "asdf3");
47          waitAndTypeByName("newCollectionLines['list1'].field4", "asdf4");
48          waitAndClickByXpath("//button[contains(.,'add')]"); // the first button is the one we want
49                  
50          for (int second = 0;; second++) {
51              if (second >= 60) Assert.fail("timeout");
52              try { if ( getAttributeByName("newCollectionLines['list1'].field1","value").equals("")) break; } catch (Exception e) {}
53              Thread.sleep(1000);
54          }
55  
56          Assert.assertEquals("",getAttributeByName("newCollectionLines['list1'].field1","value"));
57          Assert.assertEquals("", getAttributeByName("newCollectionLines['list1'].field2","value"));
58          Assert.assertEquals("", getAttributeByName("newCollectionLines['list1'].field3","value"));
59          Assert.assertEquals("", getAttributeByName("newCollectionLines['list1'].field4","value"));
60          Assert.assertEquals("asdf1", getAttributeByName("list1[0].field1","value"));
61          Assert.assertEquals("asdf2", getAttributeByName("list1[0].field2","value"));
62          Assert.assertEquals("asdf3", getAttributeByName("list1[0].field3","value"));
63          Assert.assertEquals("asdf4", getAttributeByName("list1[0].field4","value"));
64          
65          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"));
66          passed();
67      }
68  
69      
70      private void assertTableLayout() {
71          Assert.assertTrue(driver.getPageSource().contains("Table Layout"));
72          Assert.assertTrue(driver.getPageSource().contains("Field 1"));
73          Assert.assertTrue(driver.getPageSource().contains("Field 2"));
74          Assert.assertTrue(driver.getPageSource().contains("Field 3"));
75          Assert.assertTrue(driver.getPageSource().contains("Field 4"));
76          Assert.assertTrue(driver.getPageSource().contains("Actions"));
77      }
78  
79      /**
80       * Test adding a column of values to the Add Blank Line Tests Table Layout
81       */
82      @Test
83      public void testAddBlankLine() throws Exception {
84          waitAndClickByLinkText("Add Blank Line");
85          waitAndClickByXpath("//button[contains(.,'Add Line')]");
86          Thread.sleep(3000); //  TODO a wait until the loading.gif isn't visible woudl be better
87          assertElementPresentByName("list1[0].field1");
88       
89          assertTableLayout();
90          Assert.assertEquals("", getAttributeByName("list1[0].field1","value"));
91          Assert.assertEquals("", getAttributeByName("list1[0].field2","value"));
92          Assert.assertEquals("", getAttributeByName("list1[0].field3","value"));
93          Assert.assertEquals("", getAttributeByName("list1[0].field4","value"));
94          Assert.assertEquals("5", getAttributeByName("list1[1].field1","value"));
95          Assert.assertEquals("6", getAttributeByName("list1[1].field2","value"));
96          Assert.assertEquals("7", getAttributeByName("list1[1].field3","value"));
97          Assert.assertEquals("8", getAttributeByName("list1[1].field4","value"));
98          
99          
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 }