001    /*
002     * Copyright 2005-2013 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package edu.sampleu.krad.configview;
017    
018    import org.junit.Test;
019    import org.kuali.rice.testtools.selenium.WebDriverLegacyITBase;
020    import org.openqa.selenium.By;
021    
022    /**
023     * @author Kuali Rice Team (rice.collab@kuali.org)
024     */
025    public class CollectionsAft extends WebDriverLegacyITBase {
026    
027        /**
028         * /kr-krad/uicomponents?viewId=ConfigurationTestView-Collections&methodToCall=start
029         */
030        public static final String BOOKMARK_URL = "/kr-krad/uicomponents?viewId=ConfigurationTestView-Collections&methodToCall=start";
031    
032        /**
033         * (//a[contains(text(),'Collections Configuration Test View')])[2]
034         */
035        public static final String TEXT_COLLECTIONS_CONFIGURATION_TEST_VIEW_XPATH =
036                "(//a[contains(text(),'Collections Configuration Test View')])[1]";
037    
038        /**
039         * Kuali :: Collection Test View
040         */
041        public static final String KUALI_COLLECTION_WINDOW_TITLE = "Kuali :: Collection Test View";
042    
043        @Override
044        protected String getBookmarkUrl() {
045            return BOOKMARK_URL;
046        }
047    
048        protected void navigate() throws Exception {
049            waitAndClickKRAD();
050            waitAndClickByXpath(TEXT_COLLECTIONS_CONFIGURATION_TEST_VIEW_XPATH);
051            switchToWindow(KUALI_COLLECTION_WINDOW_TITLE);
052        }
053    
054        protected void testCollections() throws Exception {
055            testActionColumnPlacement();
056            testAddViaLightbox();
057            testColumnSequence();
058            testSequencerow();
059            passed();
060        }
061    
062        @Test
063        public void testCollectionsBookmark() throws Exception {
064            testCollections();
065        }
066    
067        @Test
068        public void testCollectionsNav() throws Exception {
069            testCollections();
070        }
071    
072        @Test
073        public void testAddBlankLineBookmark() throws Exception {
074            testAddBlankLine();
075            passed();
076        }
077    
078        @Test
079        public void testAddBlankLineNav() throws Exception {
080            testAddBlankLine();
081            passed();
082        }
083    
084        @Test
085        public void testAddDeleteBookmark() throws Exception {
086            testAddRowOfText();
087            passed();
088        }
089    
090        @Test
091        public void testAddDeleteNav() throws Exception {
092            testAddRowOfText();
093            passed();
094        }
095    
096        @Test
097        public void testSumBookmark() throws Exception {
098            testSum();
099            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            assertEquals("Total: 419", driver.findElement(By.xpath("//fieldset/div/div[2]/div[2]")).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            assertEquals("Total: 465", driver.findElement(By.xpath("//fieldset/div/div[2]/div[2]")).getText());
164        }
165    
166        /**
167         * Test action column placement in table layout collections
168         */
169        protected void testActionColumnPlacement() throws Exception {
170            //Lack of proper locators its not possible to uniquely identify/locate this elements without use of ID's.
171            //This restricts us to use the XPath to locate elements from the dome.
172            //This test is prone to throw error in case of any changes in the dom Html graph.
173            waitAndClickByLinkText("Column Sequence");
174            Thread.sleep(2000);
175    
176            //jiraAwareWaitAndClick("css=div.jGrowl-close");
177            // check if actions column RIGHT by default
178            //assertTrue(isElementPresent("//div[@id='ConfigurationTestView-collection1']//tr[2]/td[6]//button[contains(.,\"delete\")]"));
179            for (int second = 0;; second++) {
180                if (second >= waitSeconds)
181                    jiraAwareFail(TIMEOUT_MESSAGE);
182                try {
183                    if (isElementPresentByXpath("//tr[2]/td[6]/div/fieldset/div/div[2]/button"))
184                        break;
185                } catch (Exception e) {}
186                Thread.sleep(1000);
187            }
188            assertTrue(isElementPresentByXpath("//tr[2]/td[6]/div/fieldset/div/div[2]/button"));
189    
190            // check if actions column is LEFT
191            //assertTrue(isElementPresent("//div[@id='ConfigurationTestView-collection2']//tr[2]/td[1]//button[contains(.,\"delete\")]"));
192            for (int second = 0;; second++) {
193                if (second >= waitSeconds)
194                    jiraAwareFail(TIMEOUT_MESSAGE);
195                try {
196                    if (isElementPresentByXpath("//div[2]/div[2]/div[2]/table/tbody/tr[2]/td/div/fieldset/div/div[2]/button"))
197                        break;
198                } catch (Exception e) {}
199                Thread.sleep(1000);
200            }
201            assertTrue(isElementPresentByXpath("//div[2]/div[2]/div[2]/table/tbody/tr[2]/td/div/fieldset/div/div[2]/button"));
202    
203            // check if actions column is 3rd in a sub collection
204            //assertTrue(isElementPresent("//div[@id='ConfigurationTestView-subCollection2_line0']//tr[2]/td[3]//button[contains(.,\"delete\")]"));
205            for (int second = 0;; second++) {
206                if (second >= waitSeconds)
207                    jiraAwareFail(TIMEOUT_MESSAGE);
208                try {
209                    if (isElementPresentByXpath("//tr[2]/td[3]/div/fieldset/div/div[2]/button"))
210                        break;
211                } catch (Exception e) {}
212                Thread.sleep(1000);
213            }
214            assertTrue(isElementPresentByXpath("//tr[2]/td[3]/div/fieldset/div/div[2]/button"));
215        }
216    
217        protected void testAddViaLightbox() throws Exception {
218            waitAndClickByLinkText("Add Via Lightbox");
219            assertEquals("Total: 419", driver.findElement(By.xpath("//fieldset/div/div[2]/div[2]")).getText());
220            waitAndClickByXpath("//button[contains(.,'Add Line')]");
221            Thread.sleep(3000);
222            waitAndTypeByXpath("//form/div/table/tbody/tr/td/div/input", "1");
223            waitAndTypeByXpath("//form/div/table/tbody/tr[2]/td/div/input", "1");
224            waitAndTypeByXpath("//form/div/table/tbody/tr[3]/td/div/input", "1");
225            waitAndTypeByXpath("//form/div/table/tbody/tr[4]/td/div/input", "1");
226            waitAndClickByXpath("//button[@id='Collections-AddViaLightbox-TableTop_add']");
227            Thread.sleep(3000);
228            assertEquals("Total: 420", driver.findElement(By.xpath("//fieldset/div/div[2]/div[2]")).getText());
229        }
230    
231        protected void testColumnSequence() throws Exception {
232            waitAndClickByLinkText("Column Sequence");
233            Thread.sleep(3000);
234            waitAndTypeByName("newCollectionLines['list1'].field1", "1");
235            waitAndTypeByName("newCollectionLines['list1'].field2", "1");
236            waitAndTypeByName("newCollectionLines['list1'].field3", "1");
237            waitAndTypeByName("newCollectionLines['list1'].field4", "1");
238            waitAndClick(By.id("Collections-ColumnSequence-TableDefault_add"));
239            Thread.sleep(3000);
240    
241            //Check if row has been added really or not
242            testIfRowHasBeenAdded();
243    
244            //Check for the added if delete is present or not
245            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"));
246        }
247    
248        protected void testSequencerow() throws Exception {
249            waitAndClickByLinkText("Save Row");
250            Thread.sleep(3000);
251            waitAndTypeByName("newCollectionLines['list1'].field1", "1");
252            waitAndTypeByName("newCollectionLines['list1'].field2", "1");
253            waitAndTypeByName("newCollectionLines['list1'].field3", "1");
254            waitAndTypeByName("newCollectionLines['list1'].field4", "1");
255            waitAndClickByXpath("//button[contains(.,'add')]");
256            Thread.sleep(3000);
257    
258            //Check if row has been added really or not
259            testIfRowHasBeenAdded();
260    
261            //Check for the added if delete is present or not
262            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"));
263            //        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']"));
264        }
265    
266        protected void testIfRowHasBeenAdded() throws Exception {
267            //Check if row has been added really or not
268            assertEquals("", waitAndGetAttributeByName("newCollectionLines['list1'].field1", "value"));
269            assertEquals("", waitAndGetAttributeByName("newCollectionLines['list1'].field2", "value"));
270            assertEquals("", waitAndGetAttributeByName("newCollectionLines['list1'].field3", "value"));
271            assertEquals("", waitAndGetAttributeByName("newCollectionLines['list1'].field4", "value"));
272            assertEquals("1", waitAndGetAttributeByName("list1[0].field1", "value"));
273            assertEquals("1", waitAndGetAttributeByName("list1[0].field2", "value"));
274            assertEquals("1", waitAndGetAttributeByName("list1[0].field3", "value"));
275            assertEquals("1", waitAndGetAttributeByName("list1[0].field4", "value"));
276        }
277    }