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.ITUtil;
20  import edu.samplu.common.UpgradedSeleniumITBase;
21  import org.junit.Assert;
22  import org.junit.Test;
23  
24  /**
25   * Selenium test that tests collections
26   *
27   * @author Kuali Rice Team (rice.collab@kuali.org)
28   */
29  public class CollectionsIT extends UpgradedSeleniumITBase {
30  
31      @Override
32      public String getTestUrl() {
33          return "/kr-krad/uicomponents?viewId=ConfigurationTestView-Collections&methodToCall=start";
34      }
35  
36      /**
37       * Test adding a column of values to the Default Tests Table Layout
38       */
39      @Test
40      public void testDefaultTestsTableLayout() throws Exception{
41          //Thread.sleep(30000);
42          Assert.assertTrue(isTextPresent("Default Tests"));
43          assertTableLayout();
44  
45          waitAndType("name=newCollectionLines['list1'].field1", "asdf1");
46          waitAndType("name=newCollectionLines['list1'].field2", "asdf2");
47          waitAndType("name=newCollectionLines['list1'].field3", "asdf3");
48          waitAndType("name=newCollectionLines['list1'].field4", "asdf4");
49          waitAndClick("//button[contains(.,'add')]"); // the first button is the one we want
50  
51          for (int second = 0;; second++) {
52              if (second >= 60) Assert.fail("timeout");
53              try { if (getValue("name=newCollectionLines['list1'].field1").equals("")) break; } catch (Exception e) {}
54              Thread.sleep(1000);
55          }
56  
57          Assert.assertEquals("", getValue("name=newCollectionLines['list1'].field1"));
58          Assert.assertEquals("", getValue("name=newCollectionLines['list1'].field2"));
59          Assert.assertEquals("", getValue("name=newCollectionLines['list1'].field3"));
60          Assert.assertEquals("", getValue("name=newCollectionLines['list1'].field4"));
61          Assert.assertEquals("asdf1", getValue("name=list1[0].field1"));
62          Assert.assertEquals("asdf2", getValue("name=list1[0].field2"));
63          Assert.assertEquals("asdf3", getValue("name=list1[0].field3"));
64          Assert.assertEquals("asdf4", getValue("name=list1[0].field4"));
65          // TODO how to figure out which delete button for the one we just added?
66      }
67  
68      private void assertTableLayout() {
69          Assert.assertTrue(isTextPresent("Table Layout"));
70          Assert.assertTrue(isTextPresent("* Field 1"));
71          Assert.assertTrue(isTextPresent("* Field 2"));
72          Assert.assertTrue(isTextPresent("* Field 3"));
73          Assert.assertTrue(isTextPresent("* Field 4"));
74          Assert.assertTrue(isTextPresent("Actions"));
75      }
76  
77      /**
78       * Test adding a column of values to the Add Blank Line Tests Table Layout
79       */
80      @Test
81      public void testAddBlankLine() throws Exception {
82          waitAndClick("link=Add Blank Line");
83          waitAndClick("//button[contains(.,'Add Line')]");
84  
85          waitForElementPresent("name=list1[0].field1");
86          assertTableLayout();
87          Assert.assertEquals("", getValue("name=list1[0].field1"));
88          Assert.assertEquals("", getValue("name=list1[0].field2"));
89          Assert.assertEquals("", getValue("name=list1[0].field3"));
90          Assert.assertEquals("", getValue("name=list1[0].field4"));
91          Assert.assertEquals("5", getValue("name=list1[1].field1"));
92          Assert.assertEquals("6", getValue("name=list1[1].field2"));
93          Assert.assertEquals("7", getValue("name=list1[1].field3"));
94          Assert.assertEquals("8", getValue("name=list1[1].field4"));
95          // TODO type in new numbers into list1[0] fields and check that sums are updated and correct
96      }
97  
98      // TODO similar tests for other Collection Tabs
99  
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 }