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.library.elements; 017 018 import static org.junit.Assert.assertTrue; 019 020 import org.junit.Test; 021 import org.openqa.selenium.By; 022 023 import com.thoughtworks.selenium.SeleneseTestBase; 024 025 import org.kuali.rice.testtools.selenium.Failable; 026 import org.kuali.rice.testtools.selenium.ITUtil; 027 import org.kuali.rice.testtools.selenium.SmokeTestBase; 028 import org.kuali.rice.testtools.selenium.WebDriverLegacyITBase; 029 030 /** 031 * @author Kuali Rice Team (rice.collab@kuali.org) 032 */ 033 public class DemoLibraryElementsActionSmokeTest extends SmokeTestBase { 034 035 /** 036 * /kr-krad/kradsampleapp?viewId=Demo-Action-View&methodToCall=start 037 */ 038 public static final String BOOKMARK_URL = "/kr-krad/kradsampleapp?viewId=Demo-Action-View&methodToCall=start"; 039 040 @Override 041 protected String getBookmarkUrl() { 042 return BOOKMARK_URL; 043 } 044 045 @Override 046 protected void navigate() throws Exception { 047 waitAndClickById("Demo-LibraryLink", ""); 048 waitAndClickByLinkText("Elements"); 049 waitAndClickByLinkText("Action"); 050 } 051 052 protected void testActionDefault() throws Exception { 053 waitForElementPresentByClassName("uif-headerText-span"); 054 assertTextPresent("Default"); 055 SeleneseTestBase.assertTrue(getTextByClassName("uif-instructionalMessage").contains( 056 "Action with action script")); 057 assertElementPresentByLinkText("Action Link"); 058 } 059 060 protected void testActionPresubmit() throws Exception { 061 waitAndClickByLinkText("Presubmit"); 062 waitForElementPresentByClassName("uif-headerText-span"); 063 assertTextPresent("Presubmit"); 064 assertTextPresent("ActionLinkField with presubmit script"); 065 assertElementPresentByLinkText("Pre submit returning true Link"); 066 assertElementPresentByLinkText("Pre submit returning false Link"); 067 068 waitAndClickByLinkText("Pre submit returning true Link"); 069 assertTrue(driver.switchTo().alert().getText().contains("Pre submit call was invoked, returning true")); 070 driver.switchTo().alert().accept(); 071 072 waitAndClickByLinkText("Pre submit returning false Link"); 073 assertTrue(driver.switchTo().alert().getText().contains("Pre submit call was invoked, returning false")); 074 driver.switchTo().alert().accept(); 075 } 076 077 protected void testActionSuccessCallback() throws Exception { 078 waitAndClickByLinkText("Success Callback"); 079 waitForElementPresentByClassName("uif-headerText-span"); 080 assertTextPresent("Action Field with a success callback script"); 081 assertElementPresentByLinkText("Action Link success callback"); 082 083 waitAndClickByLinkText("Action Link success callback"); 084 assertTrue(driver.switchTo().alert().getText().contains("Refresh called successfully")); 085 driver.switchTo().alert().accept(); 086 } 087 088 protected void testActionValidation() throws Exception { 089 waitForElementPresentByClassName("uif-page"); // make sure the page is there before we use the driver 090 driver.findElement(By.className("uif-page")).findElement(By.linkText("Validation")).click(); 091 092 waitForElementPresentByClassName("uif-headerText-span"); 093 assertTextPresent("Action Field with client side validation"); 094 assertTextPresent("InputField 1"); 095 assertIsNotVisibleByXpath("//a[contains(text(),'Required')]"); 096 097 waitAndClickByLinkText("Action Link with clientside validation"); 098 assertIsVisibleByXpath("//a[contains(text(),'Required')]", ""); 099 100 waitAndTypeByName("inputField1", "some text"); 101 waitAndClickByLinkText("Action Link with clientside validation"); 102 assertIsNotVisibleByXpath("//a[contains(text(),'Required')]"); 103 } 104 105 protected void testActionImages() throws Exception { 106 waitAndClickByLinkText("Images"); 107 waitForElementPresentByClassName("uif-headerText-span"); 108 assertTextPresent("Images"); 109 assertTextPresent("Action Field with images"); 110 111 driver.findElement(By.partialLinkText("Action Link with left image")).findElement(By.className( 112 "leftActionImage")); 113 driver.findElement(By.partialLinkText("Action Link with right image")).findElement(By.className( 114 "rightActionImage")); 115 } 116 117 @Test 118 public void testLibraryElementsActionBookmark() throws Exception { 119 testActionDefault(); 120 testActionPresubmit(); 121 testActionSuccessCallback(); 122 testActionValidation(); 123 testActionImages(); 124 passed(); 125 } 126 127 @Test 128 public void testLibraryElementsActionNav() throws Exception { 129 testActionDefault(); 130 testActionPresubmit(); 131 testActionSuccessCallback(); 132 testActionValidation(); 133 testActionImages(); 134 passed(); 135 } 136 }