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.demo.uif.library;
17  
18  import com.thoughtworks.selenium.SeleneseTestBase;
19  import org.junit.Test;
20  import org.openqa.selenium.By;
21  
22  import static org.junit.Assert.assertTrue;
23  
24  /**
25   * @author Kuali Rice Team (rice.collab@kuali.org)
26   */
27  public class DemoLibraryElementsActionSmokeTest extends DemoLibraryBase {
28  
29      /**
30       * /kr-krad/kradsampleapp?viewId=Demo-Action-View&methodToCall=start
31       */
32      public static final String BOOKMARK_URL = "/kr-krad/kradsampleapp?viewId=Demo-Action-View&methodToCall=start";
33  
34      @Override
35      public String getBookmarkUrl() {
36          return BOOKMARK_URL;
37      }
38  
39      @Override
40      protected void navigate() throws Exception {
41          waitAndClickById("Demo-LibraryLink", "");
42          waitAndClickByLinkText("Elements");
43          waitAndClickByLinkText("Action");
44      }
45  
46      protected void testActionDefault() throws Exception {
47          waitForElementPresentByClassName("uif-headerText-span");
48          assertTextPresent("Default");
49          SeleneseTestBase.assertTrue(getTextByClassName("uif-instructionalMessage").contains(
50                  "Action with action script"));
51          assertElementPresentByLinkText("Action Link");
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          waitAndClickByLinkText("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          assertTrue(driver.switchTo().alert().getText().contains("Refresh called successfully"));
79          driver.switchTo().alert().accept();
80      }
81  
82      protected void testActionValidation() throws Exception {
83          waitForElementPresentByClassName("uif-page"); // make sure the page is there before we use the driver
84          driver.findElement(By.className("uif-page")).findElement(By.linkText("Validation")).click();
85  
86          waitForElementPresentByClassName("uif-headerText-span");
87          assertTextPresent("Action Field with client side validation");
88          assertTextPresent("InputField 1");
89          assertIsNotVisibleByXpath("//a[contains(text(),'Required')]");
90  
91          waitAndClickByLinkText("Action Link with clientside validation");
92          assertIsVisibleByXpath("//a[contains(text(),'Required')]", "");
93  
94          waitAndTypeByName("inputField1", "some text");
95          waitAndClickByLinkText("Action Link with clientside validation");
96          assertIsNotVisibleByXpath("//a[contains(text(),'Required')]");
97      }
98  
99      protected void testActionImages() throws Exception {
100         waitAndClickByLinkText("Images");
101         waitForElementPresentByClassName("uif-headerText-span");
102         assertTextPresent("Images");
103         assertTextPresent("Action Field with images");
104 
105         driver.findElement(By.partialLinkText("Action Link with left image")).findElement(By.className(
106                 "leftActionImage"));
107         driver.findElement(By.partialLinkText("Action Link with right image")).findElement(By.className(
108                 "rightActionImage"));
109     }
110 
111     protected void testActionButton() throws Exception {
112         waitAndClickByLinkText("Buttons");
113         waitForElementPresentByClassName("prettyprint");
114         assertTextPresent("Buttons");
115         assertTextPresent("Action Field buttons");
116 
117         waitAndClickButtonByText("button");
118         assertTrue(driver.switchTo().alert().getText().contains("You clicked a button"));
119         driver.switchTo().alert().accept();
120 
121         waitAndClickButtonByText("Image BOTTOM");
122         assertTrue(driver.switchTo().alert().getText().contains("You clicked a button"));
123         driver.switchTo().alert().accept();
124 
125         waitAndClickById("ST-DemoButtonImageTop");
126         assertTrue(driver.switchTo().alert().getText().contains("You clicked a button"));
127         driver.switchTo().alert().accept();
128 
129         driver.findElement(By.xpath("//span[contains(text(),'Image LEFT')]"));
130         driver.findElement(By.id("ST-DemoButtonImageLeft")).click();
131         assertTrue(driver.switchTo().alert().getText().contains("You clicked a button"));
132         driver.switchTo().alert().accept();
133 
134         driver.findElement(By.id("ST-DemoButtonImageRight")).click();
135         assertTrue(driver.switchTo().alert().getText().contains("You clicked a button"));
136         driver.switchTo().alert().accept();
137 
138         driver.findElement(By.id("ST-DemoButtonImageOnly")).click();
139         assertTrue(driver.switchTo().alert().getText().contains("You clicked a button"));
140         driver.switchTo().alert().accept();
141 
142         driver.findElement(By.xpath("//button[contains(text(),'Disabled Button') and @disabled]/preceding-sibling::button/img"));
143         driver.findElement(By.xpath("//button/img[contains(@alt,'Image Only button')]"));
144 
145         driver.findElement(By.xpath("//button[contains(text(),'Disabled Button') and @disabled]"));
146     }
147 
148     private void testAllActionTabs() throws Exception {
149         testActionDefault();
150         testActionPresubmit();
151         testActionSuccessCallback();
152         testActionValidation();
153         testActionImages();
154         testActionButton();
155     }
156 
157     @Test
158     public void testActionButtonBookmark() throws Exception {
159         testActionButton();
160         passed();
161     }
162 
163     @Test
164     public void testActionButtonNav() throws Exception {
165         testActionButton();
166         passed();
167     }
168 
169     @Test
170     public void testActionBookmark() throws Exception {
171         testAllActionTabs();
172         passed();
173     }
174 
175     @Test
176     public void testActionNav() throws Exception {
177         testAllActionTabs();
178         passed();
179     }
180 }