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.elements.action;
17  
18  import com.thoughtworks.selenium.SeleneseTestBase;
19  import edu.samplu.common.Failable;
20  import edu.samplu.common.ITUtil;
21  import edu.samplu.common.WebDriverLegacyITBase;
22  import org.openqa.selenium.By;
23  
24  import static org.junit.Assert.assertTrue;
25  
26  /**
27   * @author Kuali Rice Team (rice.collab@kuali.org)
28   */
29  public abstract class DemoLibraryElementsActionSmokeTestBase extends WebDriverLegacyITBase {
30  
31      /**
32       * /kr-krad/kradsampleapp?viewId=Demo-Action-View&methodToCall=start
33       */
34      public static final String BOOKMARK_URL = "/kr-krad/kradsampleapp?viewId=Demo-Action-View&methodToCall=start";
35  
36      @Override
37      public String getTestUrl() {
38          return ITUtil.KRAD_PORTAL;
39      }
40  
41      protected void navigation() throws Exception {
42          waitAndClickById("Demo-LibraryLink", "");
43          waitAndClickByLinkText("Elements");
44          waitAndClickByLinkText("Action");
45      }
46  
47      protected void testActionDefault() throws Exception {
48          waitForElementPresentByClassName("uif-headerText-span");
49          assertTextPresent("Default");
50          SeleneseTestBase.assertTrue(getTextByClassName("uif-instructionalMessage").contains(
51                  "Action with action script"));
52          assertElementPresentByLinkText("Action Link");
53      }
54  
55      protected void testActionPresubmit() throws Exception {
56          waitAndClickByLinkText("Presubmit");
57          waitForElementPresentByClassName("uif-headerText-span");
58          assertTextPresent("Presubmit");
59          assertTextPresent("ActionLinkField with presubmit script");
60          assertElementPresentByLinkText("Pre submit returning true Link");
61          assertElementPresentByLinkText("Pre submit returning false Link");
62  
63          waitAndClickByLinkText("Pre submit returning true Link");
64          assertTrue(driver.switchTo().alert().getText().contains("Pre submit call was invoked, returning true"));
65          driver.switchTo().alert().accept();
66  
67          waitAndClickByLinkText("Pre submit returning false Link");
68          assertTrue(driver.switchTo().alert().getText().contains("Pre submit call was invoked, returning false"));
69          driver.switchTo().alert().accept();
70      }
71  
72      protected void testActionSuccessCallback() throws Exception {
73          waitAndClickByLinkText("Success Callback");
74          waitForElementPresentByClassName("uif-headerText-span");
75          assertTextPresent("Action Field with a success callback script");
76          assertElementPresentByLinkText("Action Link success callback");
77  
78          waitAndClickByLinkText("Action Link success 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          driver.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          assertTextNotPresent("InputField 1: Required"); // no validation error yet
91  
92          waitAndClickByLinkText("Action Link with clientside validation");
93          assertTextPresent("InputField 1: Required"); // now we have a validation error
94  
95          waitAndTypeByName("inputField1", "some text");
96          waitAndClickByLinkText("Action Link with clientside validation");
97          assertTextNotPresent("InputField 1: Required"); // now the error goes away
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 
106         driver.findElement(By.partialLinkText("Action Link with left image")).findElement(By.className(
107                 "leftActionImage"));
108         driver.findElement(By.partialLinkText("Action Link with right image")).findElement(By.className(
109                 "rightActionImage"));
110     }
111 
112     protected void testActionButton() throws Exception {
113         waitAndClickByLinkText("Buttons");
114         waitForElementPresentByClassName("prettyprint");
115         assertTextPresent("Buttons");
116         assertTextPresent("Action Field buttons");
117 
118         waitAndClickButtonByText("button");
119         assertTrue(driver.switchTo().alert().getText().contains("You clicked a button"));
120         driver.switchTo().alert().accept();
121 
122         waitAndClickButtonByText("Image BOTTOM");
123         assertTrue(driver.switchTo().alert().getText().contains("You clicked a button"));
124         driver.switchTo().alert().accept();
125 
126         waitAndClickById("ST-DemoButtonImageTop");
127         assertTrue(driver.switchTo().alert().getText().contains("You clicked a button"));
128         driver.switchTo().alert().accept();
129 
130         driver.findElement(By.xpath("//span[contains(text(),'Image LEFT')]"));
131         driver.findElement(By.id("ST-DemoButtonImageLeft")).click();
132         assertTrue(driver.switchTo().alert().getText().contains("You clicked a button"));
133         driver.switchTo().alert().accept();
134 
135         driver.findElement(By.id("ST-DemoButtonImageRight")).click();
136         assertTrue(driver.switchTo().alert().getText().contains("You clicked a button"));
137         driver.switchTo().alert().accept();
138 
139         driver.findElement(By.id("ST-DemoButtonImageOnly")).click();
140         assertTrue(driver.switchTo().alert().getText().contains("You clicked a button"));
141         driver.switchTo().alert().accept();
142 
143         driver.findElement(By.xpath("//button[contains(text(),'Disabled Button') and @disabled]/preceding-sibling::button/img"));
144         driver.findElement(By.xpath("//button/img[contains(@alt,'Image Only button')]"));
145 
146         driver.findElement(By.xpath("//button[contains(text(),'Disabled Button') and @disabled]"));
147     }
148 
149     private void testAllActionTabs() throws Exception {
150         testActionDefault();
151         testActionPresubmit();
152         testActionSuccessCallback();
153         testActionValidation();
154         testActionImages();
155         testActionButton();
156     }
157 
158     public void testActionButtonBookmark(Failable failable) throws Exception {
159         testActionButton();
160         passed();
161     }
162 
163     public void testActionButtonNav(Failable failable) throws Exception {
164         navigation();
165         testActionButton();
166         passed();
167     }
168 
169     public void testActionBookmark(Failable failable) throws Exception {
170         testAllActionTabs();
171         passed();
172     }
173 
174     public void testActionNav(Failable failable) throws Exception {
175         navigation();
176         testAllActionTabs();
177         passed();
178     }
179 
180 }