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.samplu.krad.demo.uif.library.elements.action; 017 018 import com.thoughtworks.selenium.SeleneseTestBase; 019 import edu.samplu.common.Failable; 020 import edu.samplu.common.ITUtil; 021 import edu.samplu.common.WebDriverLegacyITBase; 022 import org.openqa.selenium.By; 023 024 import static org.junit.Assert.assertTrue; 025 026 /** 027 * @author Kuali Rice Team (rice.collab@kuali.org) 028 */ 029 public abstract class DemoLibraryElementsActionSmokeTestBase extends WebDriverLegacyITBase { 030 031 /** 032 * /kr-krad/kradsampleapp?viewId=Demo-Action-View&methodToCall=start 033 */ 034 public static final String BOOKMARK_URL = "/kr-krad/kradsampleapp?viewId=Demo-Action-View&methodToCall=start"; 035 036 @Override 037 public String getTestUrl() { 038 return ITUtil.KRAD_PORTAL; 039 } 040 041 protected void navigation() throws Exception { 042 waitAndClickById("Demo-LibraryLink", ""); 043 waitAndClickByLinkText("Elements"); 044 waitAndClickByLinkText("Action"); 045 } 046 047 protected void testActionDefault() throws Exception { 048 waitForElementPresentByClassName("uif-headerText-span"); 049 assertTextPresent("Default"); 050 SeleneseTestBase.assertTrue(getTextByClassName("uif-instructionalMessage").contains( 051 "Action with action script")); 052 assertElementPresentByLinkText("Action Link"); 053 } 054 055 protected void testActionPresubmit() throws Exception { 056 waitAndClickByLinkText("Presubmit"); 057 waitForElementPresentByClassName("uif-headerText-span"); 058 assertTextPresent("Presubmit"); 059 assertTextPresent("ActionLinkField with presubmit script"); 060 assertElementPresentByLinkText("Pre submit returning true Link"); 061 assertElementPresentByLinkText("Pre submit returning false Link"); 062 063 waitAndClickByLinkText("Pre submit returning true Link"); 064 assertTrue(driver.switchTo().alert().getText().contains("Pre submit call was invoked, returning true")); 065 driver.switchTo().alert().accept(); 066 067 waitAndClickByLinkText("Pre submit returning false Link"); 068 assertTrue(driver.switchTo().alert().getText().contains("Pre submit call was invoked, returning false")); 069 driver.switchTo().alert().accept(); 070 } 071 072 protected void testActionSuccessCallback() throws Exception { 073 waitAndClickByLinkText("Success Callback"); 074 waitForElementPresentByClassName("uif-headerText-span"); 075 assertTextPresent("Action Field with a success callback script"); 076 assertElementPresentByLinkText("Action Link success callback"); 077 078 waitAndClickByLinkText("Action Link success callback"); 079 assertTrue(driver.switchTo().alert().getText().contains("Refresh called successfully")); 080 driver.switchTo().alert().accept(); 081 } 082 083 protected void testActionValidation() throws Exception { 084 waitForElementPresentByClassName("uif-page"); // make sure the page is there before we use the driver 085 driver.findElement(By.className("uif-page")).findElement(By.linkText("Validation")).click(); 086 087 waitForElementPresentByClassName("uif-headerText-span"); 088 assertTextPresent("Action Field with client side validation"); 089 assertTextPresent("InputField 1"); 090 assertTextNotPresent("InputField 1: Required"); // no validation error yet 091 092 waitAndClickByLinkText("Action Link with clientside validation"); 093 assertTextPresent("InputField 1: Required"); // now we have a validation error 094 095 waitAndTypeByName("inputField1", "some text"); 096 waitAndClickByLinkText("Action Link with clientside validation"); 097 assertTextNotPresent("InputField 1: Required"); // now the error goes away 098 } 099 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 }