View Javadoc
1   /**
2    * Copyright 2005-2016 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 org.kuali.rice.krad.demo.uif.library.elements;
17  
18  import org.junit.Test;
19  import org.kuali.rice.krad.demo.uif.library.LibraryBase;
20  import org.openqa.selenium.By;
21  
22  /**
23   * @author Kuali Rice Team (rice.collab@kuali.org)
24   */
25  public class LibraryElementsActionAft extends LibraryBase {
26  
27      /**
28       * /kr-krad/kradsampleapp?viewId=Demo-ActionView&methodToCall=start
29       */
30      public static final String BOOKMARK_URL = "/kr-krad/kradsampleapp?viewId=Demo-ActionView&methodToCall=start";
31  
32      @Override
33      public String getBookmarkUrl() {
34          return BOOKMARK_URL;
35      }
36  
37      @Override
38      protected void navigate() throws Exception {
39          waitAndClickLibraryLink();
40          waitAndClickByLinkText("Elements");
41          waitAndClickByLinkText("Action");
42      }
43  
44      protected void testActionDefault() throws Exception {
45          waitForElementPresentByClassName("uif-headerText-span");
46          assertTextPresent("Default");
47          assertTrue(getTextByClassName("uif-instructionalMessage").contains(
48                  "Action with action script"));
49          assertElementPresentByLinkText("Action Link");
50          waitAndClickByLinkText("Action Link");
51          acceptAlert();
52      }
53  
54      protected void testActionPresubmit() throws Exception {
55          waitAndClickByLinkText("Presubmit");
56          waitForElementPresentByClassName("uif-headerText-span");
57          assertTextPresent("Presubmit");
58          assertTextPresent("ActionLinkField with presubmit script");
59          assertElementPresentByLinkText("Pre submit returning true Link");
60          assertElementPresentByLinkText("Pre submit returning false Link");
61  
62          waitAndClickByLinkText("Pre submit returning true Link");
63          assertTrue(driver.switchTo().alert().getText().contains("Pre submit call was invoked, returning true"));
64          driver.switchTo().alert().accept();
65  
66          waitAndClickLinkContainingText("Pre submit returning false Link");
67          assertTrue(driver.switchTo().alert().getText().contains("Pre submit call was invoked, returning false"));
68          driver.switchTo().alert().accept();
69      }
70  
71      protected void testActionSuccessCallback() throws Exception {
72          waitAndClickByLinkText("Success Callback");
73          waitForElementPresentByClassName("uif-headerText-span");
74          assertTextPresent("Action Field with a success callback script");
75          assertElementPresentByLinkText("Action Link success callback");
76  
77          waitAndClickByLinkText("Action Link success callback");
78          Thread.sleep(1500); // give the alert time to get triggered via callback
79          assertTrue(driver.switchTo().alert().getText().contains("Refresh called successfully"));
80          driver.switchTo().alert().accept();
81      }
82  
83      protected void testActionValidation() throws Exception {
84          waitForElementPresentByClassName("uif-page"); // make sure the page is there before we use the driver
85          findElement(By.className("uif-page")).findElement(By.linkText("Validation")).click();
86  
87          waitForElementPresentByClassName("uif-headerText-span");
88          assertTextPresent("Action Field with client side validation");
89          assertTextPresent("InputField 1");
90          assertIsNotVisibleByXpath("//a[contains(text(),'Required')]");
91  
92          waitAndClickByLinkText("Action Field with client side required validation");
93          assertIsVisibleByXpath("//a[contains(text(),'Required')]", "");
94  
95          waitAndTypeByName("inputField1", "some text");
96          waitAndClickByLinkText("Action Field with client side required validation");
97          assertIsNotVisibleByXpath("//a[contains(text(),'Required')]");
98      }
99  
100     protected void testActionImages() throws Exception {
101         waitAndClickByLinkText("Images");
102         waitForElementPresentByClassName("uif-headerText-span");
103         assertTextPresent("Images");
104         assertTextPresent("Action Field with images");
105         findElement(By.partialLinkText("Action Link with left image")).findElement(By.className("leftActionImage"));
106         findElement(By.partialLinkText("Action Link with right image")).findElement(By.className("rightActionImage"));
107         waitAndClickByLinkText("Action Link with left image");
108         acceptAlert();
109         waitAndClickByLinkText("Action Link with right image");
110         acceptAlert();
111     }
112 
113     protected void testActionButton() throws Exception {
114         waitAndClickByLinkText("Buttons");
115         waitForElementPresentByClassName("prettyprint");
116         assertTextPresent("Buttons");
117         assertTextPresent("Action Field buttons");
118 
119         waitAndClickButtonByText("button");
120         assertTrue(driver.switchTo().alert().getText().contains("You clicked a button"));
121         driver.switchTo().alert().accept();
122 
123         waitAndClickButtonByText("Image BOTTOM");
124         assertTrue(driver.switchTo().alert().getText().contains("You clicked a button"));
125         driver.switchTo().alert().accept();
126 
127         waitAndClickById("ST-DemoButtonImageTop");
128         assertTrue(driver.switchTo().alert().getText().contains("You clicked a button"));
129         driver.switchTo().alert().accept();
130 
131         findElement(By.xpath("//span[contains(text(),'Image LEFT')]"));
132         findElement(By.id("ST-DemoButtonImageLeft")).click();
133         assertTrue(driver.switchTo().alert().getText().contains("You clicked a button"));
134         driver.switchTo().alert().accept();
135 
136         findElement(By.id("ST-DemoButtonImageRight")).click();
137         assertTrue(driver.switchTo().alert().getText().contains("You clicked a button"));
138         driver.switchTo().alert().accept();
139 
140         findElement(By.id("ST-DemoButtonImageOnly")).click();
141         assertTrue(driver.switchTo().alert().getText().contains("You clicked a button"));
142         driver.switchTo().alert().accept();
143 
144         findElement(By.xpath("//button[contains(text(),'Disabled Button') and @disabled]/preceding-sibling::button/img"));
145         findElement(By.xpath("//button/img[contains(@alt,'Image Only button')]"));
146 
147         findElement(By.xpath("//button[contains(text(),'Disabled Button') and @disabled]"));
148     }
149     
150     protected void testActionStyleVarities() throws Exception {
151     	waitAndClickByLinkText("Style Varieties");
152     	
153     	//Assertion of Large Buttons
154     	waitForElementPresentByXpath("//button[@class='btn btn-primary btn-lg uif-action uif-boxLayoutVerticalItem pull-left clearfix']");
155     	waitForElementPresentByXpath("//button[@class='btn btn-primary btn-lg uif-action uif-boxLayoutVerticalItem pull-left clearfix disabled' and @disabled]");
156     	waitForElementPresentByXpath("//button[@class='btn btn-default btn-lg uif-action uif-boxLayoutVerticalItem pull-left clearfix']");
157     	waitForElementPresentByXpath("//button[@class='btn btn-default btn-lg uif-action uif-boxLayoutVerticalItem pull-left clearfix disabled' and @disabled]");
158     	
159     	//Assertion of Small Buttons
160     	waitForElementPresentByXpath("//button[@class='btn btn-primary btn-sm uif-action uif-boxLayoutVerticalItem pull-left clearfix']");
161     	waitForElementPresentByXpath("//button[@class='btn btn-primary btn-sm uif-action uif-boxLayoutVerticalItem pull-left clearfix disabled' and @disabled]");
162     	waitForElementPresentByXpath("//button[@class='btn btn-default btn-sm uif-action uif-boxLayoutVerticalItem pull-left clearfix']");
163     	waitForElementPresentByXpath("//button[@class='btn btn-default btn-sm uif-action uif-boxLayoutVerticalItem pull-left clearfix disabled' and @disabled]");
164     	
165     	//Assertion of Mini Buttons
166     	waitForElementPresentByXpath("//button[@class='btn btn-primary btn-xs uif-action uif-boxLayoutVerticalItem pull-left clearfix']");
167     	waitForElementPresentByXpath("//button[@class='btn btn-primary btn-xs uif-action uif-boxLayoutVerticalItem pull-left clearfix disabled' and @disabled]");
168     	waitForElementPresentByXpath("//button[@class='btn btn-default btn-xs uif-action uif-boxLayoutVerticalItem pull-left clearfix']");
169     	waitForElementPresentByXpath("//button[@class='btn btn-default btn-xs uif-action uif-boxLayoutVerticalItem pull-left clearfix disabled' and @disabled]");
170     	
171     	//ICON Examples
172     	waitForElementPresentByXpath("//button[@class='btn btn-primary btn-lg uif-action uif-boxLayoutVerticalItem pull-left clearfix']/span[@class='icon-ok']");
173     	waitForElementPresentByXpath("//button[@class='btn btn-primary uif-action uif-boxLayoutVerticalItem pull-left clearfix']/span[@class='icon-ok']");
174     	waitForElementPresentByXpath("//button[@class='btn btn-primary btn-sm uif-action uif-boxLayoutVerticalItem pull-left clearfix']/span[@class='icon-ok']");
175     	waitForElementPresentByXpath("//button[@class='btn btn-primary btn-xs uif-action uif-boxLayoutVerticalItem pull-left clearfix']/span[@class='icon-ok']");
176     	waitForElementPresentByXpath("//button[@class='btn btn-primary btn-lg uif-action uif-boxLayoutVerticalItem pull-left clearfix icon-ok']");
177     	waitForElementPresentByXpath("//button[@class='btn btn-primary uif-action uif-boxLayoutVerticalItem pull-left clearfix icon-ok']");
178     	waitForElementPresentByXpath("//button[@class='btn btn-primary btn-sm uif-action uif-boxLayoutVerticalItem pull-left clearfix icon-ok']");
179     	waitForElementPresentByXpath("//button[@class='btn btn-primary btn-xs uif-action uif-boxLayoutVerticalItem pull-left clearfix icon-ok']");
180     }
181 
182     protected void testActionIcons() throws Exception {
183     	waitAndClickByXpath("//a[@href='#Demo-Action-Example6_tabPanel' and contains(text(),'Icons')]");
184     	waitForElementPresentByXpath("//button[@class='btn btn-primary uif-action uif-boxLayoutVerticalItem pull-left clearfix']/span[@class='icon-office']");
185     	waitForElementPresentByXpath("//button[@class='btn btn-primary uif-action uif-boxLayoutVerticalItem pull-left clearfix icon-office']");
186     }
187     
188     private void testAllActionTabs() throws Exception {
189 //        testActionDefault();
190 //        testActionSuccessCallback();
191 //        testActionValidation();
192 //        testActionImages();
193 //        testActionButton();
194 //        testActionStyleVarities();
195 //        testActionIcons();
196         testActionPresubmit(); // last because it is failing https://jira.kuali.org/browse/KULRICE-10961 Library Action Presubmit Pre submit returning true Link redirects to Library Action Default
197     }
198 
199     @Test
200     public void testActionBookmark() throws Exception {
201         testAllActionTabs();
202         passed();
203     }
204 
205     @Test
206     public void testActionNav() throws Exception {
207         testAllActionTabs();
208         passed();
209     }
210 }