View Javadoc
1   /**
2    * Copyright 2005-2014 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  package edu.sampleu.krad.configview;
17  
18  import org.junit.Test;
19  import org.kuali.rice.testtools.selenium.WebDriverLegacyITBase;
20  import org.openqa.selenium.By;
21  
22  /**
23   * @author Kuali Rice Team (rice.collab@kuali.org)
24   */
25  public class CollectionsAft extends WebDriverLegacyITBase {
26  
27      /**
28       * /kr-krad/uicomponents?viewId=ConfigurationTestView-Collections&methodToCall=start
29       */
30      public static final String BOOKMARK_URL = "/kr-krad/uicomponents?viewId=ConfigurationTestView-Collections&methodToCall=start";
31  
32      /**
33       * (//a[contains(text(),'Collections Configuration Test View')])[2]
34       */
35      public static final String TEXT_COLLECTIONS_CONFIGURATION_TEST_VIEW_XPATH =
36              "(//a[contains(text(),'Collections Configuration Test View')])[1]";
37  
38      /**
39       * Kuali :: Collection Test View
40       */
41      public static final String KUALI_COLLECTION_WINDOW_TITLE = "Kuali :: Collection Test View";
42  
43      @Override
44      protected String getBookmarkUrl() {
45          return BOOKMARK_URL;
46      }
47  
48      protected void navigate() throws Exception {
49          waitAndClickKRAD();
50          waitAndClickByXpath(TEXT_COLLECTIONS_CONFIGURATION_TEST_VIEW_XPATH);
51          switchToWindow(KUALI_COLLECTION_WINDOW_TITLE);
52      }
53  
54      protected void testCollections() throws Exception {
55          testActionColumnPlacement();
56          testAddViaLightbox();
57          testColumnSequence();
58          testSequencerow();
59          passed();
60      }
61  
62      @Test
63      public void testCollectionsBookmark() throws Exception {
64          testCollections();
65      }
66  
67      @Test
68      public void testCollectionsNav() throws Exception {
69          testCollections();
70      }
71  
72      @Test
73      public void testAddBlankLineBookmark() throws Exception {
74          testAddBlankLine();
75          passed();
76      }
77  
78      @Test
79      public void testAddBlankLineNav() throws Exception {
80          testAddBlankLine();
81          passed();
82      }
83  
84      @Test
85      public void testAddDeleteBookmark() throws Exception {
86          testAddRowOfText();
87          passed();
88      }
89  
90      @Test
91      public void testAddDeleteNav() throws Exception {
92          testAddRowOfText();
93          passed();
94      }
95  
96      @Test
97      public void testSumBookmark() throws Exception {
98          testSum();
99          passed();
100     }
101 
102     @Test
103     public void testSumNav() throws Exception {
104         testSum();
105         passed();
106     }
107 
108     protected void testAddRowOfText() throws Exception {
109         assertTableLayout();
110         waitAndTypeByName("newCollectionLines['list1'].field1", "asdf1");
111         waitAndTypeByName("newCollectionLines['list1'].field2", "asdf2");
112         waitAndTypeByName("newCollectionLines['list1'].field3", "asdf3");
113         waitAndTypeByName("newCollectionLines['list1'].field4", "asdf4");
114         waitAndClickByXpath("//button[contains(.,'add')]"); // the first button is the one we want
115 
116         for (int second = 0;; second++) {
117             if (second >= waitSeconds)
118                 jiraAwareFail(TIMEOUT_MESSAGE);
119             try {
120                 if (waitAndGetAttributeByName("newCollectionLines['list1'].field1", "value").equals(""))
121                     break;
122             } catch (Exception e) {}
123             Thread.sleep(1000);
124         }
125 
126         assertEquals("", waitAndGetAttributeByName("newCollectionLines['list1'].field1", "value"));
127         assertEquals("", waitAndGetAttributeByName("newCollectionLines['list1'].field2", "value"));
128         assertEquals("", waitAndGetAttributeByName("newCollectionLines['list1'].field3", "value"));
129         assertEquals("", waitAndGetAttributeByName("newCollectionLines['list1'].field4", "value"));
130         assertEquals("asdf1", waitAndGetAttributeByName("list1[0].field1", "value"));
131         assertEquals("asdf2", waitAndGetAttributeByName("list1[0].field2", "value"));
132         assertEquals("asdf3", waitAndGetAttributeByName("list1[0].field3", "value"));
133         assertEquals("asdf4", waitAndGetAttributeByName("list1[0].field4", "value"));
134     }
135 
136     /**
137      * Test adding a column of values to the Add Blank Line Tests Table Layout
138      */
139     protected void testAddBlankLine() throws Exception {
140         waitAndClickByLinkText("Add Blank Line");
141         waitAndClickById("Collections-AddBlankLine-TableTop_del_line0"); // the line withe asdf1, etc.
142         Thread.sleep(3000); //  TODO a wait until the loading.gif isn't visible would be better
143         waitAndClickByXpath("//button[contains(.,'Add Line')]");
144         Thread.sleep(3000); //  TODO a wait until the loading.gif isn't visible would be better
145         assertElementPresentByName("list1[0].field1");
146         assertTableLayout();
147         assertEquals("", waitAndGetAttributeByName("list1[0].field1", "value"));
148         assertEquals("", waitAndGetAttributeByName("list1[0].field2", "value"));
149         assertEquals("", waitAndGetAttributeByName("list1[0].field3", "value"));
150         assertEquals("", waitAndGetAttributeByName("list1[0].field4", "value"));
151     }
152 
153     private void testSum() throws InterruptedException {
154         assertEquals("5", waitAndGetAttributeByName("list1[0].field1", "value"));
155         assertEquals("6", waitAndGetAttributeByName("list1[0].field2", "value"));
156         assertEquals("7", waitAndGetAttributeByName("list1[0].field3", "value"));
157         assertEquals("8", waitAndGetAttributeByName("list1[0].field4", "value"));
158         Integer preValue= Integer.parseInt(driver.findElement(By.xpath("//fieldset/div/div[2]/p")).getText());
159         waitAndTypeByName("list1[0].field1", "1");
160         waitAndTypeByName("list1[0].field2", "1");
161         waitAndTypeByName("list1[0].field3", "1");
162         waitAndTypeByName("list1[0].field4", "1");
163         Integer postValue= Integer.parseInt(driver.findElement(By.xpath("//fieldset/div/div[2]/p")).getText());
164         if(preValue>postValue) {
165             jiraAwareFail("Totalling not working in " + getClass().toString());
166         }
167     }
168 
169     /**
170      * Test action column placement in table layout collections
171      */
172     protected void testActionColumnPlacement() throws Exception {
173         //Lack of proper locators its not possible to uniquely identify/locate this elements without use of ID's.
174         //This restricts us to use the XPath to locate elements from the dome.
175         //This test is prone to throw error in case of any changes in the dom Html graph.
176         waitAndClickByLinkText("Column Sequence");
177         Thread.sleep(2000);
178 
179         //jiraAwareWaitAndClick("css=div.jGrowl-close");
180         // check if actions column RIGHT by default
181         //assertTrue(isElementPresent("//div[@id='ConfigurationTestView-collection1']//tr[2]/td[6]//button[contains(.,\"delete\")]"));
182         for (int second = 0;; second++) {
183             if (second >= waitSeconds)
184                 jiraAwareFail(TIMEOUT_MESSAGE);
185             try {
186                 if (isElementPresentByXpath("//tr[2]/td[6]/div/fieldset/div/button"))
187                     break;
188             } catch (Exception e) {}
189             Thread.sleep(1000);
190         }
191         assertTrue(getClass().toString(), isElementPresentByXpath("//tr[2]/td[6]/div/fieldset/div/button"));
192 
193         // check if actions column is LEFT
194         //assertTrue(isElementPresent("//div[@id='ConfigurationTestView-collection2']//tr[2]/td[1]//button[contains(.,\"delete\")]"));
195         for (int second = 0;; second++) {
196             if (second >= waitSeconds)
197                 jiraAwareFail(TIMEOUT_MESSAGE);
198             try {
199                 if (isElementPresentByXpath("//tr/td/div/fieldset/div/button[@id='Collections-ColumnSequence-TableLeft_add']"))
200                     break;
201             } catch (Exception e) {}
202             Thread.sleep(1000);
203         }
204         assertTrue(getClass().toString(), isElementPresentByXpath("//tr/td/div/fieldset/div/button[@id='Collections-ColumnSequence-TableLeft_add']"));
205 
206         // check if actions column is 3rd in a sub collection
207         //assertTrue(isElementPresent("//div[@id='ConfigurationTestView-subCollection2_line0']//tr[2]/td[3]//button[contains(.,\"delete\")]"));
208         for (int second = 0;; second++) {
209             if (second >= waitSeconds)
210                 jiraAwareFail(TIMEOUT_MESSAGE);
211             try {
212                 if (isElementPresentByXpath("//tr[2]/td[3]/div/fieldset/div/button"))
213                     break;
214             } catch (Exception e) {}
215             Thread.sleep(1000);
216         }
217         assertTrue(getClass().toString(), isElementPresentByXpath("//tr[2]/td[3]/div/fieldset/div/button"));
218     }
219 
220     protected void testAddViaLightbox() throws Exception {
221         waitAndClickByLinkText("Add Via Lightbox");
222         Integer preValue= Integer.parseInt(driver.findElement(By.xpath("//fieldset/div/div[2]/p")).getText());
223         waitAndClickButtonByText("Add Line");
224         Thread.sleep(3000);
225         waitAndTypeByXpath("//form/section/table/tbody/tr/td/div/input", "1");
226         waitAndTypeByXpath("//form/section/table/tbody/tr[2]/td/div/input", "1");
227         waitAndTypeByXpath("//form/section/table/tbody/tr[3]/td/div/input", "1");
228         waitAndTypeByXpath("//form/section/table/tbody/tr[4]/td/div/input", "1");
229         waitAndClickByXpath("//button[@id='Collections-AddViaLightbox-TableTop_add']");
230         Thread.sleep(3000);
231         Integer postValue= Integer.parseInt(driver.findElement(By.xpath("//fieldset/div/div[2]/p")).getText());
232         if(preValue>postValue) {
233             jiraAwareFail("Totalling not working in " + getClass().toString());
234         }
235     }
236 
237     protected void testColumnSequence() throws Exception {
238         waitAndClickByLinkText("Column Sequence");
239         acceptAlertIfPresent();
240         Thread.sleep(3000);
241         waitAndTypeByName("newCollectionLines['list1'].field1", "1");
242         waitAndTypeByName("newCollectionLines['list1'].field2", "1");
243         waitAndTypeByName("newCollectionLines['list1'].field3", "1");
244         waitAndTypeByName("newCollectionLines['list1'].field4", "1");
245         waitAndClick(By.id("Collections-ColumnSequence-TableDefault_add"));
246         Thread.sleep(3000);
247 
248         //Check if row has been added really or not
249         testIfRowHasBeenAdded();
250 
251         //Check for the added if delete is present or not
252         assertTrue(getClass().toString(), isElementPresentByXpath("//div[@id='Collections-ColumnSequence-TableDefault_disclosureContent']/div[@class='dataTables_wrapper']/table/tbody/tr[2]/td[6]/div/fieldset/div/button"));
253     }
254 
255     protected void testSequencerow() throws Exception {
256         waitAndClickByLinkText("Save Row");
257         acceptAlertIfPresent();
258         Thread.sleep(3000);
259         waitAndTypeByName("newCollectionLines['list1'].field1", "1");
260         waitAndTypeByName("newCollectionLines['list1'].field2", "1");
261         waitAndTypeByName("newCollectionLines['list1'].field3", "1");
262         waitAndTypeByName("newCollectionLines['list1'].field4", "1");
263         waitAndClickByXpath("//button[contains(.,'add')]");
264         Thread.sleep(3000);
265 
266         //Check if row has been added really or not
267         testIfRowHasBeenAdded();
268 
269         //Check for the added if delete is present or not
270         assertTrue(getClass().toString(), isElementPresentByXpath("//div[@id='Collections-SaveRow-Table_disclosureContent']/div[@class='dataTables_wrapper']/table/tbody/tr[2]/td[6]/div/fieldset/div/button"));
271         //        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']"));
272     }
273 
274     protected void testIfRowHasBeenAdded() throws Exception {
275         //Check if row has been added really or not
276         assertEquals("", waitAndGetAttributeByName("newCollectionLines['list1'].field1", "value"));
277         assertEquals("", waitAndGetAttributeByName("newCollectionLines['list1'].field2", "value"));
278         assertEquals("", waitAndGetAttributeByName("newCollectionLines['list1'].field3", "value"));
279         assertEquals("", waitAndGetAttributeByName("newCollectionLines['list1'].field4", "value"));
280         assertEquals("1", waitAndGetAttributeByName("list1[0].field1", "value"));
281         assertEquals("1", waitAndGetAttributeByName("list1[0].field2", "value"));
282         assertEquals("1", waitAndGetAttributeByName("list1[0].field3", "value"));
283         assertEquals("1", waitAndGetAttributeByName("list1[0].field4", "value"));
284     }
285 }