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