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 org.kuali.rice.krad.demo.uif.library.elements;
17  
18  import org.junit.Test;
19  import org.kuali.rice.krad.demo.uif.library.DemoLibraryBase;
20  import org.openqa.selenium.By;
21  
22  /**
23   * @author Kuali Rice Team (rice.collab@kuali.org)
24   */
25  public class DemoElementsActionAft extends DemoLibraryBase {
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          waitAndClickById("Demo-LibraryLink", "");
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      }
51  
52      protected void testActionPresubmit() throws Exception {
53          waitAndClickByLinkText("Presubmit");
54          waitForElementPresentByClassName("uif-headerText-span");
55          assertTextPresent("Presubmit");
56          assertTextPresent("ActionLinkField with presubmit script");
57          assertElementPresentByLinkText("Pre submit returning true Link");
58          assertElementPresentByLinkText("Pre submit returning false Link");
59  
60          waitAndClickByLinkText("Pre submit returning true Link");
61          assertTrue(driver.switchTo().alert().getText().contains("Pre submit call was invoked, returning true"));
62          driver.switchTo().alert().accept();
63  
64          waitAndClickByLinkText("Pre submit returning false Link");
65          assertTrue(driver.switchTo().alert().getText().contains("Pre submit call was invoked, returning false"));
66          driver.switchTo().alert().accept();
67      }
68  
69      protected void testActionSuccessCallback() throws Exception {
70          waitAndClickByLinkText("Success Callback");
71          waitForElementPresentByClassName("uif-headerText-span");
72          assertTextPresent("Action Field with a success callback script");
73          assertElementPresentByLinkText("Action Link success callback");
74  
75          waitAndClickByLinkText("Action Link success callback");
76          Thread.sleep(1500); // give the alert time to get triggered via callback
77          assertTrue(driver.switchTo().alert().getText().contains("Refresh called successfully"));
78          driver.switchTo().alert().accept();
79      }
80  
81      protected void testActionValidation() throws Exception {
82          waitForElementPresentByClassName("uif-page"); // make sure the page is there before we use the driver
83          findElement(By.className("uif-page")).findElement(By.linkText("Validation")).click();
84  
85          waitForElementPresentByClassName("uif-headerText-span");
86          assertTextPresent("Action Field with client side validation");
87          assertTextPresent("InputField 1");
88          assertIsNotVisibleByXpath("//a[contains(text(),'Required')]");
89  
90          waitAndClickByLinkText("Action Field with client side required validation");
91          assertIsVisibleByXpath("//a[contains(text(),'Required')]", "");
92  
93          waitAndTypeByName("inputField1", "some text");
94          waitAndClickByLinkText("Action Field with client side required validation");
95          assertIsNotVisibleByXpath("//a[contains(text(),'Required')]");
96      }
97  
98      protected void testActionImages() throws Exception {
99          waitAndClickByLinkText("Images");
100         waitForElementPresentByClassName("uif-headerText-span");
101         assertTextPresent("Images");
102         assertTextPresent("Action Field with images");
103 
104         findElement(By.partialLinkText("Action Link with left image")).findElement(By.className("leftActionImage"));
105         findElement(By.partialLinkText("Action Link with right image")).findElement(By.className("rightActionImage"));
106     }
107 
108     protected void testActionButton() throws Exception {
109         waitAndClickByLinkText("Buttons");
110         waitForElementPresentByClassName("prettyprint");
111         assertTextPresent("Buttons");
112         assertTextPresent("Action Field buttons");
113 
114         waitAndClickButtonByText("button");
115         assertTrue(driver.switchTo().alert().getText().contains("You clicked a button"));
116         driver.switchTo().alert().accept();
117 
118         waitAndClickButtonByText("Image BOTTOM");
119         assertTrue(driver.switchTo().alert().getText().contains("You clicked a button"));
120         driver.switchTo().alert().accept();
121 
122         waitAndClickById("ST-DemoButtonImageTop");
123         assertTrue(driver.switchTo().alert().getText().contains("You clicked a button"));
124         driver.switchTo().alert().accept();
125 
126         findElement(By.xpath("//span[contains(text(),'Image LEFT')]"));
127         findElement(By.id("ST-DemoButtonImageLeft")).click();
128         assertTrue(driver.switchTo().alert().getText().contains("You clicked a button"));
129         driver.switchTo().alert().accept();
130 
131         findElement(By.id("ST-DemoButtonImageRight")).click();
132         assertTrue(driver.switchTo().alert().getText().contains("You clicked a button"));
133         driver.switchTo().alert().accept();
134 
135         findElement(By.id("ST-DemoButtonImageOnly")).click();
136         assertTrue(driver.switchTo().alert().getText().contains("You clicked a button"));
137         driver.switchTo().alert().accept();
138 
139         findElement(By.xpath("//button[contains(text(),'Disabled Button') and @disabled]/preceding-sibling::button/img"));
140         findElement(By.xpath("//button/img[contains(@alt,'Image Only button')]"));
141 
142         findElement(By.xpath("//button[contains(text(),'Disabled Button') and @disabled]"));
143     }
144 
145     private void testAllActionTabs() throws Exception {
146         testActionDefault();
147         testActionSuccessCallback();
148         testActionValidation();
149         testActionImages();
150         testActionButton();
151         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
152     }
153 
154     @Test
155     public void testActionBookmark() throws Exception {
156         testAllActionTabs();
157         passed();
158     }
159 
160     @Test
161     public void testActionNav() throws Exception {
162         testAllActionTabs();
163         passed();
164     }
165 }