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